@serverless-devs/s 0.0.45 → 0.1.4-18cdd23b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -21
- package/OWNERS +33 -0
- package/_config.yml +1 -0
- package/bin/s +1 -1
- package/lib/daemon/lib.js +327 -0
- package/lib/daemon/report.js +50 -0
- package/lib/daemon/update-cli.js +20 -0
- package/lib/daemon/update-component.js +21 -0
- package/lib/daemon/update-templates.js +19 -0
- package/lib/index.js +1732 -0
- package/package.json +73 -61
- package/readme.md +127 -0
- package/.eslintrc +0 -75
- package/README.md +0 -65
- package/bin/s-config +0 -2
- package/bin/s-config-add +0 -2
- package/bin/s-config-delete +0 -2
- package/bin/s-config-get +0 -3
- package/bin/s-config-update +0 -3
- package/bin/s-deploy +0 -2
- package/bin/s-gui +0 -2
- package/bin/s-init +0 -2
- package/bin/s-platform +0 -2
- package/bin/s-platform-delete +0 -2
- package/bin/s-platform-init +0 -2
- package/bin/s-platform-login +0 -2
- package/bin/s-platform-publish +0 -2
- package/bin/s-remove +0 -2
- package/bin/s-search +0 -2
- package/bin/s-set +0 -2
- package/bin/s-set-analysis +0 -2
- package/bin/s-set-language +0 -2
- package/bin/s-set-output-color +0 -2
- package/compile.tsconfig.json +0 -12
- package/configs/base.tsconfig.json +0 -25
- package/lib/command/command-manager.d.ts +0 -12
- package/lib/command/command-manager.d.ts.map +0 -1
- package/lib/command/command-manager.js +0 -144
- package/lib/command/command-manager.js.map +0 -1
- package/lib/command/index.d.ts +0 -2
- package/lib/command/index.d.ts.map +0 -1
- package/lib/command/index.js +0 -41
- package/lib/command/index.js.map +0 -1
- package/lib/component/hook.d.ts +0 -17
- package/lib/component/hook.d.ts.map +0 -1
- package/lib/component/hook.js +0 -201
- package/lib/component/hook.js.map +0 -1
- package/lib/component/index.d.ts +0 -53
- package/lib/component/index.d.ts.map +0 -1
- package/lib/component/index.js +0 -577
- package/lib/component/index.js.map +0 -1
- package/lib/config/add/add-manager.d.ts +0 -23
- package/lib/config/add/add-manager.d.ts.map +0 -1
- package/lib/config/add/add-manager.js +0 -282
- package/lib/config/add/add-manager.js.map +0 -1
- package/lib/config/add/index.d.ts +0 -2
- package/lib/config/add/index.d.ts.map +0 -1
- package/lib/config/add/index.js +0 -77
- package/lib/config/add/index.js.map +0 -1
- package/lib/config/common/common.d.ts +0 -7
- package/lib/config/common/common.d.ts.map +0 -1
- package/lib/config/common/common.js +0 -175
- package/lib/config/common/common.js.map +0 -1
- package/lib/config/delete/delete-manager.d.ts +0 -11
- package/lib/config/delete/delete-manager.d.ts.map +0 -1
- package/lib/config/delete/delete-manager.js +0 -133
- package/lib/config/delete/delete-manager.js.map +0 -1
- package/lib/config/delete/index.d.ts +0 -2
- package/lib/config/delete/index.d.ts.map +0 -1
- package/lib/config/delete/index.js +0 -77
- package/lib/config/delete/index.js.map +0 -1
- package/lib/config/get/get-manager.d.ts +0 -14
- package/lib/config/get/get-manager.d.ts.map +0 -1
- package/lib/config/get/get-manager.js +0 -205
- package/lib/config/get/get-manager.js.map +0 -1
- package/lib/config/get/index.d.ts +0 -2
- package/lib/config/get/index.d.ts.map +0 -1
- package/lib/config/get/index.js +0 -86
- package/lib/config/get/index.js.map +0 -1
- package/lib/config/index.d.ts +0 -2
- package/lib/config/index.d.ts.map +0 -1
- package/lib/config/index.js +0 -15
- package/lib/config/index.js.map +0 -1
- package/lib/config/update/index.d.ts +0 -2
- package/lib/config/update/index.d.ts.map +0 -1
- package/lib/config/update/index.js +0 -83
- package/lib/config/update/index.js.map +0 -1
- package/lib/config/update/update-manager.d.ts +0 -23
- package/lib/config/update/update-manager.d.ts.map +0 -1
- package/lib/config/update/update-manager.js +0 -208
- package/lib/config/update/update-manager.js.map +0 -1
- package/lib/constants/static-variable.d.ts +0 -12
- package/lib/constants/static-variable.d.ts.map +0 -1
- package/lib/constants/static-variable.js +0 -15
- package/lib/constants/static-variable.js.map +0 -1
- package/lib/entity.d.ts +0 -11
- package/lib/entity.d.ts.map +0 -1
- package/lib/entity.js +0 -3
- package/lib/entity.js.map +0 -1
- package/lib/error/command-error.d.ts +0 -5
- package/lib/error/command-error.d.ts.map +0 -1
- package/lib/error/command-error.js +0 -26
- package/lib/error/command-error.js.map +0 -1
- package/lib/error/config-delete-error.d.ts +0 -5
- package/lib/error/config-delete-error.d.ts.map +0 -1
- package/lib/error/config-delete-error.js +0 -26
- package/lib/error/config-delete-error.js.map +0 -1
- package/lib/error/config-error.d.ts +0 -5
- package/lib/error/config-error.d.ts.map +0 -1
- package/lib/error/config-error.js +0 -26
- package/lib/error/config-error.js.map +0 -1
- package/lib/error/config-get-error.d.ts +0 -5
- package/lib/error/config-get-error.d.ts.map +0 -1
- package/lib/error/config-get-error.js +0 -26
- package/lib/error/config-get-error.js.map +0 -1
- package/lib/error/config-update-error.d.ts +0 -5
- package/lib/error/config-update-error.d.ts.map +0 -1
- package/lib/error/config-update-error.js +0 -26
- package/lib/error/config-update-error.js.map +0 -1
- package/lib/error/init-error.d.ts +0 -5
- package/lib/error/init-error.d.ts.map +0 -1
- package/lib/error/init-error.js +0 -26
- package/lib/error/init-error.js.map +0 -1
- package/lib/error/login-error.d.ts +0 -5
- package/lib/error/login-error.d.ts.map +0 -1
- package/lib/error/login-error.js +0 -26
- package/lib/error/login-error.js.map +0 -1
- package/lib/error/platform-delete-error.d.ts +0 -5
- package/lib/error/platform-delete-error.d.ts.map +0 -1
- package/lib/error/platform-delete-error.js +0 -26
- package/lib/error/platform-delete-error.js.map +0 -1
- package/lib/error/platform-init-error.d.ts +0 -5
- package/lib/error/platform-init-error.d.ts.map +0 -1
- package/lib/error/platform-init-error.js +0 -26
- package/lib/error/platform-init-error.js.map +0 -1
- package/lib/error/platform-publish-error.d.ts +0 -5
- package/lib/error/platform-publish-error.d.ts.map +0 -1
- package/lib/error/platform-publish-error.js +0 -26
- package/lib/error/platform-publish-error.js.map +0 -1
- package/lib/error/search-error.d.ts +0 -5
- package/lib/error/search-error.d.ts.map +0 -1
- package/lib/error/search-error.js +0 -26
- package/lib/error/search-error.js.map +0 -1
- package/lib/error/serverless-error.d.ts +0 -4
- package/lib/error/serverless-error.d.ts.map +0 -1
- package/lib/error/serverless-error.js +0 -20
- package/lib/error/serverless-error.js.map +0 -1
- package/lib/error/set-analysis-error.d.ts +0 -5
- package/lib/error/set-analysis-error.d.ts.map +0 -1
- package/lib/error/set-analysis-error.js +0 -26
- package/lib/error/set-analysis-error.js.map +0 -1
- package/lib/error/set-language-error.d.ts +0 -5
- package/lib/error/set-language-error.d.ts.map +0 -1
- package/lib/error/set-language-error.js +0 -26
- package/lib/error/set-language-error.js.map +0 -1
- package/lib/gui/gui-service.d.ts +0 -11
- package/lib/gui/gui-service.d.ts.map +0 -1
- package/lib/gui/gui-service.js +0 -276
- package/lib/gui/gui-service.js.map +0 -1
- package/lib/gui/index.d.ts +0 -2
- package/lib/gui/index.d.ts.map +0 -1
- package/lib/gui/index.js +0 -67
- package/lib/gui/index.js.map +0 -1
- package/lib/init/init-manager.d.ts +0 -9
- package/lib/init/init-manager.d.ts.map +0 -1
- package/lib/init/init-manager.js +0 -171
- package/lib/init/init-manager.js.map +0 -1
- package/lib/init/init-message.d.ts +0 -6
- package/lib/init/init-message.d.ts.map +0 -1
- package/lib/init/init-message.js +0 -9
- package/lib/init/init-message.js.map +0 -1
- package/lib/init/init.d.ts +0 -2
- package/lib/init/init.d.ts.map +0 -1
- package/lib/init/init.js +0 -87
- package/lib/init/init.js.map +0 -1
- package/lib/platform/delete/index.d.ts +0 -2
- package/lib/platform/delete/index.d.ts.map +0 -1
- package/lib/platform/delete/index.js +0 -89
- package/lib/platform/delete/index.js.map +0 -1
- package/lib/platform/delete/platform-delete-manager.d.ts +0 -4
- package/lib/platform/delete/platform-delete-manager.d.ts.map +0 -1
- package/lib/platform/delete/platform-delete-manager.js +0 -100
- package/lib/platform/delete/platform-delete-manager.js.map +0 -1
- package/lib/platform/index.d.ts +0 -2
- package/lib/platform/index.d.ts.map +0 -1
- package/lib/platform/index.js +0 -25
- package/lib/platform/index.js.map +0 -1
- package/lib/platform/init/index.d.ts +0 -2
- package/lib/platform/init/index.d.ts.map +0 -1
- package/lib/platform/init/index.js +0 -70
- package/lib/platform/init/index.js.map +0 -1
- package/lib/platform/init/platform-init-manager.d.ts +0 -4
- package/lib/platform/init/platform-init-manager.d.ts.map +0 -1
- package/lib/platform/init/platform-init-manager.js +0 -24
- package/lib/platform/init/platform-init-manager.js.map +0 -1
- package/lib/platform/login/index.d.ts +0 -2
- package/lib/platform/login/index.d.ts.map +0 -1
- package/lib/platform/login/index.js +0 -68
- package/lib/platform/login/index.js.map +0 -1
- package/lib/platform/login/login-manager.d.ts +0 -15
- package/lib/platform/login/login-manager.d.ts.map +0 -1
- package/lib/platform/login/login-manager.js +0 -176
- package/lib/platform/login/login-manager.js.map +0 -1
- package/lib/platform/publish/index.d.ts +0 -2
- package/lib/platform/publish/index.d.ts.map +0 -1
- package/lib/platform/publish/index.js +0 -93
- package/lib/platform/publish/index.js.map +0 -1
- package/lib/platform/publish/platform-publish-manager.d.ts +0 -5
- package/lib/platform/publish/platform-publish-manager.d.ts.map +0 -1
- package/lib/platform/publish/platform-publish-manager.js +0 -115
- package/lib/platform/publish/platform-publish-manager.js.map +0 -1
- package/lib/plugin/index.d.ts +0 -20
- package/lib/plugin/index.d.ts.map +0 -1
- package/lib/plugin/index.js +0 -175
- package/lib/plugin/index.js.map +0 -1
- package/lib/s.d.ts +0 -2
- package/lib/s.d.ts.map +0 -1
- package/lib/s.js +0 -134
- package/lib/s.js.map +0 -1
- package/lib/search/search.d.ts +0 -2
- package/lib/search/search.d.ts.map +0 -1
- package/lib/search/search.js +0 -233
- package/lib/search/search.js.map +0 -1
- package/lib/set/analysis/index.d.ts +0 -2
- package/lib/set/analysis/index.d.ts.map +0 -1
- package/lib/set/analysis/index.js +0 -84
- package/lib/set/analysis/index.js.map +0 -1
- package/lib/set/index.d.ts +0 -2
- package/lib/set/index.d.ts.map +0 -1
- package/lib/set/index.js +0 -16
- package/lib/set/index.js.map +0 -1
- package/lib/set/language/index.d.ts +0 -2
- package/lib/set/language/index.d.ts.map +0 -1
- package/lib/set/language/index.js +0 -73
- package/lib/set/language/index.js.map +0 -1
- package/lib/set/output-color/index.d.ts +0 -2
- package/lib/set/output-color/index.d.ts.map +0 -1
- package/lib/set/output-color/index.js +0 -87
- package/lib/set/output-color/index.js.map +0 -1
- package/lib/utils/analysis.d.ts +0 -12
- package/lib/utils/analysis.d.ts.map +0 -1
- package/lib/utils/analysis.js +0 -42
- package/lib/utils/analysis.js.map +0 -1
- package/lib/utils/check-version.d.ts +0 -13
- package/lib/utils/check-version.d.ts.map +0 -1
- package/lib/utils/check-version.js +0 -241
- package/lib/utils/check-version.js.map +0 -1
- package/lib/utils/command.d.ts +0 -14
- package/lib/utils/command.d.ts.map +0 -1
- package/lib/utils/command.js +0 -251
- package/lib/utils/command.js.map +0 -1
- package/lib/utils/common.d.ts +0 -4
- package/lib/utils/common.d.ts.map +0 -1
- package/lib/utils/common.js +0 -50
- package/lib/utils/common.js.map +0 -1
- package/lib/utils/download-manager.d.ts +0 -23
- package/lib/utils/download-manager.d.ts.map +0 -1
- package/lib/utils/download-manager.js +0 -302
- package/lib/utils/download-manager.js.map +0 -1
- package/lib/utils/handler-set-config.d.ts +0 -14
- package/lib/utils/handler-set-config.d.ts.map +0 -1
- package/lib/utils/handler-set-config.js +0 -122
- package/lib/utils/handler-set-config.js.map +0 -1
- package/lib/utils/i18n.d.ts +0 -3
- package/lib/utils/i18n.d.ts.map +0 -1
- package/lib/utils/i18n.js +0 -21
- package/lib/utils/i18n.js.map +0 -1
- package/lib/utils/locales/en.json +0 -9
- package/lib/utils/locales/zh.json +0 -203
- package/lib/utils/logger.d.ts +0 -18
- package/lib/utils/logger.d.ts.map +0 -1
- package/lib/utils/logger.js +0 -196
- package/lib/utils/logger.js.map +0 -1
- package/lib/utils/package-type.d.ts +0 -6
- package/lib/utils/package-type.d.ts.map +0 -1
- package/lib/utils/package-type.js +0 -10
- package/lib/utils/package-type.js.map +0 -1
- package/lib/utils/parse.d.ts +0 -26
- package/lib/utils/parse.d.ts.map +0 -1
- package/lib/utils/parse.js +0 -229
- package/lib/utils/parse.js.map +0 -1
- package/lib/utils/repo-template-entity.d.ts +0 -12
- package/lib/utils/repo-template-entity.d.ts.map +0 -1
- package/lib/utils/repo-template-entity.js +0 -3
- package/lib/utils/repo-template-entity.js.map +0 -1
- package/lib/utils/start-service.d.ts +0 -22
- package/lib/utils/start-service.d.ts.map +0 -1
- package/lib/utils/start-service.js +0 -97
- package/lib/utils/start-service.js.map +0 -1
- package/lib/utils/storage.d.ts +0 -3
- package/lib/utils/storage.d.ts.map +0 -1
- package/lib/utils/storage.js +0 -23
- package/lib/utils/storage.js.map +0 -1
- package/lib/utils/url-parser.d.ts +0 -8
- package/lib/utils/url-parser.d.ts.map +0 -1
- package/lib/utils/url-parser.js +0 -58
- package/lib/utils/url-parser.js.map +0 -1
- package/scripts/tests/deploy/parse.ts +0 -0
- package/scripts/tests/download-manager-test.ts +0 -135
- package/scripts/tests/init-manager-test.ts +0 -232
- package/scripts/tests/url-parser-test.ts +0 -44
- package/src/command/command-manager.ts +0 -83
- package/src/command/index.ts +0 -42
- package/src/component/hook.ts +0 -88
- package/src/component/index.ts +0 -433
- package/src/config/add/add-manager.ts +0 -207
- package/src/config/add/index.ts +0 -45
- package/src/config/common/common.ts +0 -186
- package/src/config/delete/delete-manager.ts +0 -51
- package/src/config/delete/index.ts +0 -38
- package/src/config/get/get-manager.ts +0 -148
- package/src/config/get/index.ts +0 -49
- package/src/config/index.ts +0 -13
- package/src/config/update/index.ts +0 -46
- package/src/config/update/update-manager.ts +0 -120
- package/src/constants/static-variable.ts +0 -12
- package/src/entity.ts +0 -10
- package/src/error/command-error.ts +0 -7
- package/src/error/config-delete-error.ts +0 -7
- package/src/error/config-error.ts +0 -7
- package/src/error/config-get-error.ts +0 -7
- package/src/error/config-update-error.ts +0 -7
- package/src/error/init-error.ts +0 -7
- package/src/error/login-error.ts +0 -7
- package/src/error/platform-delete-error.ts +0 -7
- package/src/error/platform-init-error.ts +0 -7
- package/src/error/platform-publish-error.ts +0 -7
- package/src/error/search-error.ts +0 -7
- package/src/error/serverless-error.ts +0 -17
- package/src/error/set-analysis-error.ts +0 -7
- package/src/error/set-language-error.ts +0 -7
- package/src/gui/gui-service.ts +0 -183
- package/src/gui/index.ts +0 -26
- package/src/init/init-manager.ts +0 -104
- package/src/init/init-message.ts +0 -8
- package/src/init/init.ts +0 -56
- package/src/platform/delete/index.ts +0 -46
- package/src/platform/delete/platform-delete-manager.ts +0 -46
- package/src/platform/index.ts +0 -26
- package/src/platform/init/index.ts +0 -33
- package/src/platform/init/platform-init-manager.ts +0 -17
- package/src/platform/login/index.ts +0 -25
- package/src/platform/login/login-manager.ts +0 -121
- package/src/platform/publish/index.ts +0 -52
- package/src/platform/publish/platform-publish-manager.ts +0 -69
- package/src/plugin/index.ts +0 -96
- package/src/s.ts +0 -83
- package/src/search/search.ts +0 -127
- package/src/set/analysis/index.ts +0 -45
- package/src/set/index.ts +0 -19
- package/src/set/language/index.ts +0 -39
- package/src/set/output-color/index.ts +0 -49
- package/src/utils/analysis.ts +0 -36
- package/src/utils/check-version.ts +0 -139
- package/src/utils/command.ts +0 -123
- package/src/utils/common.ts +0 -47
- package/src/utils/download-manager.ts +0 -197
- package/src/utils/handler-set-config.ts +0 -83
- package/src/utils/i18n.ts +0 -21
- package/src/utils/locales/en.json +0 -9
- package/src/utils/locales/zh.json +0 -228
- package/src/utils/logger.ts +0 -84
- package/src/utils/package-type.ts +0 -3
- package/src/utils/parse.ts +0 -176
- package/src/utils/repo-template-entity.ts +0 -14
- package/src/utils/start-service.ts +0 -64
- package/src/utils/storage.ts +0 -20
- package/src/utils/url-parser.ts +0 -60
- package/templates/application/common/publish.yaml +0 -16
- package/templates/application/common/readme.md +0 -99
- package/templates/application/common/src/index.js +0 -13
- package/templates/application/common/src/template.yaml +0 -16
- package/templates/component/common/publish.yaml +0 -24
- package/templates/component/common/readme.md +0 -386
- package/templates/component/common/src/index.js +0 -18
- package/templates/component/common/src/package.json +0 -7
- package/templates/plugin/common/publish.yaml +0 -9
- package/templates/plugin/common/readme.md +0 -128
- package/templates/plugin/common/src/index.js +0 -9
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as program from 'commander';
|
|
2
|
-
import { PlatformLoginManager } from './login-manager';
|
|
3
|
-
import { CommandError } from '../../error/command-error';
|
|
4
|
-
import i18n from '../../utils/i18n';
|
|
5
|
-
const description = `${i18n.__('Login Serverless Tool.')}
|
|
6
|
-
|
|
7
|
-
${i18n.__('Example')}:
|
|
8
|
-
$ s platform login
|
|
9
|
-
$ s platform login -u username -p password`;
|
|
10
|
-
program
|
|
11
|
-
.name('s platform login')
|
|
12
|
-
|
|
13
|
-
.option('-u, --username', i18n.__('Username of Serverless Devs Tool Platform'))
|
|
14
|
-
.option('-p, --password', i18n.__('Password of Serverless Devs Tool Platform'))
|
|
15
|
-
.option('-g, --gui', i18n.__('Start gui service'))
|
|
16
|
-
.description(description)
|
|
17
|
-
.helpOption('-h, --help', i18n.__('Display help for command'))
|
|
18
|
-
.parse(process.argv);
|
|
19
|
-
(async () => {
|
|
20
|
-
const { username, password, gui } = program;
|
|
21
|
-
const initManager = new PlatformLoginManager();
|
|
22
|
-
await initManager.init({ username, password, gui });
|
|
23
|
-
})().catch((err) => {
|
|
24
|
-
throw new CommandError(err.message);
|
|
25
|
-
});
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
const inquirer = require('inquirer');
|
|
3
|
-
import axios from 'axios';
|
|
4
|
-
import * as fs from 'fs-extra';
|
|
5
|
-
import * as os from 'os';
|
|
6
|
-
import * as path from 'path';
|
|
7
|
-
import { InquirerCommand, CommandType } from '../../entity';
|
|
8
|
-
import logger from '../../utils/logger';
|
|
9
|
-
import { LoginError } from '../../error/login-error';
|
|
10
|
-
import { SERVERLESS_LOGIN_URL } from '../../constants/static-variable';
|
|
11
|
-
import GUIService from '../../gui/gui-service';
|
|
12
|
-
import i18n from '../../utils/i18n';
|
|
13
|
-
export interface IPlatformAddManagerData {
|
|
14
|
-
username?: string;
|
|
15
|
-
password?: string;
|
|
16
|
-
gui?: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const CONFIG_COMMAND_MAP: InquirerCommand = {
|
|
20
|
-
username: {
|
|
21
|
-
type: 'input',
|
|
22
|
-
message: i18n.__('Please input username'),
|
|
23
|
-
name: 'username',
|
|
24
|
-
default: '' // 默认值
|
|
25
|
-
},
|
|
26
|
-
password: {
|
|
27
|
-
type: 'password',
|
|
28
|
-
message: i18n.__('Please input password'),
|
|
29
|
-
name: 'password',
|
|
30
|
-
default: '' // 默认值
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export class PlatformLoginManager {
|
|
35
|
-
constructor() { }
|
|
36
|
-
|
|
37
|
-
async init(context: IPlatformAddManagerData) {
|
|
38
|
-
let { username, password, gui } = context;
|
|
39
|
-
if (gui) {
|
|
40
|
-
const guiService = new GUIService('/login');
|
|
41
|
-
guiService.start();
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
if (username && password) {
|
|
45
|
-
await this.login(context);
|
|
46
|
-
} else {
|
|
47
|
-
const promptList: CommandType[] = [];
|
|
48
|
-
if (!username && !password) {
|
|
49
|
-
Object.keys(CONFIG_COMMAND_MAP).forEach(key => {
|
|
50
|
-
promptList.push(CONFIG_COMMAND_MAP[key]);
|
|
51
|
-
});
|
|
52
|
-
let { username, password } = await inquirer.prompt(promptList);
|
|
53
|
-
await this.login({ username, password });
|
|
54
|
-
} else if (username && !password) {
|
|
55
|
-
promptList.push(CONFIG_COMMAND_MAP.password);
|
|
56
|
-
let { password } = await inquirer.prompt(promptList);
|
|
57
|
-
await this.login({ username, password });
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
//.then((answers: IPlatformAddManagerData) => {
|
|
61
|
-
// this.login(answers);
|
|
62
|
-
// });
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async login(loginData: IPlatformAddManagerData) {
|
|
67
|
-
logger.info('In operation......');
|
|
68
|
-
const options = {
|
|
69
|
-
// url: LOGIN_URL,
|
|
70
|
-
// type: 'post',
|
|
71
|
-
timeout: 5000,
|
|
72
|
-
headers: {
|
|
73
|
-
'User-Agent': 's'
|
|
74
|
-
}
|
|
75
|
-
// data: loginData
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
let result;
|
|
79
|
-
try {
|
|
80
|
-
result = await axios.post(SERVERLESS_LOGIN_URL, { username: loginData.username, password: loginData.password }, options);
|
|
81
|
-
} catch (err) {
|
|
82
|
-
throw new LoginError('Failed to login, error: {{error}}', { error: err.message });
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (result.status !== 200) {
|
|
86
|
-
throw new LoginError('Failed to login, http code: {{code}}', { code: result.status });
|
|
87
|
-
}
|
|
88
|
-
if (result.data.Error) {
|
|
89
|
-
throw new LoginError('Failed to login, code: {{code}}, message: {{msg}}', { code: result.data.Error.Code, msg: result.data.Error.Message });
|
|
90
|
-
}
|
|
91
|
-
const token = result.data.Response.Code;
|
|
92
|
-
|
|
93
|
-
if (!fs.existsSync(this.getTokenDir())) {
|
|
94
|
-
fs.mkdirSync(this.getTokenDir());
|
|
95
|
-
}
|
|
96
|
-
const tokenFile = this.getTokenFile();
|
|
97
|
-
if (fs.existsSync(tokenFile)) {
|
|
98
|
-
fs.removeSync(tokenFile);
|
|
99
|
-
}
|
|
100
|
-
fs.writeFileSync(tokenFile, token);
|
|
101
|
-
logger.success('Login information obtained successfully.');
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
isCurrentLogin() {
|
|
105
|
-
return fs.existsSync(this.getTokenFile());
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
getLoginToken(): string {
|
|
109
|
-
return fs.readFileSync(this.getTokenFile(), 'utf-8');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
private getTokenFile() {
|
|
113
|
-
const dir = this.getTokenDir();
|
|
114
|
-
return path.join(dir, 'login-token');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
private getTokenDir() {
|
|
118
|
-
return path.join(os.homedir(), '.s');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import * as program from 'commander';
|
|
2
|
-
import * as fs from 'fs-extra';
|
|
3
|
-
import i18n from '../../utils/i18n';
|
|
4
|
-
import { PlatformPublishManager } from './platform-publish-manager';
|
|
5
|
-
import { PlatformLoginManager } from '../login/login-manager';
|
|
6
|
-
import GUIService from '../../gui/gui-service';
|
|
7
|
-
import { PlatformPublishError } from '../../error/platform-publish-error';
|
|
8
|
-
import { CommandError } from '../../error/command-error';
|
|
9
|
-
const description = ` ${i18n.__('Publish package.')}
|
|
10
|
-
|
|
11
|
-
${i18n.__('Example')}:
|
|
12
|
-
$ s platform publish`;
|
|
13
|
-
program
|
|
14
|
-
.name('s platform publish')
|
|
15
|
-
.option('-g, --gui', i18n.__('Start gui service'))
|
|
16
|
-
// .option('-s, --skip', i18n.__('Skip the update configuration information step and publish directly'))
|
|
17
|
-
.description(description)
|
|
18
|
-
.helpOption('-h, --help', i18n.__('Display help for command'))
|
|
19
|
-
.parse(process.argv);
|
|
20
|
-
|
|
21
|
-
(async () => {
|
|
22
|
-
|
|
23
|
-
const { gui } = program;
|
|
24
|
-
if (gui) {
|
|
25
|
-
const guiService = new GUIService('/publish');
|
|
26
|
-
guiService.start();
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const loginManger: PlatformLoginManager = new PlatformLoginManager();
|
|
30
|
-
if (!loginManger.isCurrentLogin()) {
|
|
31
|
-
throw new PlatformPublishError('Please login in first.');
|
|
32
|
-
}
|
|
33
|
-
const token = loginManger.getLoginToken();
|
|
34
|
-
|
|
35
|
-
if (!fs.existsSync('publish.yaml')) {
|
|
36
|
-
throw new Error('No publish.yaml exists in current dir.');
|
|
37
|
-
}
|
|
38
|
-
if (!fs.existsSync('readme.md')) {
|
|
39
|
-
throw new Error('No readme exists in current dir.');
|
|
40
|
-
}
|
|
41
|
-
if (!fs.existsSync('src')) {
|
|
42
|
-
throw new Error('No src exists in current dir.');
|
|
43
|
-
}
|
|
44
|
-
const publishManager = new PlatformPublishManager();
|
|
45
|
-
const encoding = 'utf-8';
|
|
46
|
-
const publish: string = fs.readFileSync('publish.yaml', encoding); //TODO encoding
|
|
47
|
-
const readme: string = fs.readFileSync('readme.md', encoding); //TODO encoding
|
|
48
|
-
|
|
49
|
-
await publishManager.publish(token, publish, readme);
|
|
50
|
-
})().catch((err) => {
|
|
51
|
-
throw new CommandError(err.message);
|
|
52
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
import { PlatformPublishError } from '../../error/platform-publish-error';
|
|
4
|
-
import logger from '../../utils/logger';
|
|
5
|
-
import * as path from 'path';
|
|
6
|
-
import * as os from 'os';
|
|
7
|
-
const Zip = require('adm-zip');
|
|
8
|
-
|
|
9
|
-
const PUBLISH_PACKAGE_URL = 'http://tool.serverlessfans.com/api/package/put/object/url';
|
|
10
|
-
|
|
11
|
-
export class PlatformPublishManager {
|
|
12
|
-
async publish(user: string, content: string, readme: string) {
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
logger.info('Publishing......');
|
|
16
|
-
//zip
|
|
17
|
-
const zipFile = path.join(os.tmpdir(), this.generateUUID() + '.zip');
|
|
18
|
-
var zipper = new Zip();
|
|
19
|
-
zipper.addLocalFolder('src', 'src');
|
|
20
|
-
zipper.writeZip(zipFile);
|
|
21
|
-
//console.log(zipFile);
|
|
22
|
-
|
|
23
|
-
const result = await axios.post(PUBLISH_PACKAGE_URL, {
|
|
24
|
-
user: user,
|
|
25
|
-
publish: content,
|
|
26
|
-
readme: readme
|
|
27
|
-
});
|
|
28
|
-
// eslint-disable-next-line eqeqeq
|
|
29
|
-
if (result.status != 200) {
|
|
30
|
-
throw new Error(`Failed to publish package, http status code: ${result.status}`);
|
|
31
|
-
}
|
|
32
|
-
if (result.data.Error) {
|
|
33
|
-
throw new Error(`Failed to publish package, code: ${result.data.Error.Code}, message: ${result.data.Error.Message}`);
|
|
34
|
-
}
|
|
35
|
-
const url: string = result.data.Response.Url;
|
|
36
|
-
|
|
37
|
-
const options = {
|
|
38
|
-
url,
|
|
39
|
-
method: 'put',
|
|
40
|
-
timeout: 30 * 60 * 1000,
|
|
41
|
-
headers: {
|
|
42
|
-
'User-Agent': 's'
|
|
43
|
-
},
|
|
44
|
-
data: zipper.toBuffer(),
|
|
45
|
-
maxContentLength: Infinity,
|
|
46
|
-
maxBodyLength: Infinity,
|
|
47
|
-
transformRequest: (data: any, headers: any) => {
|
|
48
|
-
delete headers.put;
|
|
49
|
-
return data;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
53
|
-
// @ts-ignore
|
|
54
|
-
const uploadResult = await axios(options);
|
|
55
|
-
// eslint-disable-next-line eqeqeq
|
|
56
|
-
if (uploadResult.status != 200) {
|
|
57
|
-
throw new Error(`Failed to upload package, status code is: ${uploadResult.status}, messge is : ${uploadResult}`);
|
|
58
|
-
}
|
|
59
|
-
logger.success('Publish successfully');
|
|
60
|
-
} catch (err) {
|
|
61
|
-
throw new PlatformPublishError(err.message);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
private generateUUID(): string {
|
|
66
|
-
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
}
|
package/src/plugin/index.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const os = require('os');
|
|
4
|
-
import axios from 'axios';
|
|
5
|
-
import { DownloadManager } from '../utils/download-manager';
|
|
6
|
-
import * as logger from '../utils/logger';
|
|
7
|
-
import { PackageType } from '../utils/package-type';
|
|
8
|
-
const S_PLUGIN_BASE_PATH = path.join(os.homedir(), `.s/plugins`);
|
|
9
|
-
const BASE_API_URL = 'https://tool.serverlessfans.com/api';
|
|
10
|
-
const CHECK_VERSION_URL = '/package/object/version';
|
|
11
|
-
const TYPE_MAP: { [key: number]: string } = {
|
|
12
|
-
[PackageType.component]: 'Component',
|
|
13
|
-
[PackageType.plugin]: 'Plugin',
|
|
14
|
-
[PackageType.application]: 'Application'
|
|
15
|
-
};
|
|
16
|
-
export interface PluginConifg {
|
|
17
|
-
name: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class PluginExeCute {
|
|
21
|
-
protected pluginPath: string;
|
|
22
|
-
|
|
23
|
-
constructor(protected pluginConfig: PluginConifg) {
|
|
24
|
-
if (!fs.existsSync(S_PLUGIN_BASE_PATH)) {
|
|
25
|
-
fs.mkdirSync(S_PLUGIN_BASE_PATH);
|
|
26
|
-
}
|
|
27
|
-
const { name } = this.pluginConfig;
|
|
28
|
-
this.pluginPath = path.join(S_PLUGIN_BASE_PATH, `/${name}`);
|
|
29
|
-
}
|
|
30
|
-
async init() {
|
|
31
|
-
const { name } = this.pluginConfig;
|
|
32
|
-
|
|
33
|
-
if (!this.pluginExist()) {
|
|
34
|
-
await this.downLoadPlugin(PackageType.plugin, name);
|
|
35
|
-
} else {
|
|
36
|
-
const localVersion = this.getLocalComponentVersion();
|
|
37
|
-
const remoteVersion = await this.getRemotePluginVersion({ name, type: PackageType.plugin });
|
|
38
|
-
const isSameVersion = this.checkVersion(localVersion, remoteVersion);
|
|
39
|
-
if (!isSameVersion) {
|
|
40
|
-
await this.downLoadPlugin(PackageType.plugin, name);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
pluginExist() {
|
|
45
|
-
return fs.existsSync(this.pluginPath);
|
|
46
|
-
}
|
|
47
|
-
async getRemotePluginVersion({ name, type }: { name: string, type: PackageType }) {
|
|
48
|
-
const url = `${BASE_API_URL}${CHECK_VERSION_URL}`;
|
|
49
|
-
|
|
50
|
-
let version = null;
|
|
51
|
-
try {
|
|
52
|
-
const result: any = await axios.get(url, {
|
|
53
|
-
params: {
|
|
54
|
-
name, type: TYPE_MAP[type]
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
if (result.data && result.data.Response && result.data.Response.Version) {
|
|
58
|
-
version = result.data.Response.Version;
|
|
59
|
-
} else {
|
|
60
|
-
// throw new Error("Please Check the plugin name");
|
|
61
|
-
}
|
|
62
|
-
} catch (e) {
|
|
63
|
-
logger.error(e.message);
|
|
64
|
-
}
|
|
65
|
-
return version;
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
getLocalComponentVersion() {
|
|
69
|
-
const { name } = this.pluginConfig;
|
|
70
|
-
const pkgFile = path.join(S_PLUGIN_BASE_PATH, `/${name}/package.json`);
|
|
71
|
-
if (!fs.existsSync(pkgFile)) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
const componentPackageJsonObj = require(pkgFile);
|
|
75
|
-
return componentPackageJsonObj.version;
|
|
76
|
-
}
|
|
77
|
-
checkVersion(localVersion: string | null, remoteVersion: string) {
|
|
78
|
-
return remoteVersion === localVersion;
|
|
79
|
-
}
|
|
80
|
-
async downLoadPlugin(type: PackageType, name: string) {
|
|
81
|
-
const downloadManager = new DownloadManager();
|
|
82
|
-
const pluginPath = path.join(S_PLUGIN_BASE_PATH, `/${name}`);
|
|
83
|
-
if (!fs.existsSync(pluginPath)) {
|
|
84
|
-
fs.mkdirSync(pluginPath);
|
|
85
|
-
}
|
|
86
|
-
await downloadManager.downloadTemplateFromAppCenter(type, name, pluginPath);
|
|
87
|
-
}
|
|
88
|
-
async loadPlugin() {
|
|
89
|
-
|
|
90
|
-
const PluginModule = require(this.pluginPath);
|
|
91
|
-
return PluginModule;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
package/src/s.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import i18n from './utils/i18n';
|
|
2
|
-
import * as program from 'commander';
|
|
3
|
-
import { handlerProfileFile } from './utils/handler-set-config';
|
|
4
|
-
import logger from './utils/logger';
|
|
5
|
-
import { registerCommandChecker, registerExitOverride, recordCommandHistory, registerCustomerCommand, regiserUniversalCommand } from './utils/command';
|
|
6
|
-
import { checkAndReturnTemplateFile } from './utils/common';
|
|
7
|
-
import { PROCESS_ENV_TEMPLATE_NAME } from './constants/static-variable';
|
|
8
|
-
const description = ` _________ .__
|
|
9
|
-
/ _____/ ______________ __ ___________| | ____ ______ ______
|
|
10
|
-
\\_____ \\_/ __ \\_ __ \\ \\/ // __ \\_ __ \\ | _/ __ \\ / ___// ___/
|
|
11
|
-
/ \\ ___/| | \\/\\ /\\ ___/| | \\/ |_\\ ___/ \\___ \\ \\___ \\
|
|
12
|
-
/_______ /\\___ >__| \\_/ \\___ >__| |____/\\___ >____ >____ >
|
|
13
|
-
\\/ \\/ \\/ \\/ \\/ \\/
|
|
14
|
-
|
|
15
|
-
${i18n.__('Welcome to the Serverless Tool.')}
|
|
16
|
-
${i18n.__('You can use the corresponding function through the following instructions.')}
|
|
17
|
-
`;
|
|
18
|
-
|
|
19
|
-
async function setSpecialCommand() {
|
|
20
|
-
const templateFile = checkAndReturnTemplateFile();
|
|
21
|
-
if (templateFile) {
|
|
22
|
-
process['env'][PROCESS_ENV_TEMPLATE_NAME] = templateFile;
|
|
23
|
-
// Determine whether basic instructions are used, if not useful, add general instructions, etc.
|
|
24
|
-
if (!['init', 'config', 'platform', 'search', 'set', 'gui'].includes(process.argv[2])) {
|
|
25
|
-
await registerCustomerCommand(program, templateFile); // Add user-defined commands
|
|
26
|
-
await regiserUniversalCommand(program, templateFile); // Register pan instruction
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function globalParameterProcessing() {
|
|
32
|
-
const tempGlobal = ['skip-extends', 'verbose'];
|
|
33
|
-
for (let i = 0;i < tempGlobal.length;i++) {
|
|
34
|
-
process.env[tempGlobal[i]] = 'false';
|
|
35
|
-
if (process.argv.includes('--' + tempGlobal[i])) {
|
|
36
|
-
process.env[tempGlobal[i]] = 'true';
|
|
37
|
-
process.argv.splice(process.argv.indexOf('--' + tempGlobal[i]), 1);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
(async () => {
|
|
43
|
-
|
|
44
|
-
// Initialize the print configuration, open by default
|
|
45
|
-
const setConfigObject = await handlerProfileFile({ read: true });
|
|
46
|
-
const outputColorFlag = setConfigObject['output-color'] === false ? false : true;
|
|
47
|
-
|
|
48
|
-
// Set output color
|
|
49
|
-
logger.colorSwitch(outputColorFlag);
|
|
50
|
-
|
|
51
|
-
// Wrong instruction
|
|
52
|
-
registerCommandChecker(program);
|
|
53
|
-
|
|
54
|
-
let system_command = program
|
|
55
|
-
.version('', '-v, --version', i18n.__('Output the version number'))
|
|
56
|
-
.description(description)
|
|
57
|
-
.helpOption('-h, --help', i18n.__('Display help for command'))
|
|
58
|
-
.command('config', i18n.__('Configure cloud service account.'))
|
|
59
|
-
.command('gui', i18n.__('Start GUI service.'))
|
|
60
|
-
.command('init', i18n.__('Initializing a project.'))
|
|
61
|
-
.command('search', i18n.__('Search the package.'))
|
|
62
|
-
.command('platform', i18n.__('Publish a(an) Component/Plugin/Application.'))
|
|
63
|
-
.command('set', i18n.__('Settings for the tool.'))
|
|
64
|
-
.option('--skip-extends', i18n.__('Skip the extends section'))
|
|
65
|
-
.addHelpCommand(false);
|
|
66
|
-
|
|
67
|
-
// Global parameter processing
|
|
68
|
-
await globalParameterProcessing();
|
|
69
|
-
|
|
70
|
-
// Universal instruction processing
|
|
71
|
-
await setSpecialCommand();
|
|
72
|
-
|
|
73
|
-
// Verification version
|
|
74
|
-
await registerExitOverride(program);
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
// Record command
|
|
78
|
-
recordCommandHistory(process.argv);
|
|
79
|
-
} catch (ex) { }
|
|
80
|
-
|
|
81
|
-
system_command.parse(process.argv);
|
|
82
|
-
})();
|
|
83
|
-
|
package/src/search/search.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import * as program from 'commander';
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
import logger from '../utils/logger';
|
|
4
|
-
import i18n from '../utils/i18n';
|
|
5
|
-
import { SearchError } from '../error/search-error';
|
|
6
|
-
import { SERVERLESS_SEARCH_URL } from '../constants/static-variable';
|
|
7
|
-
import {CommandError} from '../error/command-error';
|
|
8
|
-
import GUIService from '../gui/gui-service';
|
|
9
|
-
|
|
10
|
-
const description = `${i18n.__('Search packages')}.
|
|
11
|
-
|
|
12
|
-
${i18n.__('Example')}:
|
|
13
|
-
$ s search keywords
|
|
14
|
-
$ s search keywords -p alibaba
|
|
15
|
-
$ s search keywords -t component
|
|
16
|
-
`;
|
|
17
|
-
program
|
|
18
|
-
.name('s search')
|
|
19
|
-
.option('-p, --provider [provider]', i18n.__('The cloud service provider.'))
|
|
20
|
-
.helpOption('-h, --help', i18n.__('Display help for command'))
|
|
21
|
-
.option('-t, --type [type]', i18n.__('The package type. [component/plugin/application]'))
|
|
22
|
-
.option('-g, --gui', i18n.__('Start gui service'))
|
|
23
|
-
.description(description)
|
|
24
|
-
.parse(process.argv);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
(async () => {
|
|
28
|
-
|
|
29
|
-
const gui = program.gui || false;
|
|
30
|
-
|
|
31
|
-
if (program.args.length === 0 && gui === false) {
|
|
32
|
-
program.help();
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (gui === true) {
|
|
37
|
-
const guiService = new GUIService();
|
|
38
|
-
await guiService.start();
|
|
39
|
-
} else {
|
|
40
|
-
const name = program.args[0];
|
|
41
|
-
const provider = program.provider;
|
|
42
|
-
const type = program.type || 'application';
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
await search(name, provider, type);
|
|
46
|
-
} catch (err) {
|
|
47
|
-
throw new SearchError('Could not get packages.');
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
})().catch((err) => {
|
|
51
|
-
throw new CommandError(err.message);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
async function printn(n: number, str = ' ') {
|
|
55
|
-
let temp_str = '';
|
|
56
|
-
for (let i = 0;i < n;i++) {
|
|
57
|
-
temp_str = temp_str + str;
|
|
58
|
-
}
|
|
59
|
-
return temp_str;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async function search(name: string, provider ?: string, type ?: string) {
|
|
63
|
-
const options = {
|
|
64
|
-
url: SERVERLESS_SEARCH_URL,
|
|
65
|
-
type: 'get',
|
|
66
|
-
timeout: 5000,
|
|
67
|
-
headers: {
|
|
68
|
-
'User-Agent': 's'
|
|
69
|
-
},
|
|
70
|
-
params: {
|
|
71
|
-
keyword: name,
|
|
72
|
-
type: type,
|
|
73
|
-
provider: provider
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
let result;
|
|
78
|
-
try {
|
|
79
|
-
result = await axios.request(options);
|
|
80
|
-
} catch (err) {
|
|
81
|
-
throw new SearchError('Search failed, error: {{error}}', {error: err.message});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (result.status !== 200) {
|
|
85
|
-
throw new SearchError('Search failed, status code: {{code}}', {code: result.status});
|
|
86
|
-
}
|
|
87
|
-
//console.log(result.data);
|
|
88
|
-
if (result.data.Error) {
|
|
89
|
-
throw new SearchError('Search failed, error code: {{code}}, message:{{msg}}', {
|
|
90
|
-
code: result.data.Error.Code,
|
|
91
|
-
msg: result.data.Error.Message
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
let maxName = 0;
|
|
96
|
-
let maxProviderType = 0;
|
|
97
|
-
for (let entry of result.data.Response) {
|
|
98
|
-
if (maxName < entry.name.length) {
|
|
99
|
-
maxName = entry.name.length;
|
|
100
|
-
}
|
|
101
|
-
if (maxProviderType < (entry.provider.length + entry.type.length)) {
|
|
102
|
-
maxProviderType = entry.provider.length + entry.type.length;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const nameInfo = i18n.__('Name');
|
|
107
|
-
const providerTypeInfo = i18n.__('Provider & Type');
|
|
108
|
-
let tempNameLength;
|
|
109
|
-
let tempProviderTypeLength;
|
|
110
|
-
if (nameInfo === 'Name') {
|
|
111
|
-
tempNameLength = maxName - nameInfo.length;
|
|
112
|
-
tempProviderTypeLength = maxProviderType - providerTypeInfo.length;
|
|
113
|
-
} else {
|
|
114
|
-
tempNameLength = maxName - nameInfo.length * 2;
|
|
115
|
-
tempProviderTypeLength = maxProviderType - providerTypeInfo.length * 2 + 1;
|
|
116
|
-
}
|
|
117
|
-
logger.info(`${nameInfo}${await printn(tempNameLength, ' ')} ${providerTypeInfo}${await printn(tempProviderTypeLength, ' ')} ${i18n.__('Description')}\n`);
|
|
118
|
-
for (let entry of result.data.Response) {
|
|
119
|
-
const tempNameLength = await printn(maxName - entry.name.length, ' ');
|
|
120
|
-
const tempConString = entry.provider && entry.type ? '@' : '';
|
|
121
|
-
const tempProviderTypeLength = await printn(maxProviderType - entry.provider.length - entry.type.length + (entry.provider && entry.type ? 0 : 1), ' ');
|
|
122
|
-
logger.info(`${entry.name}${tempNameLength} ${entry.provider}${tempConString}${entry.type}${tempProviderTypeLength} ${entry.description}`);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
logger.info('');
|
|
126
|
-
|
|
127
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import * as program from 'commander';
|
|
2
|
-
import { setConfig } from '../../utils/handler-set-config';
|
|
3
|
-
import logger from '../../utils/logger';
|
|
4
|
-
import i18n from '../../utils/i18n';
|
|
5
|
-
import { SetAnalysisError } from '../../error/set-analysis-error';
|
|
6
|
-
import {CommandError} from '../../error/command-error';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
program
|
|
10
|
-
.name('s set analysis')
|
|
11
|
-
.usage('[options] [name]')
|
|
12
|
-
.helpOption('-h, --help', i18n.__('Display help for command'))
|
|
13
|
-
.description(`${i18n.__('Upload your usage habits to help us improve our products')}
|
|
14
|
-
|
|
15
|
-
${i18n.__('Example')}:
|
|
16
|
-
# ${i18n.__('Upload your usage habits')}:
|
|
17
|
-
$ s set analysis enable
|
|
18
|
-
# ${i18n.__('Do not upload your usage habits')}:
|
|
19
|
-
$ s set analysis disable`)
|
|
20
|
-
.parse(process.argv);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
(async () => {
|
|
24
|
-
//console.log("language")
|
|
25
|
-
if (program.args.length === 0) {
|
|
26
|
-
program.help();
|
|
27
|
-
}
|
|
28
|
-
if (program.args.length > 1) {
|
|
29
|
-
throw new SetAnalysisError('Too many args input');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const flag = program.args[0].toLowerCase();
|
|
33
|
-
if (flag === 'enable') {
|
|
34
|
-
await setConfig('analysis', true);
|
|
35
|
-
} else if (flag === 'disable') {
|
|
36
|
-
await setConfig('analysis', false);
|
|
37
|
-
} else {
|
|
38
|
-
throw new SetAnalysisError('Unknown input: {{input}}', {input: flag});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
logger.success('Setup succeeded');
|
|
42
|
-
|
|
43
|
-
})().catch((err) => {
|
|
44
|
-
throw new CommandError(err.message);
|
|
45
|
-
});
|
package/src/set/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as program from 'commander';
|
|
2
|
-
import registerCommandChecker from '../utils/command';
|
|
3
|
-
import i18n from '../utils/i18n';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
program
|
|
7
|
-
.name('s set')
|
|
8
|
-
.usage('[commands] [options]')
|
|
9
|
-
.helpOption('-h, --help', i18n.__('Display help for command'))
|
|
10
|
-
.command('output-color', i18n.__('Control color output'))
|
|
11
|
-
.command('language', i18n.__('Output language switch'))
|
|
12
|
-
.command('analysis', i18n.__('Upload your usage habits to help us improve our products'))
|
|
13
|
-
.description(i18n.__('You can make some default settings for the tool here.'));
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
registerCommandChecker(program);
|
|
18
|
-
|
|
19
|
-
program.parse(process.argv);
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import * as program from 'commander';
|
|
2
|
-
import { setConfig } from '../../utils/handler-set-config';
|
|
3
|
-
import i18n from '../../utils/i18n';
|
|
4
|
-
import logger from '../../utils/logger';
|
|
5
|
-
import { SetLanguageError } from '../../error/set-language-error';
|
|
6
|
-
import {CommandError} from '../../error/command-error';
|
|
7
|
-
|
|
8
|
-
const defaultLanguage = ['zh', 'en'];
|
|
9
|
-
|
|
10
|
-
program
|
|
11
|
-
.name('s set language')
|
|
12
|
-
.usage('[options] [name]')
|
|
13
|
-
.helpOption('-h, --help', i18n.__('Display help for command'))
|
|
14
|
-
.description(`${i18n.__('You can set language.')}
|
|
15
|
-
|
|
16
|
-
${i18n.__('Example')}:
|
|
17
|
-
$ s set language zh
|
|
18
|
-
$ s set language en`)
|
|
19
|
-
.parse(process.argv);
|
|
20
|
-
|
|
21
|
-
(async () => {
|
|
22
|
-
|
|
23
|
-
if (program.args.length === 0) {
|
|
24
|
-
program.help();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (program.args.length > 0) {
|
|
28
|
-
const lang = program.args[0];
|
|
29
|
-
if (defaultLanguage.indexOf(lang) === -1) {
|
|
30
|
-
throw new SetLanguageError('Setup failed');
|
|
31
|
-
} else {
|
|
32
|
-
setConfig('locale', lang);
|
|
33
|
-
logger.success('Setup succeeded');
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
})().catch((err) => {
|
|
38
|
-
throw new CommandError(err.message);
|
|
39
|
-
});
|