@serverless-devs/s 0.0.44 → 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,135 +0,0 @@
|
|
|
1
|
-
import { DownloadManager } from "../../src/init/download-manager";
|
|
2
|
-
import * as fs from "fs-extra";
|
|
3
|
-
import * as download from "download";
|
|
4
|
-
import * as path from "path";
|
|
5
|
-
import * as os from "os";
|
|
6
|
-
import * as childProcess from 'child_process';
|
|
7
|
-
import * as urlParser from "../../src/utils/url-parser";
|
|
8
|
-
import { expect } from "chai";
|
|
9
|
-
const sinon = require('sinon');
|
|
10
|
-
const assert = require('assert');
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
describe('InitManager', function () {
|
|
14
|
-
let downloadManager: DownloadManager;
|
|
15
|
-
|
|
16
|
-
before(() => {
|
|
17
|
-
downloadManager = new DownloadManager();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
describe('#downloadTemplateByUrl()', function () {
|
|
22
|
-
let sandbox = sinon.createSandbox();
|
|
23
|
-
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
afterEach(() => {
|
|
28
|
-
sandbox.restore();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('should download and copy for normal git template', async function () {
|
|
32
|
-
const notExistsDir = "notExistsDirJustForUnitTest";
|
|
33
|
-
const zipFile = "http://github.com/test/test.zip";
|
|
34
|
-
const repoName = "test";
|
|
35
|
-
|
|
36
|
-
sandbox.stub(downloadManager, 'proxyDownload');
|
|
37
|
-
const copySyncStub = sandbox.stub(fs, 'copySync');
|
|
38
|
-
await downloadManager.downloadTemplateByUrl({zipFile: zipFile, hasSubPath:false, repoName:repoName}, notExistsDir);
|
|
39
|
-
copySyncStub.calledWith(path.join(os.tmpdir(), repoName), notExistsDir, {dereference:true});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should download and copy sub dir for git template with subDir', async function () {
|
|
43
|
-
const notExistsDir = "notExistsDirJustForUnitTest";
|
|
44
|
-
const zipFile = "http://github.com/test/test.zip";
|
|
45
|
-
const repoName = "test";
|
|
46
|
-
const subpath = "subpath";
|
|
47
|
-
|
|
48
|
-
sandbox.stub(downloadManager, 'proxyDownload');
|
|
49
|
-
const copySyncStub = sandbox.stub(fs, 'copySync');
|
|
50
|
-
await downloadManager.downloadTemplateByUrl({zipFile: zipFile, hasSubPath:true, subPath:subpath, repoName:repoName}, notExistsDir);
|
|
51
|
-
const srcDir = path.join(os.tmpdir(), repoName, subpath);
|
|
52
|
-
const destDir = path.join(notExistsDir, subpath);
|
|
53
|
-
copySyncStub.calledWith(path.join(os.tmpdir(), repoName), notExistsDir, {dereference:true});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should throw error if output dir exists for http template', async function () {
|
|
57
|
-
const dir = "test";
|
|
58
|
-
const zipFile = "http://github.com/test/test.zip";
|
|
59
|
-
const repoName = "test";
|
|
60
|
-
const execStub = sandbox.stub(childProcess, 'exec');
|
|
61
|
-
sandbox.stub(fs, 'existsSync').returns(true);
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
await downloadManager.downloadTemplateByUrl({zipFile: zipFile, hasSubPath:false, repoName:repoName}, dir);
|
|
65
|
-
assert.fail("should throw an error");
|
|
66
|
-
} catch(err) {
|
|
67
|
-
expect(err).to.match(/Directory already exists/);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe('#downloadTemplateByGitClone()', function () {
|
|
73
|
-
let sandbox = sinon.createSandbox();
|
|
74
|
-
|
|
75
|
-
beforeEach(() => {
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
afterEach(() => {
|
|
79
|
-
sandbox.restore();
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('should clone git template for git protocol', async function () {
|
|
83
|
-
const notExistsDir = "notExistsDirJustForUnitTest";
|
|
84
|
-
const url = "git@github.com:mochajs/mocha.git";
|
|
85
|
-
const execStub = sandbox.stub(childProcess, 'exec');
|
|
86
|
-
|
|
87
|
-
downloadManager.downloadTemplateByGitClone(urlParser.parse(url), notExistsDir);
|
|
88
|
-
execStub.calledWith(`git clone ${url} ${notExistsDir}`);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should throw error if output dir exists for git clone', async function () {
|
|
92
|
-
const dir = "test";
|
|
93
|
-
const url = "git@github.com:mochajs/mocha.git";
|
|
94
|
-
const execStub = sandbox.stub(childProcess, 'exec');
|
|
95
|
-
sandbox.stub(fs, 'existsSync').returns(true);
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
await downloadManager.downloadTemplateByGitClone(urlParser.parse(url), dir);
|
|
99
|
-
assert.fail("should throw an error");
|
|
100
|
-
} catch(err) {
|
|
101
|
-
expect(err).to.match(/Directory already exists/);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should throw error if exec failed', async function () {
|
|
106
|
-
const notExistsDir = "notExistsDirJustForUnitTest";
|
|
107
|
-
const url = "git@github.com:mochajs/mocha.git";
|
|
108
|
-
const execStub = sandbox.stub(childProcess, 'exec');
|
|
109
|
-
execStub.throws(new Error("Failed"));
|
|
110
|
-
|
|
111
|
-
try {
|
|
112
|
-
await downloadManager.downloadTemplateByGitClone(urlParser.parse(url), notExistsDir);
|
|
113
|
-
assert.fail("should throw an error");
|
|
114
|
-
} catch(err) {
|
|
115
|
-
expect(err).to.match(/Failed/);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
/*
|
|
121
|
-
async downloadTemplateByGitClone(url: URL.Url, outputDir: string) {
|
|
122
|
-
if (fs.existsSync(outputDir)) {
|
|
123
|
-
throw new Error("Directory already exists: " + outputDir);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
let cmd = `git clone ${url.href} ${outputDir}`;
|
|
127
|
-
const exec = util.promisify(ChildProcess.exec);
|
|
128
|
-
try {
|
|
129
|
-
await exec(cmd);
|
|
130
|
-
} catch(err) {
|
|
131
|
-
throw err;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
*/
|
|
135
|
-
});
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { InitManager } from "../../src/init/init-manager";
|
|
2
|
-
import { DownloadManager } from "../../src/init/download-manager";
|
|
3
|
-
import axios from "axios";
|
|
4
|
-
import * as inquirer from "inquirer";
|
|
5
|
-
|
|
6
|
-
const chai = require('chai');
|
|
7
|
-
const sinon = require('sinon');
|
|
8
|
-
chai.use(require('sinon-chai'));
|
|
9
|
-
const { expect } = require('chai');
|
|
10
|
-
const assert = require('assert');
|
|
11
|
-
|
|
12
|
-
describe('InitManager', function () {
|
|
13
|
-
let initManager: InitManager;
|
|
14
|
-
|
|
15
|
-
before(() => {
|
|
16
|
-
initManager = new InitManager();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe('#init()', function () {
|
|
20
|
-
let sandbox = sinon.createSandbox();
|
|
21
|
-
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
afterEach(() => {
|
|
26
|
-
sandbox.restore();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should init success if download url template succeeds', async function () {
|
|
30
|
-
try {
|
|
31
|
-
//stub to return
|
|
32
|
-
const downloadUrlTemplateStub = sandbox.stub(initManager, 'downloadUrlTemplate');
|
|
33
|
-
downloadUrlTemplateStub.resolves("success");
|
|
34
|
-
//call method
|
|
35
|
-
await initManager.init("https://github.com/TypeStrong/ts-node", "test provider");
|
|
36
|
-
//expect call once
|
|
37
|
-
expect(downloadUrlTemplateStub).to.have.been.calledOnce;
|
|
38
|
-
} catch (err) {
|
|
39
|
-
assert.fail(err);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should init success if download app template succeeds', async function () {
|
|
44
|
-
try {
|
|
45
|
-
const downloadAppTemplateStub = sandbox.stub(initManager, 'downloadAppTemplate');
|
|
46
|
-
//stub to return
|
|
47
|
-
downloadAppTemplateStub.resolves("success");
|
|
48
|
-
//call method
|
|
49
|
-
await initManager.init("test app", "test provider");
|
|
50
|
-
//expect call once
|
|
51
|
-
expect(downloadAppTemplateStub).to.have.been.calledOnce;
|
|
52
|
-
} catch (err) {
|
|
53
|
-
assert.fail(err);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should throw error if downloadAppTemplate fail', async function () {
|
|
58
|
-
try {
|
|
59
|
-
const downloadAppTemplateStub = sandbox.stub(initManager, 'downloadAppTemplate');
|
|
60
|
-
//(sinon) stub to throw a exception
|
|
61
|
-
downloadAppTemplateStub.rejects(new Error("Failed"));
|
|
62
|
-
//call method
|
|
63
|
-
await initManager.init("test app", "test provider");
|
|
64
|
-
//should not reach
|
|
65
|
-
assert.fail("Exception not thrown");
|
|
66
|
-
} catch (err) {
|
|
67
|
-
//use Chai to check error thrown if expected
|
|
68
|
-
expect(err).to.match(/Failed/);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should throw error if downloadUrlTemplate fail', async function () {
|
|
73
|
-
try {
|
|
74
|
-
//stub to throw a exception
|
|
75
|
-
const downloadUrlTemplateStub = sandbox.stub(initManager, 'downloadUrlTemplate');
|
|
76
|
-
downloadUrlTemplateStub.rejects(new Error("Failed"));
|
|
77
|
-
//call method
|
|
78
|
-
await initManager.init("https://github.com/TypeStrong/ts-node", "test provider");
|
|
79
|
-
//should not reach
|
|
80
|
-
assert.fail("Exception not thrown");
|
|
81
|
-
} catch (err) {
|
|
82
|
-
//use Chai to check error thrown if expected
|
|
83
|
-
expect(err).to.match(/Failed/);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('#downloadAppTemplate()', function () {
|
|
90
|
-
let sandbox = sinon.createSandbox();
|
|
91
|
-
|
|
92
|
-
beforeEach(() => {
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
afterEach(() => {
|
|
96
|
-
sandbox.restore();
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('should call getAppProvider if provider not provided', async function () {
|
|
100
|
-
const provider = "Aliyun";
|
|
101
|
-
const project = "test project";
|
|
102
|
-
|
|
103
|
-
const getAppProviderStub = sandbox.stub(initManager, "getAppProvider");
|
|
104
|
-
getAppProviderStub.resolves(provider);
|
|
105
|
-
//stub app download
|
|
106
|
-
const getAppDownloadUrlStub = sandbox.stub(initManager, "getAppDownloadUrl");
|
|
107
|
-
getAppDownloadUrlStub.withArgs(project, provider).resolves("https://oss.aliyun.com/app");
|
|
108
|
-
//stub downloadManager
|
|
109
|
-
let downloadManager = new DownloadManager();
|
|
110
|
-
sandbox.stub(initManager, "downloadManager").value(downloadManager);
|
|
111
|
-
//stub downloadManager.downloadTemplateByUrl
|
|
112
|
-
const downloadTemplateByUrlStub = sandbox.stub(downloadManager, "downloadTemplateByUrl");
|
|
113
|
-
downloadTemplateByUrlStub.resolves("success")
|
|
114
|
-
//call method
|
|
115
|
-
await initManager.downloadAppTemplate(project);
|
|
116
|
-
expect(getAppProviderStub).to.have.been.calledOnce;
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('should throw InitError if get provider failed', async function() {
|
|
120
|
-
const provider = "Aliyun";
|
|
121
|
-
const project = "test project";
|
|
122
|
-
|
|
123
|
-
const getAppProviderStub = sandbox.stub(initManager, "getAppProvider");
|
|
124
|
-
const msg = "Failed to get app provider";
|
|
125
|
-
getAppProviderStub.rejects(new Error(msg));
|
|
126
|
-
//call method
|
|
127
|
-
try {
|
|
128
|
-
await initManager.downloadAppTemplate(project);
|
|
129
|
-
assert.fail('should thrown a error');
|
|
130
|
-
} catch(err) {
|
|
131
|
-
expect(err.message).to.include(msg);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
describe('#getAppDownloadUrl()', function () {
|
|
137
|
-
let sandbox = sinon.createSandbox();
|
|
138
|
-
|
|
139
|
-
beforeEach(() => {
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
afterEach(() => {
|
|
143
|
-
sandbox.restore();
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('should return app download url if request successfully', async function () {
|
|
147
|
-
const appDownloadUrl = "https://oss.aliyun.com";
|
|
148
|
-
sandbox.stub(axios, 'request').resolves({status: 200, data:{Response:{Url: appDownloadUrl}}});
|
|
149
|
-
//call
|
|
150
|
-
const url = await initManager.getAppDownloadUrl("test project", "test provider");
|
|
151
|
-
expect(url).to.equal(appDownloadUrl);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
describe('#getAppProvider()', function () {
|
|
156
|
-
let sandbox = sinon.createSandbox();
|
|
157
|
-
|
|
158
|
-
beforeEach(() => {
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
afterEach(() => {
|
|
162
|
-
sandbox.restore();
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('should return app providers if request successfully', async function () {
|
|
166
|
-
const aliyunProvider = "Aliyun";
|
|
167
|
-
sandbox.stub(axios, 'request').resolves({status: 200, data:{Response:{Providers: [aliyunProvider]}}});
|
|
168
|
-
sandbox.stub(inquirer, 'prompt').resolves({provider: aliyunProvider});
|
|
169
|
-
//call
|
|
170
|
-
const provider = await initManager.getAppProvider("test project");
|
|
171
|
-
expect(provider).to.equal(aliyunProvider);
|
|
172
|
-
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
describe('#downloadUrlTemplate()', function () {
|
|
177
|
-
let sandbox = sinon.createSandbox();
|
|
178
|
-
|
|
179
|
-
beforeEach(() => {
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
afterEach(() => {
|
|
183
|
-
sandbox.restore();
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('should call downloadManager.downloadTemplateByUrl() for http git address', async function () {
|
|
187
|
-
const url = "https://github.com/mochajs/mocha";
|
|
188
|
-
|
|
189
|
-
let downloadManager = new DownloadManager();
|
|
190
|
-
sandbox.stub(initManager, "downloadManager").value(downloadManager);
|
|
191
|
-
const downloadTemplateByUrlStub = sandbox.stub(downloadManager, "downloadTemplateByUrl");
|
|
192
|
-
|
|
193
|
-
await initManager.downloadUrlTemplate(url);
|
|
194
|
-
|
|
195
|
-
expect(downloadTemplateByUrlStub).to.have.been.calledOnce;
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('should call downloadManager.downloadTemplateByUrl() for http git address', async function () {
|
|
199
|
-
const url = "git@github.com:mochajs/mocha.git";
|
|
200
|
-
|
|
201
|
-
let downloadManager = new DownloadManager();
|
|
202
|
-
sandbox.stub(initManager, "downloadManager").value(downloadManager);
|
|
203
|
-
const downloadTemplateByGitCloneStub = sandbox.stub(downloadManager, "downloadTemplateByGitClone");
|
|
204
|
-
|
|
205
|
-
await initManager.downloadUrlTemplate(url);
|
|
206
|
-
|
|
207
|
-
expect(downloadTemplateByGitCloneStub).to.have.been.calledOnce;
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it('should throw error if unexpected protocol', async function () {
|
|
211
|
-
const url = "ssh://host";
|
|
212
|
-
|
|
213
|
-
try {
|
|
214
|
-
await initManager.downloadUrlTemplate(url);
|
|
215
|
-
assert.fail("should throw an error");
|
|
216
|
-
} catch(err) {
|
|
217
|
-
expect(err).to.match(/Unknown project format/);
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it('should throw error if unexpected host', async function () {
|
|
222
|
-
const url = "http://unknown.com/";
|
|
223
|
-
|
|
224
|
-
try {
|
|
225
|
-
await initManager.downloadUrlTemplate(url);
|
|
226
|
-
assert.fail("should throw an error");
|
|
227
|
-
} catch(err) {
|
|
228
|
-
expect(err).to.match(/Unknown host/);
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import * as urlParser from "../../src/utils/url-parser";
|
|
2
|
-
const sinon = require('sinon');
|
|
3
|
-
const assert = require('assert');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
describe('UrlParser', function () {
|
|
7
|
-
|
|
8
|
-
describe('#getProjectNameFromUrl()', function () {
|
|
9
|
-
let sandbox = sinon.createSandbox();
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
afterEach(() => {
|
|
15
|
-
sandbox.restore();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should extract project name for http git url without .git', async function () {
|
|
19
|
-
const url = "https://github.com/mochajs/mocha";
|
|
20
|
-
const name = urlParser.getProjectNameFromUrl(url);
|
|
21
|
-
assert.equal(name, "mocha");
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should extract template for http git url with .git', async function () {
|
|
25
|
-
const url = "https://github.com/mochajs/mocha.git";
|
|
26
|
-
const {repoName, branch, ownerName} = urlParser.extractTemplateInfo(urlParser.parse(url));
|
|
27
|
-
assert.equal(repoName, "mocha");
|
|
28
|
-
assert.equal(branch, "master");
|
|
29
|
-
assert.equal(ownerName, "mochajs");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should extract template for http git url without .git', async function () {
|
|
33
|
-
const url = "https://github.com/mochajs/mocha/tree/master/scripts";
|
|
34
|
-
const {repoName, branch, ownerName, subPath} = urlParser.extractTemplateInfo(urlParser.parse(url));
|
|
35
|
-
assert.equal(repoName, "mocha");
|
|
36
|
-
assert.equal(branch, "master");
|
|
37
|
-
assert.equal(ownerName, "mochajs");
|
|
38
|
-
assert.equal(subPath, "scripts");
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
//https://github.com/mochajs/mocha.git
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
const yaml = require('js-yaml');
|
|
3
|
-
import { Parse } from '../utils/parse';
|
|
4
|
-
import { Analysis } from '../utils/analysis';
|
|
5
|
-
import { checkTemplateFile } from '../utils/common';
|
|
6
|
-
import i18n from '../utils/i18n';
|
|
7
|
-
import { TEMPLATE_FILE } from '../constants/static-variable';
|
|
8
|
-
// eslint-disable-next-line no-unused-vars
|
|
9
|
-
import { ComponentExeCute, ComponentConfig, generateSynchronizeComponentExeList, synchronizeExecuteComponentList } from '../component';
|
|
10
|
-
import * as logger from '../utils/logger';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export default class CommandManager {
|
|
14
|
-
protected deployParams: any
|
|
15
|
-
constructor(protected templateFile: string, protected method: string, protected customerCommandName?: string, params?: any) {
|
|
16
|
-
this.deployParams = params;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async assemblyProjectConfig(parse: Parse, projectName: string, parsedObj: any): Promise<ComponentConfig> {
|
|
20
|
-
const realVariables = await parse.getRealVariables(parsedObj); // Get the original conversion data
|
|
21
|
-
const projectConfig = realVariables[projectName];
|
|
22
|
-
projectConfig.ProjectName = projectName;
|
|
23
|
-
if (this.deployParams) {
|
|
24
|
-
projectConfig.Params = this.deployParams;
|
|
25
|
-
}
|
|
26
|
-
return projectConfig;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
async init(): Promise<void> {
|
|
31
|
-
try {
|
|
32
|
-
logger.info(i18n.__('Start ......'));
|
|
33
|
-
const templateFile = checkTemplateFile(this.templateFile);
|
|
34
|
-
if (templateFile) {
|
|
35
|
-
let outPutData: any = {};
|
|
36
|
-
const parse = new Parse(templateFile);
|
|
37
|
-
const parsedObj = parse.getOriginalParsedObj();
|
|
38
|
-
|
|
39
|
-
if (this.customerCommandName) {
|
|
40
|
-
const projectConfig = await this.assemblyProjectConfig(parse, this.customerCommandName, parsedObj);
|
|
41
|
-
const componentExecute = new ComponentExeCute(projectConfig, this.method);
|
|
42
|
-
const tempResult = await componentExecute.init();
|
|
43
|
-
if (tempResult) {
|
|
44
|
-
outPutData[projectConfig.ProjectName] = tempResult;
|
|
45
|
-
}
|
|
46
|
-
} else {
|
|
47
|
-
const params = this.deployParams || '';
|
|
48
|
-
const realVariables = await parse.getRealVariables(parsedObj); // Get the original conversion data
|
|
49
|
-
const analysis = new Analysis(realVariables, parse.dependenciesMap);
|
|
50
|
-
const executeOrderList = analysis.getProjectOrder();
|
|
51
|
-
logger.info(i18n.__('It is detected that your project has the following project/projects < {{projects}} > to be execute', { projects: executeOrderList.join(',') }));
|
|
52
|
-
const componentList = generateSynchronizeComponentExeList({ list: executeOrderList, parse, parsedObj, method: this.method, params}, this.assemblyProjectConfig.bind(this));
|
|
53
|
-
const tempResult = await synchronizeExecuteComponentList(componentList);
|
|
54
|
-
for (const item in tempResult) {
|
|
55
|
-
if (executeOrderList.includes(item) && tempResult[item]) {
|
|
56
|
-
outPutData[item] = tempResult[item];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
let outResult: any;
|
|
62
|
-
try {
|
|
63
|
-
outResult = yaml.safeDump(JSON.parse(JSON.stringify(outPutData)));
|
|
64
|
-
} catch (ex) {
|
|
65
|
-
logger.error(ex);
|
|
66
|
-
logger.warning('Unable to format the output, the system will display the original output of the component:');
|
|
67
|
-
outResult = JSON.stringify(outPutData, null, ' ');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
logger.success(Object.keys(outPutData).length === 0 ? i18n.__('End of method: {{method}}', { method: this.method }) : outResult);
|
|
71
|
-
} else {
|
|
72
|
-
logger.error(i18n.__('Cannot find {{template}} file, please check the directory {{filepath}}', { template: TEMPLATE_FILE, filepath: this.templateFile }));
|
|
73
|
-
}
|
|
74
|
-
} catch (e) {
|
|
75
|
-
logger.error(e.message);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
package/src/command/index.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const { Command } = require('commander');
|
|
2
|
-
import CommandManager from './command-manager';
|
|
3
|
-
import { PROCESS_ENV_TEMPLATE_NAME } from '../constants/static-variable';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export default function create(command: string, customerCommandName?: string, description?: string) {
|
|
7
|
-
let params: Array<string> = [];
|
|
8
|
-
const _command = new Command(command);
|
|
9
|
-
let processArgv: Array<string> = [];
|
|
10
|
-
let start = false;
|
|
11
|
-
|
|
12
|
-
for (let i = 0; i < process.argv.length; i++) {
|
|
13
|
-
if (!start) {
|
|
14
|
-
processArgv.push(process.argv[i]);
|
|
15
|
-
} else {
|
|
16
|
-
params.push(process.argv[i]);
|
|
17
|
-
}
|
|
18
|
-
if (process.argv[i] === command) {
|
|
19
|
-
start = true;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (params.length !== 0) {
|
|
24
|
-
process.env.temp_params = params.join(' ');
|
|
25
|
-
} else {
|
|
26
|
-
params = process.env.temp_params ? process.env.temp_params.split(' ') : [];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
process.argv = processArgv;
|
|
30
|
-
|
|
31
|
-
_command
|
|
32
|
-
.description(description || '')
|
|
33
|
-
.action(() => {
|
|
34
|
-
const template: string | undefined = process['env'][PROCESS_ENV_TEMPLATE_NAME];
|
|
35
|
-
if (template) {
|
|
36
|
-
const commandManager = new CommandManager(template, command, customerCommandName, params.join(' '));
|
|
37
|
-
commandManager.init();
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
return _command;
|
|
41
|
-
}
|
|
42
|
-
|
package/src/component/hook.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const util = require('util');
|
|
4
|
-
import i18n from '../utils/i18n';
|
|
5
|
-
const exec = util.promisify(require('child_process').exec);
|
|
6
|
-
import { PluginExeCute } from '../plugin';
|
|
7
|
-
import * as logger from '../utils/logger';
|
|
8
|
-
export interface HookConfig {
|
|
9
|
-
Pre: boolean;
|
|
10
|
-
Plugin?: string;
|
|
11
|
-
Hook?: string;
|
|
12
|
-
Path?: string;
|
|
13
|
-
}
|
|
14
|
-
export class Hook {
|
|
15
|
-
preHooks: Array<HookConfig> = [];
|
|
16
|
-
afterHooks: Array<HookConfig> = [];
|
|
17
|
-
constructor(extendsParams: Array<HookConfig> = []) {
|
|
18
|
-
extendsParams.forEach((_extend: HookConfig) => {
|
|
19
|
-
if (_extend.Pre) {
|
|
20
|
-
this.preHooks.push(_extend);
|
|
21
|
-
} else {
|
|
22
|
-
this.afterHooks.push(_extend);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async executePreHook() {
|
|
28
|
-
if (this.preHooks.length > 0) {
|
|
29
|
-
logger.info(i18n.__('Start the pre-hook'));
|
|
30
|
-
for (let i = 0;i < this.preHooks.length;i++) {
|
|
31
|
-
logger.info(`[Hook / Plugin] ${this.preHooks[i]['Hook'] || this.preHooks[i]['Plugin']}`);
|
|
32
|
-
try {
|
|
33
|
-
await this.executeByConfig(this.preHooks[i]);
|
|
34
|
-
} catch (ex) {
|
|
35
|
-
logger.error(`[Hook / Plugin] [Error]: ${ex.stdout || ex.stderr}`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
logger.info(i18n.__('End the pre-hook'));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async executeAfterHook() {
|
|
43
|
-
if (this.afterHooks.length > 0) {
|
|
44
|
-
logger.info(i18n.__('Start the after-hook'));
|
|
45
|
-
|
|
46
|
-
// 2020-9-23 修复afterHooks无法处理的bug
|
|
47
|
-
for (let i = 0;i < this.afterHooks.length;i++) {
|
|
48
|
-
logger.info(`[Hook / Plugin] ${this.afterHooks[i]['Hook'] || this.afterHooks[i]['Plugin']}`);
|
|
49
|
-
try {
|
|
50
|
-
await this.executeByConfig(this.afterHooks[i]);
|
|
51
|
-
} catch (ex) {
|
|
52
|
-
logger.error(`[Hook / Plugin] [Error]: ${ex.stdout || ex.stderr}`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
logger.info(i18n.__('End the after-hook'));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
async commandExecute(command: string, executePath: string | undefined) {
|
|
60
|
-
const currentDir = process.cwd();
|
|
61
|
-
const cwdPath = executePath ? path.resolve(currentDir, executePath) : currentDir;
|
|
62
|
-
if (fs.existsSync(cwdPath) && fs.lstatSync(cwdPath).isDirectory()) {
|
|
63
|
-
process.env['next-command-execute-flag'] = 'true';
|
|
64
|
-
logger.info(i18n.__('Executing ...'));
|
|
65
|
-
const { stdout, stderr } = await exec(command, { cwd: cwdPath });
|
|
66
|
-
if (stderr) {
|
|
67
|
-
logger.error(i18n.__('Execute:'), stderr);
|
|
68
|
-
} else {
|
|
69
|
-
logger.info(i18n.__('Execute:'), stdout);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async pluginExecute(name: string) {
|
|
75
|
-
const pluginInstance = new PluginExeCute({ name });
|
|
76
|
-
await pluginInstance.init();
|
|
77
|
-
const pluginModule = await pluginInstance.loadPlugin();
|
|
78
|
-
pluginModule.apply(null, []);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async executeByConfig(hookConfig: HookConfig) {
|
|
82
|
-
if (hookConfig.Hook) {
|
|
83
|
-
await this.commandExecute(hookConfig.Hook, hookConfig.Path);
|
|
84
|
-
} else if (hookConfig.Plugin) {
|
|
85
|
-
await this.pluginExecute(hookConfig.Plugin);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|