Skip to content

Commit

Permalink
Moved getAppVersion and getAppName to Export cli base class
Browse files Browse the repository at this point in the history
  • Loading branch information
sea-kg committed Oct 7, 2020
1 parent ea50347 commit 9282733
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 61 deletions.
2 changes: 1 addition & 1 deletion example-of-exported/py3/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Automatically generated by wsjcpp-jsonrpc20.
* Version: v0.0.4
* Date: Wed, 07 Oct 2020 01:59:09 GMT
* Date: Wed, 07 Oct 2020 02:05:13 GMT

Example connect/disconnect:
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
### This file was automatically generated by wsjcpp-jsonrpc20
### Version: v0.0.4
### Date: Wed, 07 Oct 2020 01:59:09 GMT
### Date: Wed, 07 Oct 2020 02:05:13 GMT

import asyncio
import websocket
Expand Down
27 changes: 27 additions & 0 deletions src/wsjcpp_jsonrpc20_export_cli_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,31 @@ std::string WsjcppJsonRpc20ExportCliBase::getPackageName() const {
return m_sPackageName;
}

// ---------------------------------------------------------------------

void WsjcppJsonRpc20ExportCliBase::setAppName(const std::string &sAppName) {
m_sAppName = sAppName;
}

// ---------------------------------------------------------------------

std::string WsjcppJsonRpc20ExportCliBase::getAppName() const {
return m_sAppName;
}

// ---------------------------------------------------------------------

void WsjcppJsonRpc20ExportCliBase::setAppVersion(const std::string &sAppVersion) {
// https://www.python.org/dev/peps/pep-0440/
// [N!]N(.N)*[{a|b|rc}N][.postN][.devN]
// TODO regexp
m_sAppVersion = sAppVersion;
}

// ---------------------------------------------------------------------

std::string WsjcppJsonRpc20ExportCliBase::getAppVersion() const {
return m_sAppVersion;
}

// ---------------------------------------------------------------------
6 changes: 6 additions & 0 deletions src/wsjcpp_jsonrpc20_export_cli_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class WsjcppJsonRpc20ExportCliBase {

std::string getExportDir() const;
std::string getPackageName() const;
void setAppName(const std::string &sAppName);
std::string getAppName() const;
void setAppVersion(const std::string &sAppVersion);
std::string getAppVersion() const;

virtual bool doExportLib() = 0;

Expand All @@ -23,6 +27,8 @@ class WsjcppJsonRpc20ExportCliBase {
private:
std::string m_sExportDir;
std::string m_sPackageName;
std::string m_sAppName;
std::string m_sAppVersion;
};

#endif // WSJCPP_JSONRPC20_EXPORT_CLI_BASE_H
33 changes: 8 additions & 25 deletions src/wsjcpp_jsonrpc20_export_cli_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ WsjcppJsonRpc20ExportCliPython::WsjcppJsonRpc20ExportCliPython(
TAG = "WsjcppJsonRpc20ExportCliPython";
m_sAuthorName = "Unknown";
m_sAuthorEmail = "unknown";
m_sAppName = "unknown";
m_sAppVersion = "unknown";
m_sClassName = "Unknown";
m_sUrl = "none";
}
Expand All @@ -150,21 +148,6 @@ void WsjcppJsonRpc20ExportCliPython::setAuthorEmail(const std::string &sAuthorEm

// ---------------------------------------------------------------------

void WsjcppJsonRpc20ExportCliPython::setAppName(const std::string &sAppName) {
m_sAppName = sAppName;
}

// ---------------------------------------------------------------------

void WsjcppJsonRpc20ExportCliPython::setAppVersion(const std::string &sAppVersion) {
// https://www.python.org/dev/peps/pep-0440/
// [N!]N(.N)*[{a|b|rc}N][.postN][.devN]
// TODO regexp
m_sAppVersion = sAppVersion;
}

// ---------------------------------------------------------------------

void WsjcppJsonRpc20ExportCliPython::setClassName(const std::string &sClassName) {
m_sClassName = sClassName;
}
Expand Down Expand Up @@ -269,7 +252,7 @@ bool WsjcppJsonRpc20ExportCliPython::prepareReadmeMdIfNeed() {
if (!WsjcppCore::fileExists(sReadmeMd)) {
std::string sContentReadme =
"#" + this->getPackageName() + "\n\n"
+ m_sClassName + " Python Library for " + m_sAppName + "\n\n"
+ m_sClassName + " Python Library for " + this->getAppName() + "\n\n"
+ "## Install \n\n"
+ "```\n"
+ "$ pip3 install " + this->getPackageName() + " --upgrade\n"
Expand Down Expand Up @@ -306,13 +289,13 @@ bool WsjcppJsonRpc20ExportCliPython::exportSetupPy() {
"\n"
"setuptools.setup(\n"
" name='" + this->getPackageName() + "',\n"
" version='" + m_sAppVersion + "',\n"
" version='" + this->getAppVersion() + "',\n"
" packages=['" + this->getPackageName() + "'],\n"
" install_requires=['websocket-client>=0.56.0', 'requests>=2.21.0'],\n"
" keywords=['" + WsjcppCore::join(m_vKeywords, "', '") + "'],\n"
" author='" + m_sAuthorName + "',\n"
" author_email='" + m_sAuthorEmail + "',\n"
" description='" + m_sClassName + " Python Library for " + m_sAppName + "',\n"
" description='" + m_sClassName + " Python Library for " + this->getAppName() + "',\n"
" long_description=long_description,\n"
" long_description_content_type='text/markdown',\n"
" url='" + m_sUrl + "',\n"
Expand Down Expand Up @@ -351,8 +334,8 @@ bool WsjcppJsonRpc20ExportCliPython::exportAPImd() {
long nSec = WsjcppCore::getCurrentTimeInSeconds();

apimd << "# " + m_sClassName + " Python Library \n\n";
apimd << "Automatically generated by " << m_sAppName << ". \n";
apimd << "* Version: " << m_sAppVersion << "\n";
apimd << "Automatically generated by " << this->getAppName() << ". \n";
apimd << "* Version: " << this->getAppVersion() << "\n";
apimd << "* Date: " << WsjcppCore::formatTimeForWeb(nSec) << "\n\n";
apimd << "Example connect/disconnect:\n"
<< "```\n"
Expand Down Expand Up @@ -483,8 +466,8 @@ bool WsjcppJsonRpc20ExportCliPython::exportClientPy() {
builder
.add("#!/usr/bin/env python3")
.add("# -*- coding: utf-8 -*-")
.add("### This file was automatically generated by " + m_sAppName)
.add("### Version: " + m_sAppVersion)
.add("### This file was automatically generated by " + this->getAppName())
.add("### Version: " + this->getAppVersion())
.add("### Date: " + WsjcppCore::formatTimeForWeb(nSec))
.add("")
.add("import asyncio")
Expand All @@ -496,7 +479,7 @@ bool WsjcppJsonRpc20ExportCliPython::exportClientPy() {
.sub("class " + m_sClassName + ":")
.add("__ws = None")
.add("__url = None")
.add("__cli_version = '" + m_sAppVersion + "'")
.add("__cli_version = '" + this->getAppVersion() + "'")
.add("__loop = None")
.add("__token = None")
.add("__connecting = False")
Expand Down
4 changes: 0 additions & 4 deletions src/wsjcpp_jsonrpc20_export_cli_python.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class WsjcppJsonRpc20ExportCliPython : public WsjcppJsonRpc20ExportCliBase {
);
void setAuthorName(const std::string &sAuthorName);
void setAuthorEmail(const std::string &sAuthorEmail);
void setAppName(const std::string &sAppName);
void setAppVersion(const std::string &sAppVersion);
void setClassName(const std::string &sClassName);
void setUrl(const std::string &sUrl);
void setDownloadUrl(const std::string &sDownloadUrl);
Expand All @@ -26,8 +24,6 @@ class WsjcppJsonRpc20ExportCliPython : public WsjcppJsonRpc20ExportCliBase {
private:
std::string m_sAuthorName;
std::string m_sAuthorEmail;
std::string m_sAppName;
std::string m_sAppVersion;
std::string m_sClassName;
std::string m_sUrl;
std::string m_sDownloadUrl;
Expand Down
40 changes: 14 additions & 26 deletions src/wsjcpp_jsonrpc20_export_cli_webjs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ WsjcppJsonRpc20ExportCliWebJs::WsjcppJsonRpc20ExportCliWebJs(
TAG = "WsjcppJsonRpc20ExportCliWebJs";
m_sAuthorName = "Unknown";
m_sAuthorEmail = "unknown";
m_sAppName = "unknown";
m_sAppVersion = "unknown";
this->getAppName() = "unknown";
this->getAppVersion() = "unknown";
m_sClassName = "Unknown";
m_sDefaultConnectionString = "ws://localhost:1234/";

Expand Down Expand Up @@ -53,12 +53,6 @@ void WsjcppJsonRpc20ExportCliWebJs::setAuthorEmail(const std::string &sAuthorEma

// ---------------------------------------------------------------------

void WsjcppJsonRpc20ExportCliWebJs::setAppName(const std::string &sAppName) {
m_sAppName = sAppName;
}

// ---------------------------------------------------------------------

void WsjcppJsonRpc20ExportCliWebJs::setClassName(const std::string &sClassName) {
m_sClassName = sClassName;
}
Expand Down Expand Up @@ -97,12 +91,6 @@ void WsjcppJsonRpc20ExportCliWebJs::setDefaultConnectionString(const std::string

// ---------------------------------------------------------------------

void WsjcppJsonRpc20ExportCliWebJs::setAppVersion(const std::string &sAppVersion) {
m_sAppVersion = sAppVersion;
}

// ---------------------------------------------------------------------

bool WsjcppJsonRpc20ExportCliWebJs::doExportLib() {
std::string sBasicDir = "./" + this->getPackageName();

Expand Down Expand Up @@ -159,8 +147,8 @@ void WsjcppJsonRpc20ExportCliWebJs::exportPackageJson() {
packageJson <<
"{\n"
" \"name\": \"" + this->getPackageName() + "\",\n"
" \"version\": \"" + m_sAppVersion + "\",\n"
" \"description\": \"" + m_sClassName + " JavaScript Web Client Library for " + m_sAppName + "\",\n"
" \"version\": \"" + this->getAppVersion() + "\",\n"
" \"description\": \"" + m_sClassName + " JavaScript Web Client Library for " + this->getAppName() + "\",\n"
" \"main\": \"dist/" + this->getPackageName() + ".js\",\n"
" \"repository\": {\n"
" \"type\": \"" + m_sRepositoryType + "\",\n"
Expand Down Expand Up @@ -199,8 +187,8 @@ void WsjcppJsonRpc20ExportCliWebJs::exportAPImd() {

apimd <<
"# " + this->getPackageName() + "\n\n"
" Automatically generated by " << m_sAppName << ". \n"
" * Version: " << m_sAppVersion << "\n"
" Automatically generated by " << this->getAppName() << ". \n"
" * Version: " << this->getAppVersion() << "\n"
" * Date: " << buffer.str() << "\n\n"
" Include script ```dist/" + this->getPackageName() + ".js```\n"
" Example connect:\n"
Expand Down Expand Up @@ -381,11 +369,11 @@ bool WsjcppJsonRpc20ExportCliWebJs::exportLibCliWebJSFile() {
// now the result is in `buffer.str()`.

libwjscppcli_web_js_file <<
"// This file was automatically generated by " << m_sAppName << " (" + m_sAppVersion + "), date: " << sBuildDate << "\r\n"
"// This file was automatically generated by " << this->getAppName() << " (" + this->getAppVersion() + "), date: " << sBuildDate << "\r\n"
"window." << m_sClassName << " = window." << m_sClassName << " || (function() { \r\n"
" var self = {};\r\n"
" self.appName = '" + m_sAppName + "';\r\n"
" self.appVersion = '" + m_sAppVersion + "';\r\n"
" self.appName = '" + this->getAppName() + "';\r\n"
" self.appVersion = '" + this->getAppVersion() + "';\r\n"
" self.appBuildDate = '" + sBuildDate + "';\r\n"
" var _lastm = 0;\r\n"
" var _listeners = {};\r\n"
Expand All @@ -401,7 +389,7 @@ bool WsjcppJsonRpc20ExportCliWebJs::exportLibCliWebJSFile() {
libwjscppcli_web_js_file <<
" };\r\n"
" function _lm() { _lastm++; return 'm' + _lastm; };\r\n"
" console.warn('" + m_sClassName + " (" + m_sAppVersion + ")');\r\n"
" console.warn('" + m_sClassName + " (" + this->getAppVersion() + ")');\r\n"
" self.promise = function() {\r\n"
" return {\r\n"
" completed: false, failed: false, successed: false, \r\n"
Expand Down Expand Up @@ -698,7 +686,7 @@ void WsjcppJsonRpc20ExportCliWebJs::exportLibCliWebServiceTSFile() {
// now the result is in `buffer.str()`.

libwjscppcli_web_service_ts_file <<
"// This file was automatically generated by " << m_sAppName << " (v" + m_sAppVersion + "), date: " << sBuildDate << "\r\n"
"// This file was automatically generated by " << this->getAppName() << " (v" + this->getAppVersion() + "), date: " << sBuildDate << "\r\n"
"import { Injectable, EventEmitter } from '@angular/core';\r\n"
"import { PlatformLocation } from '@angular/common';\r\n"
"import { ToastrService } from 'ngx-toastr';\r\n"
Expand All @@ -707,8 +695,8 @@ void WsjcppJsonRpc20ExportCliWebJs::exportLibCliWebServiceTSFile() {
"\r\n"
"@Injectable({providedIn: 'root'})\r\n"
"export class " + m_sClassName + " {\r\n"
" private appName: string = '" + m_sAppName + "';\r\n"
" private appVersion: string = '" + m_sAppVersion + "';\r\n"
" private appName: string = '" + this->getAppName() + "';\r\n"
" private appVersion: string = '" + this->getAppVersion() + "';\r\n"
" private appBuildDate: string = '" + sBuildDate + "';\r\n"
" isAuthorized: boolean = false;\r\n"
" connectionState: string = '';\r\n"
Expand Down Expand Up @@ -738,7 +726,7 @@ void WsjcppJsonRpc20ExportCliWebJs::exportLibCliWebServiceTSFile() {
" ) {\r\n"
" this.serverHost = this._location.hostname;\r\n"
" this.currentProtocol = this._location.protocol;\r\n"
" console.warn('" + m_sClassName + " (" + m_sAppVersion + ")');\r\n"
" console.warn('" + m_sClassName + " (" + this->getAppVersion() + ")');\r\n"
" this._tokenValue = this.getToken();\r\n"
" }\r\n"
"\r\n"
Expand Down
4 changes: 0 additions & 4 deletions src/wsjcpp_jsonrpc20_export_cli_webjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class WsjcppJsonRpc20ExportCliWebJs : public WsjcppJsonRpc20ExportCliBase {
);
void setAuthorName(const std::string &sAuthorName);
void setAuthorEmail(const std::string &sAuthorEmail);
void setAppName(const std::string &sAppName);
void setAppVersion(const std::string &sAppVersion);
// TODO homepage
void setClassName(const std::string &sClassName);
void setIssuesURL(const std::string &sIssuesURL);
Expand All @@ -27,8 +25,6 @@ class WsjcppJsonRpc20ExportCliWebJs : public WsjcppJsonRpc20ExportCliBase {
std::string TAG;
std::string m_sAuthorName;
std::string m_sAuthorEmail;
std::string m_sAppName;
std::string m_sAppVersion;
std::string m_sClassName;
std::string m_sIssuesURL;
std::string m_sRepositoryType;
Expand Down

0 comments on commit 9282733

Please sign in to comment.