@adobe/create-ccweb-add-on 3.0.0 → 3.2.0
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/.c8rc.json +4 -1
- package/bin/run.js +1 -2
- package/dist/app/AddOnFactory.d.ts +30 -3
- package/dist/app/AddOnFactory.d.ts.map +1 -1
- package/dist/app/AddOnFactory.js +140 -1
- package/dist/app/{AddOnPackageManager.d.ts → PackageManager.d.ts} +2 -2
- package/dist/app/PackageManager.d.ts.map +1 -0
- package/dist/app/{AddOnPackageManager.js → PackageManager.js} +2 -2
- package/dist/app/TemplateSelector.d.ts +20 -4
- package/dist/app/TemplateSelector.d.ts.map +1 -1
- package/dist/app/TemplateSelector.js +142 -1
- package/dist/app/index.d.ts +1 -3
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +1 -3
- package/dist/commands/create.d.ts +1 -1
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/config/inversify.config.d.ts +1 -1
- package/dist/config/inversify.config.d.ts.map +1 -1
- package/dist/config/inversify.config.js +8 -6
- package/dist/templates/react-javascript/template.json +2 -2
- package/dist/templates/react-javascript-with-document-sandbox/template.json +2 -2
- package/dist/templates/react-typescript/template.json +2 -2
- package/dist/templates/react-typescript-with-document-sandbox/template.json +2 -2
- package/dist/templates/swc-javascript/template.json +2 -2
- package/dist/templates/swc-javascript-with-document-sandbox/template.json +2 -2
- package/dist/templates/swc-typescript/template.json +2 -2
- package/dist/templates/swc-typescript-with-document-sandbox/template.json +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/validators/DirectoryValidator.d.ts +22 -11
- package/dist/validators/DirectoryValidator.d.ts.map +1 -1
- package/dist/validators/DirectoryValidator.js +152 -1
- package/dist/validators/EnvironmentValidator.d.ts +17 -2
- package/dist/validators/EnvironmentValidator.d.ts.map +1 -1
- package/dist/validators/EnvironmentValidator.js +149 -1
- package/dist/validators/index.d.ts +0 -2
- package/dist/validators/index.d.ts.map +1 -1
- package/dist/validators/index.js +0 -2
- package/package.json +8 -8
- package/src/app/AddOnFactory.ts +164 -4
- package/src/app/{AddOnPackageManager.ts → PackageManager.ts} +1 -1
- package/src/app/TemplateSelector.ts +157 -5
- package/src/app/index.ts +1 -3
- package/src/commands/create.ts +1 -1
- package/src/config/inversify.config.ts +10 -9
- package/src/test/app/{WxpAddOnFactory.spec.ts → AddOnFactory.spec.ts} +7 -6
- package/src/test/app/{AddOnPackageManager.spec.ts → PackageManager.spec.ts} +3 -6
- package/src/test/app/{AddOnTemplateSelector.spec.ts → TemplateSelector.spec.ts} +27 -14
- package/src/test/commands/command.spec.ts +1 -1
- package/src/test/commands/create.spec.ts +2 -2
- package/src/test/models/CLIOptions.spec.ts +1 -1
- package/src/test/validators/{AddOnDirectoryValidator.spec.ts → DirectoryValidator.spec.ts} +5 -6
- package/src/test/validators/{NodeEnvironmentValidator.spec.ts → EnvironmentValidator.spec.ts} +6 -19
- package/src/validators/DirectoryValidator.ts +172 -11
- package/src/validators/EnvironmentValidator.ts +157 -5
- package/src/validators/index.ts +0 -2
- package/templates/react-javascript/template.json +2 -2
- package/templates/react-javascript-with-document-sandbox/template.json +2 -2
- package/templates/react-typescript/template.json +2 -2
- package/templates/react-typescript-with-document-sandbox/template.json +2 -2
- package/templates/swc-javascript/template.json +2 -2
- package/templates/swc-javascript-with-document-sandbox/template.json +2 -2
- package/templates/swc-typescript/template.json +2 -2
- package/templates/swc-typescript-with-document-sandbox/template.json +2 -2
- package/dist/app/AddOnPackageManager.d.ts.map +0 -1
- package/dist/app/AddOnTemplateSelector.d.ts +0 -54
- package/dist/app/AddOnTemplateSelector.d.ts.map +0 -1
- package/dist/app/AddOnTemplateSelector.js +0 -168
- package/dist/app/WxpAddOnFactory.d.ts +0 -62
- package/dist/app/WxpAddOnFactory.d.ts.map +0 -1
- package/dist/app/WxpAddOnFactory.js +0 -159
- package/dist/validators/AddOnDirectoryValidator.d.ts +0 -55
- package/dist/validators/AddOnDirectoryValidator.d.ts.map +0 -1
- package/dist/validators/AddOnDirectoryValidator.js +0 -176
- package/dist/validators/NodeEnvironmentValidator.d.ts +0 -58
- package/dist/validators/NodeEnvironmentValidator.d.ts.map +0 -1
- package/dist/validators/NodeEnvironmentValidator.js +0 -173
- package/src/app/AddOnTemplateSelector.ts +0 -193
- package/src/app/WxpAddOnFactory.ts +0 -196
- package/src/validators/AddOnDirectoryValidator.ts +0 -207
- package/src/validators/NodeEnvironmentValidator.ts +0 -197
|
@@ -21,5 +21,156 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
********************************************************************************/
|
|
24
|
-
|
|
24
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
25
|
+
import { ITypes as IAnalyticsTypes } from "@adobe/ccweb-add-on-analytics";
|
|
26
|
+
import { ITypes as ICoreTypes, isNullOrWhiteSpace } from "@adobe/ccweb-add-on-core";
|
|
27
|
+
import fs from "fs-extra";
|
|
28
|
+
import { inject, injectable } from "inversify";
|
|
29
|
+
import path from "path";
|
|
30
|
+
import process from "process";
|
|
31
|
+
import "reflect-metadata";
|
|
32
|
+
import format from "string-template";
|
|
33
|
+
import validate from "validate-npm-package-name";
|
|
34
|
+
import { AnalyticsErrorMarkers } from "../AnalyticsMarkers.js";
|
|
35
|
+
import { PROGRAM_NAME } from "../constants.js";
|
|
36
|
+
/**
|
|
37
|
+
* Directory validator implementation class to validate
|
|
38
|
+
* whether the directory can be used to create the add-on project.
|
|
39
|
+
*/
|
|
40
|
+
let DirectoryValidator = class DirectoryValidator {
|
|
41
|
+
_logger;
|
|
42
|
+
_analyticsService;
|
|
43
|
+
/**
|
|
44
|
+
* Instantiate {@link DirectoryValidator}.
|
|
45
|
+
* @param logger - {@link Logger} reference.
|
|
46
|
+
* @param analyticsService - {@link AnalyticsService} reference.
|
|
47
|
+
* @returns Reference to a new {@link DirectoryValidator} instance.
|
|
48
|
+
*/
|
|
49
|
+
constructor(logger, analyticsService) {
|
|
50
|
+
this._logger = logger;
|
|
51
|
+
this._analyticsService = analyticsService;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Validate the Add-on name.
|
|
55
|
+
* @param addOnName - Name of the Add-on.
|
|
56
|
+
*/
|
|
57
|
+
async validateAddOnName(addOnName) {
|
|
58
|
+
if (isNullOrWhiteSpace(addOnName)) {
|
|
59
|
+
this._logger.warning(LOGS.specifyAddOnName);
|
|
60
|
+
this._chooseDifferentAddOnName();
|
|
61
|
+
await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_NO_ADD_ON_NAME, LOGS.analyticsNoAddOnName, false);
|
|
62
|
+
return process.exit(0);
|
|
63
|
+
}
|
|
64
|
+
const isValid = validate(addOnName).validForNewPackages;
|
|
65
|
+
if (!isValid) {
|
|
66
|
+
this._logger.warning(format(LOGS.npmNamingRestriction, { addOnName }));
|
|
67
|
+
this._chooseDifferentAddOnName();
|
|
68
|
+
await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_INVALID_NAME_NPM, LOGS.analyticsInvalidAddOnNameNPM, false);
|
|
69
|
+
return process.exit(0);
|
|
70
|
+
}
|
|
71
|
+
const dependencies = new Set([
|
|
72
|
+
"@adobe/create-ccweb-add-on",
|
|
73
|
+
"create-ccweb-add-on",
|
|
74
|
+
"@adobe/ccweb-add-on-scripts",
|
|
75
|
+
"ccweb-add-on-scripts",
|
|
76
|
+
"@adobe/ccweb-add-on-scaffolder",
|
|
77
|
+
"ccweb-add-on-scaffolder"
|
|
78
|
+
]);
|
|
79
|
+
if (dependencies.has(addOnName)) {
|
|
80
|
+
this._logger.warning(format(LOGS.dependencyNamingRestriction, { addOnName }));
|
|
81
|
+
this._chooseDifferentAddOnName();
|
|
82
|
+
await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_INVALID_NAME_DEP, LOGS.analyticsInvalidAddOnNameDependency, false);
|
|
83
|
+
return process.exit(0);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Validate the addOn directory.
|
|
88
|
+
* @param addOnDirectory - Root directory of the addOn.
|
|
89
|
+
* @param addOnName - Name of the addOn.
|
|
90
|
+
*/
|
|
91
|
+
async validateAddOnDirectory(addOnDirectory, addOnName) {
|
|
92
|
+
fs.ensureDirSync(addOnName);
|
|
93
|
+
const validFiles = [
|
|
94
|
+
".DS_Store",
|
|
95
|
+
".git",
|
|
96
|
+
".gitattributes",
|
|
97
|
+
".gitignore",
|
|
98
|
+
".gitlab-ci.yml",
|
|
99
|
+
".hg",
|
|
100
|
+
".hgcheck",
|
|
101
|
+
".hgignore",
|
|
102
|
+
".idea",
|
|
103
|
+
".npmignore",
|
|
104
|
+
".travis.yml",
|
|
105
|
+
"docs",
|
|
106
|
+
"LICENSE",
|
|
107
|
+
"README.md",
|
|
108
|
+
"mkdocs.yml",
|
|
109
|
+
"Thumbs.db"
|
|
110
|
+
];
|
|
111
|
+
const errorLogFilePatterns = ["npm-debug.log"];
|
|
112
|
+
const isErrorLog = (file) => {
|
|
113
|
+
return errorLogFilePatterns.some(pattern => file.startsWith(pattern));
|
|
114
|
+
};
|
|
115
|
+
const existingFiles = fs.readdirSync(addOnDirectory, { withFileTypes: true });
|
|
116
|
+
const conflictingFiles = existingFiles
|
|
117
|
+
.filter(file => !validFiles.includes(file.name))
|
|
118
|
+
.filter(file => !/\.iml$/.test(file.name))
|
|
119
|
+
.filter(file => !isErrorLog(file.name));
|
|
120
|
+
if (conflictingFiles.length === 0) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
this._logger.warning(format(LOGS.directoryContainsFiles, { addOnName }), {
|
|
124
|
+
postfix: LOGS.newLine
|
|
125
|
+
});
|
|
126
|
+
for (const file of conflictingFiles) {
|
|
127
|
+
try {
|
|
128
|
+
if (fs.lstatSync(path.join(addOnDirectory, file.name)).isDirectory()) {
|
|
129
|
+
this._logger.warning(`${file.name}/`, { prefix: LOGS.tab });
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
this._logger.warning(`${file.name}`, { prefix: LOGS.tab });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
this._logger.warning(`${file.name}`, { prefix: LOGS.tab });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
this._logger.information(LOGS.newAddOnOrRemoveFiles, { prefix: LOGS.newLine });
|
|
140
|
+
await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_INVALID_NAME_DIR, LOGS.analyticsInvalidAddOnDir, false);
|
|
141
|
+
return process.exit(0);
|
|
142
|
+
}
|
|
143
|
+
_chooseDifferentAddOnName() {
|
|
144
|
+
this._logger.warning(format(LOGS.executeProgram, { PROGRAM_NAME }), { prefix: LOGS.tab });
|
|
145
|
+
this._logger.message(LOGS.forExample, { prefix: LOGS.newLine });
|
|
146
|
+
this._logger.information(format(LOGS.executeProgramExample, { PROGRAM_NAME }), {
|
|
147
|
+
prefix: LOGS.tab,
|
|
148
|
+
postfix: LOGS.newLine
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
DirectoryValidator = __decorate([
|
|
153
|
+
injectable(),
|
|
154
|
+
__param(0, inject(ICoreTypes.Logger)),
|
|
155
|
+
__param(1, inject(IAnalyticsTypes.AnalyticsService)),
|
|
156
|
+
__metadata("design:paramtypes", [Object, Function])
|
|
157
|
+
], DirectoryValidator);
|
|
158
|
+
export { DirectoryValidator };
|
|
159
|
+
const LOGS = {
|
|
160
|
+
newLine: "\n",
|
|
161
|
+
tab: " ",
|
|
162
|
+
specifyAddOnName: "Please specify an Add-on name",
|
|
163
|
+
executeProgram: "{PROGRAM_NAME} <add-on-name> --entrypoint <panel> --template <javascript>",
|
|
164
|
+
executeProgramExample: "{PROGRAM_NAME} my-add-on --entrypoint panel --template javascript",
|
|
165
|
+
forExample: "For example:",
|
|
166
|
+
npmNamingRestriction: "Cannot create a project named {addOnName} because of NPM naming restrictions.",
|
|
167
|
+
dependencyNamingRestriction: "Cannot create a project named {addOnName} because a dependency with the same name exists.",
|
|
168
|
+
chooseDifferentAddOnName: "Please choose a different Add-on name:",
|
|
169
|
+
directoryContainsFiles: "The directory {addOnName} contains files that could conflict:",
|
|
170
|
+
newAddOnOrRemoveFiles: "Either try using a new Add-on name, or remove the files listed above.",
|
|
171
|
+
analyticsNoAddOnName: "Add-on name was not specified",
|
|
172
|
+
analyticsInvalidAddOnNameNPM: "Invalid Add-on name. Npm name check failed",
|
|
173
|
+
analyticsInvalidAddOnNameDependency: "Invalid Add-on name. Dependency with same name exists",
|
|
174
|
+
analyticsInvalidAddOnDir: "Invalid Add-on name. Conflicting directory with same name exists"
|
|
175
|
+
};
|
|
25
176
|
//# sourceMappingURL=DirectoryValidator.js.map
|
|
@@ -21,11 +21,26 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
********************************************************************************/
|
|
24
|
+
import type { AnalyticsService } from "@adobe/ccweb-add-on-analytics";
|
|
25
|
+
import type { Logger, Process } from "@adobe/ccweb-add-on-core";
|
|
26
|
+
import "reflect-metadata";
|
|
24
27
|
/**
|
|
25
|
-
* Environment validator
|
|
28
|
+
* Environment validator implementation class to validate
|
|
26
29
|
* the system requirements required for running the app.
|
|
27
30
|
*/
|
|
28
|
-
export
|
|
31
|
+
export declare class EnvironmentValidator {
|
|
32
|
+
private readonly _process;
|
|
33
|
+
private readonly _logger;
|
|
34
|
+
private readonly _analyticsService;
|
|
35
|
+
/**
|
|
36
|
+
* Instantiate {@link EnvironmentValidator}.
|
|
37
|
+
*
|
|
38
|
+
* @param processHandler - {@link Process} reference.
|
|
39
|
+
* @param logger - {@link Logger} reference.
|
|
40
|
+
* @param analyticsService - {@link AnalyticsService} reference.
|
|
41
|
+
* @returns Reference to a new {@link EnvironmentValidator} instance.
|
|
42
|
+
*/
|
|
43
|
+
constructor(processHandler: Process, logger: Logger, analyticsService: AnalyticsService);
|
|
29
44
|
/**
|
|
30
45
|
* Validate the node version in the user's system.
|
|
31
46
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvironmentValidator.d.ts","sourceRoot":"","sources":["../../src/validators/EnvironmentValidator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF;;;GAGG;AACH,MAAM,
|
|
1
|
+
{"version":3,"file":"EnvironmentValidator.d.ts","sourceRoot":"","sources":["../../src/validators/EnvironmentValidator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAIhE,OAAO,kBAAkB,CAAC;AAM1B;;;GAGG;AACH,qBACa,oBAAoB;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IACrD;;;;;;;OAOG;gBAE6B,cAAc,EAAE,OAAO,EACxB,MAAM,EAAE,MAAM,EACC,gBAAgB,EAAE,gBAAgB;IAOhF;;OAEG;IACG,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IA2B1C;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAwCzC;;OAEG;IACG,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;CAmClD"}
|
|
@@ -21,5 +21,153 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
********************************************************************************/
|
|
24
|
-
|
|
24
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
25
|
+
import { ITypes as IAnalyticsTypes } from "@adobe/ccweb-add-on-analytics";
|
|
26
|
+
import { ITypes as ICoreTypes } from "@adobe/ccweb-add-on-core";
|
|
27
|
+
import { inject, injectable } from "inversify";
|
|
28
|
+
import process from "process";
|
|
29
|
+
import "reflect-metadata";
|
|
30
|
+
import semver from "semver";
|
|
31
|
+
import format from "string-template";
|
|
32
|
+
import { AnalyticsErrorMarkers } from "../AnalyticsMarkers.js";
|
|
33
|
+
import { PROGRAM_NAME } from "../constants.js";
|
|
34
|
+
/**
|
|
35
|
+
* Environment validator implementation class to validate
|
|
36
|
+
* the system requirements required for running the app.
|
|
37
|
+
*/
|
|
38
|
+
let EnvironmentValidator = class EnvironmentValidator {
|
|
39
|
+
_process;
|
|
40
|
+
_logger;
|
|
41
|
+
_analyticsService;
|
|
42
|
+
/**
|
|
43
|
+
* Instantiate {@link EnvironmentValidator}.
|
|
44
|
+
*
|
|
45
|
+
* @param processHandler - {@link Process} reference.
|
|
46
|
+
* @param logger - {@link Logger} reference.
|
|
47
|
+
* @param analyticsService - {@link AnalyticsService} reference.
|
|
48
|
+
* @returns Reference to a new {@link EnvironmentValidator} instance.
|
|
49
|
+
*/
|
|
50
|
+
constructor(processHandler, logger, analyticsService) {
|
|
51
|
+
this._process = processHandler;
|
|
52
|
+
this._logger = logger;
|
|
53
|
+
this._analyticsService = analyticsService;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Validate the node version in the user's system.
|
|
57
|
+
*/
|
|
58
|
+
async validateNodeVersion() {
|
|
59
|
+
const minNode = "18.0.0";
|
|
60
|
+
try {
|
|
61
|
+
const result = this._process.executeSync("node", ["--version"]);
|
|
62
|
+
const nodeVersion = String(result?.data)?.trim();
|
|
63
|
+
const hasMinNode = semver.gte(nodeVersion, minNode);
|
|
64
|
+
if (!hasMinNode) {
|
|
65
|
+
this._logger.warning(format(LOGS.usingNodeVersion, { nodeVersion }));
|
|
66
|
+
this._logger.information(format(LOGS.requiresHigherNode, {
|
|
67
|
+
PROGRAM_NAME,
|
|
68
|
+
minNode
|
|
69
|
+
}));
|
|
70
|
+
this._logger.information(LOGS.updateNodeVersion);
|
|
71
|
+
await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_INVALID_NODE, format(LOGS.analyticsInvalidNode, { nodeVersion }), false);
|
|
72
|
+
return process.exit(0);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
this._process.handleError(error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Validate the npm version in the user's system.
|
|
81
|
+
*/
|
|
82
|
+
async validateNpmVersion() {
|
|
83
|
+
const minNpm = "10.0.0";
|
|
84
|
+
try {
|
|
85
|
+
const result = this._process.executeSync("npm", ["--version"]);
|
|
86
|
+
const npmVersion = result.data ? String(result.data)?.trim() : undefined;
|
|
87
|
+
if (!npmVersion) {
|
|
88
|
+
this._logger.warning(LOGS.notUsingNpm);
|
|
89
|
+
this._logger.information(format(LOGS.requiresHigherNpm, {
|
|
90
|
+
PROGRAM_NAME,
|
|
91
|
+
minNpm
|
|
92
|
+
}));
|
|
93
|
+
this._logger.information(LOGS.installNpm);
|
|
94
|
+
await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_NO_NPM, LOGS.analyticsNoNpm, false);
|
|
95
|
+
return process.exit(0);
|
|
96
|
+
}
|
|
97
|
+
const hasMinNpm = semver.gte(npmVersion, minNpm);
|
|
98
|
+
if (!hasMinNpm) {
|
|
99
|
+
this._logger.warning(format(LOGS.usingNpmVersion, { npmVersion }));
|
|
100
|
+
this._logger.information(format(LOGS.requiresHigherNpm, {
|
|
101
|
+
PROGRAM_NAME,
|
|
102
|
+
minNpm
|
|
103
|
+
}));
|
|
104
|
+
this._logger.information(LOGS.updateNpm);
|
|
105
|
+
await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_INVALID_NPM, format(LOGS.analyticsInvalidNpm, { npmVersion }), false);
|
|
106
|
+
return process.exit(0);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
this._process.handleError(error);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Validate the npm configuration in the user's system.
|
|
115
|
+
*/
|
|
116
|
+
async validateNpmConfiguration() {
|
|
117
|
+
try {
|
|
118
|
+
const cwd = process.cwd();
|
|
119
|
+
const configList = this._process.executeSync("npm", ["config", "list"])?.data;
|
|
120
|
+
if (!configList) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const prefix = "; cwd = ";
|
|
124
|
+
const configLines = configList.split("\n");
|
|
125
|
+
const cwdLine = configLines.find(line => line.startsWith(prefix));
|
|
126
|
+
if (!cwdLine) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const npmCWD = cwdLine.substring(prefix.length);
|
|
130
|
+
if (npmCWD === cwd) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
this._logger.warning(LOGS.couldNotStartNpmProcess);
|
|
134
|
+
this._logger.information(format(LOGS.currentDirectory, { cwd }));
|
|
135
|
+
this._logger.information(format(LOGS.newNpmProcessRunsIn, { npmCWD }));
|
|
136
|
+
this._logger.information(LOGS.misconfiguredTerminalShell);
|
|
137
|
+
await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_NPM_NOT_STARTED, LOGS.analyticsNotStartNpm, false);
|
|
138
|
+
return process.exit(0);
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
EnvironmentValidator = __decorate([
|
|
146
|
+
injectable(),
|
|
147
|
+
__param(0, inject(ICoreTypes.Process)),
|
|
148
|
+
__param(1, inject(ICoreTypes.Logger)),
|
|
149
|
+
__param(2, inject(IAnalyticsTypes.AnalyticsService)),
|
|
150
|
+
__metadata("design:paramtypes", [Object, Object, Function])
|
|
151
|
+
], EnvironmentValidator);
|
|
152
|
+
export { EnvironmentValidator };
|
|
153
|
+
const LOGS = {
|
|
154
|
+
newLine: "\n",
|
|
155
|
+
tab: " ",
|
|
156
|
+
usingNodeVersion: "You are using node {nodeVersion}.",
|
|
157
|
+
requiresHigherNode: "{PROGRAM_NAME} requires node {minNode} or higher.",
|
|
158
|
+
updateNodeVersion: "Please update your version of node.",
|
|
159
|
+
notUsingNpm: "You are not using npm.",
|
|
160
|
+
requiresHigherNpm: "{PROGRAM_NAME} requires npm {minNpm} or higher.",
|
|
161
|
+
installNpm: "Please install npm.",
|
|
162
|
+
usingNpmVersion: "You are using npm {npmVersion}.",
|
|
163
|
+
updateNpm: "Please update your version of npm.",
|
|
164
|
+
couldNotStartNpmProcess: "Could not start an npm process in the right directory.",
|
|
165
|
+
currentDirectory: "The current directory is: {cwd}",
|
|
166
|
+
newNpmProcessRunsIn: "However, a newly started npm process runs in: {npmCWD}",
|
|
167
|
+
misconfiguredTerminalShell: "This is probably caused by a misconfigured system terminal shell.",
|
|
168
|
+
analyticsInvalidNode: "Invalid node version: {nodeVersion}",
|
|
169
|
+
analyticsNoNpm: "npm is not present",
|
|
170
|
+
analyticsInvalidNpm: "Invalid npm version: {npmVersion}",
|
|
171
|
+
analyticsNotStartNpm: "npm process could not be started"
|
|
172
|
+
};
|
|
25
173
|
//# sourceMappingURL=EnvironmentValidator.js.map
|
|
@@ -21,8 +21,6 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
********************************************************************************/
|
|
24
|
-
export * from "./AddOnDirectoryValidator.js";
|
|
25
24
|
export * from "./DirectoryValidator.js";
|
|
26
25
|
export * from "./EnvironmentValidator.js";
|
|
27
|
-
export * from "./NodeEnvironmentValidator.js";
|
|
28
26
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC"}
|
package/dist/validators/index.js
CHANGED
|
@@ -21,8 +21,6 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
********************************************************************************/
|
|
24
|
-
export * from "./AddOnDirectoryValidator.js";
|
|
25
24
|
export * from "./DirectoryValidator.js";
|
|
26
25
|
export * from "./EnvironmentValidator.js";
|
|
27
|
-
export * from "./NodeEnvironmentValidator.js";
|
|
28
26
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/create-ccweb-add-on",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"author": "Adobe",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Create an Adobe Creative Cloud Web Add-on.",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@oclif/core": "4.2.8",
|
|
36
|
-
"@swc/helpers": "0.5.
|
|
36
|
+
"@swc/helpers": "0.5.17",
|
|
37
37
|
"chalk": "4.1.1",
|
|
38
38
|
"fs-extra": "10.0.1",
|
|
39
39
|
"inversify": "6.0.1",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"string-template": "1.0.0",
|
|
45
45
|
"tslib": "2.7.0",
|
|
46
46
|
"validate-npm-package-name": "3.0.0",
|
|
47
|
-
"@adobe/ccweb-add-on-
|
|
48
|
-
"@adobe/ccweb-add-on-
|
|
49
|
-
"@adobe/ccweb-add-on-manifest": "3.
|
|
50
|
-
"@adobe/ccweb-add-on-scaffolder": "3.
|
|
47
|
+
"@adobe/ccweb-add-on-analytics": "3.2.0",
|
|
48
|
+
"@adobe/ccweb-add-on-core": "3.2.0",
|
|
49
|
+
"@adobe/ccweb-add-on-manifest": "3.2.0",
|
|
50
|
+
"@adobe/ccweb-add-on-scaffolder": "3.2.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@oclif/test": "4.1.12",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@types/sinon": "9.0.8",
|
|
62
62
|
"@types/string-template": "1.0.2",
|
|
63
63
|
"@types/validate-npm-package-name": "3.0.3",
|
|
64
|
-
"c8": "
|
|
64
|
+
"c8": "10.1.3",
|
|
65
65
|
"chai-as-promised": "7.1.1",
|
|
66
66
|
"chai": "4.3.4",
|
|
67
67
|
"mocha": "10.0.0",
|
|
@@ -80,6 +80,6 @@
|
|
|
80
80
|
"ibuild": "tsc",
|
|
81
81
|
"build": "rushx clean && rushx ibuild && rushx _postbuild",
|
|
82
82
|
"build:release": "rushx build",
|
|
83
|
-
"test": "c8 mocha && c8 check-coverage
|
|
83
|
+
"test": "c8 mocha && c8 check-coverage"
|
|
84
84
|
}
|
|
85
85
|
}
|
package/src/app/AddOnFactory.ts
CHANGED
|
@@ -22,15 +22,175 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
********************************************************************************/
|
|
24
24
|
|
|
25
|
+
import type { AnalyticsService } from "@adobe/ccweb-add-on-analytics";
|
|
26
|
+
import { ITypes as IAnalyticsTypes } from "@adobe/ccweb-add-on-analytics";
|
|
27
|
+
import type { Logger, Process } from "@adobe/ccweb-add-on-core";
|
|
28
|
+
import { ITypes as ICoreTypes } from "@adobe/ccweb-add-on-core";
|
|
29
|
+
import type { AddOnScaffolder } from "@adobe/ccweb-add-on-scaffolder";
|
|
30
|
+
import { ITypes as IScaffolderTypes, PACKAGE_JSON, ScaffolderOptions } from "@adobe/ccweb-add-on-scaffolder";
|
|
31
|
+
import fs from "fs-extra";
|
|
32
|
+
import { inject, injectable } from "inversify";
|
|
33
|
+
import os from "os";
|
|
34
|
+
import path from "path";
|
|
35
|
+
import process from "process";
|
|
36
|
+
import "reflect-metadata";
|
|
37
|
+
import format from "string-template";
|
|
38
|
+
import url from "url";
|
|
39
|
+
import { AnalyticsErrorMarkers, AnalyticsSuccessMarkers } from "../AnalyticsMarkers.js";
|
|
40
|
+
import { ITypes } from "../config/inversify.types.js";
|
|
41
|
+
import { TEMP_TEMPLATE_PATH } from "../constants.js";
|
|
25
42
|
import type { CLIOptions } from "../models/CLIOptions.js";
|
|
43
|
+
import { DirectoryValidator } from "../validators/DirectoryValidator.js";
|
|
44
|
+
import { EnvironmentValidator } from "../validators/EnvironmentValidator.js";
|
|
45
|
+
import { PackageManager } from "./PackageManager.js";
|
|
46
|
+
import { TemplateSelector } from "./TemplateSelector.js";
|
|
26
47
|
|
|
27
48
|
/**
|
|
28
|
-
*
|
|
49
|
+
* AddOn factory implementation class.
|
|
29
50
|
*/
|
|
30
|
-
|
|
51
|
+
@injectable()
|
|
52
|
+
export class AddOnFactory {
|
|
53
|
+
private readonly _directoryValidator: DirectoryValidator;
|
|
54
|
+
private readonly _environmentValidator: EnvironmentValidator;
|
|
55
|
+
private readonly _templateSelector: TemplateSelector;
|
|
56
|
+
|
|
57
|
+
private readonly _scaffolder: AddOnScaffolder;
|
|
58
|
+
|
|
59
|
+
private readonly _process: Process;
|
|
60
|
+
private readonly _logger: Logger;
|
|
61
|
+
|
|
62
|
+
private readonly _analyticsService: AnalyticsService;
|
|
63
|
+
|
|
31
64
|
/**
|
|
32
|
-
*
|
|
65
|
+
* Instantiate {@link AddOnFactory}.
|
|
66
|
+
* @param directoryValidator - {@link DirectoryValidator} reference.
|
|
67
|
+
* @param environmentValidator - {@link EnvironmentValidator} reference.
|
|
68
|
+
* @param templateSelector - {@link TemplateSelector} reference.
|
|
69
|
+
* @param scaffolder - {@link AddOnScaffolder} reference.
|
|
70
|
+
* @param cliProcess - {@link Process} reference.
|
|
71
|
+
* @param logger - {@link Logger} reference.
|
|
72
|
+
* @param analyticsService - {@link AnalyticsService} reference.
|
|
73
|
+
* @returns Reference to a new {@link AddOnFactory} instance.
|
|
74
|
+
*/
|
|
75
|
+
constructor(
|
|
76
|
+
@inject(ITypes.DirectoryValidator) directoryValidator: DirectoryValidator,
|
|
77
|
+
@inject(ITypes.EnvironmentValidator) environmentValidator: EnvironmentValidator,
|
|
78
|
+
@inject(ITypes.TemplateSelector) templateSelector: TemplateSelector,
|
|
79
|
+
@inject(IScaffolderTypes.AddOnScaffolder) scaffolder: AddOnScaffolder,
|
|
80
|
+
@inject(ICoreTypes.Process) cliProcess: Process,
|
|
81
|
+
@inject(ICoreTypes.Logger) logger: Logger,
|
|
82
|
+
@inject(IAnalyticsTypes.AnalyticsService) analyticsService: AnalyticsService
|
|
83
|
+
) {
|
|
84
|
+
this._directoryValidator = directoryValidator;
|
|
85
|
+
this._environmentValidator = environmentValidator;
|
|
86
|
+
this._templateSelector = templateSelector;
|
|
87
|
+
|
|
88
|
+
this._scaffolder = scaffolder;
|
|
89
|
+
|
|
90
|
+
this._process = cliProcess;
|
|
91
|
+
this._logger = logger;
|
|
92
|
+
|
|
93
|
+
this._analyticsService = analyticsService;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Create the Add-on project.
|
|
33
98
|
* @param options - {@link CLIOptions}.
|
|
34
99
|
*/
|
|
35
|
-
create(options: CLIOptions): Promise<void
|
|
100
|
+
async create(options: CLIOptions): Promise<void> {
|
|
101
|
+
let addOnDirectory = "";
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
await this._environmentValidator.validateNodeVersion();
|
|
105
|
+
await this._environmentValidator.validateNpmVersion();
|
|
106
|
+
await this._environmentValidator.validateNpmConfiguration();
|
|
107
|
+
|
|
108
|
+
await this._directoryValidator.validateAddOnName(options.addOnName);
|
|
109
|
+
addOnDirectory = path.resolve(options.addOnName);
|
|
110
|
+
await this._directoryValidator.validateAddOnDirectory(addOnDirectory, options.addOnName);
|
|
111
|
+
|
|
112
|
+
this._logger.information(LOGS.creatingAddOn);
|
|
113
|
+
this._logger.message(LOGS.mayTakeAMinute);
|
|
114
|
+
|
|
115
|
+
const templateName = await this._templateSelector.setupTemplate(options);
|
|
116
|
+
|
|
117
|
+
const packageJson = PackageManager.getPackageJson(options.entrypointType, options.addOnName);
|
|
118
|
+
const packageJsonPath = path.join(addOnDirectory, PACKAGE_JSON);
|
|
119
|
+
|
|
120
|
+
fs.writeFileSync(packageJsonPath, packageJson.toJSON() + os.EOL);
|
|
121
|
+
|
|
122
|
+
this._copyTemplateFiles(addOnDirectory, templateName);
|
|
123
|
+
|
|
124
|
+
const rootDirectory = process.cwd();
|
|
125
|
+
process.chdir(addOnDirectory);
|
|
126
|
+
|
|
127
|
+
const devDependencyArgs = [
|
|
128
|
+
"install",
|
|
129
|
+
"--save-dev",
|
|
130
|
+
"@adobe/ccweb-add-on-scripts",
|
|
131
|
+
"@types/adobe__ccweb-add-on-sdk"
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
if (options.verbose) {
|
|
135
|
+
devDependencyArgs.push("--verbose");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
this._logger.information(LOGS.installingDevDependencies, { prefix: LOGS.newLine });
|
|
139
|
+
await this._process.execute("npm", devDependencyArgs, { stdio: "inherit" });
|
|
140
|
+
|
|
141
|
+
const scaffolderOptions = new ScaffolderOptions(
|
|
142
|
+
addOnDirectory,
|
|
143
|
+
options.addOnName,
|
|
144
|
+
options.entrypointType,
|
|
145
|
+
rootDirectory,
|
|
146
|
+
templateName,
|
|
147
|
+
options.verbose
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
this._logger.information(format(LOGS.scaffoldingProjectFromTemplate, { templateName }), {
|
|
151
|
+
prefix: LOGS.newLine
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
await this._scaffolder.run(scaffolderOptions);
|
|
155
|
+
|
|
156
|
+
const analyticsEventData = [
|
|
157
|
+
"--addOnName",
|
|
158
|
+
options.addOnName,
|
|
159
|
+
"--entrypointType",
|
|
160
|
+
options.entrypointType,
|
|
161
|
+
"--template",
|
|
162
|
+
templateName
|
|
163
|
+
];
|
|
164
|
+
await this._analyticsService.postEvent(AnalyticsSuccessMarkers.SUCCESS, analyticsEventData.join(" "), true);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
this._process.handleError(error);
|
|
167
|
+
this._process.removeAddOn(addOnDirectory, options.addOnName);
|
|
168
|
+
await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_UNKNOWN_REASON, error.message, false);
|
|
169
|
+
|
|
170
|
+
return process.exit(0);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private _copyTemplateFiles(addOnDirectory: string, templateName: string) {
|
|
175
|
+
const targetPath = path.join(addOnDirectory, TEMP_TEMPLATE_PATH);
|
|
176
|
+
fs.ensureDirSync(targetPath);
|
|
177
|
+
|
|
178
|
+
const templateDirectory = path.join(url.fileURLToPath(import.meta.url), "..", "..", "templates", templateName);
|
|
179
|
+
|
|
180
|
+
if (fs.existsSync(templateDirectory)) {
|
|
181
|
+
fs.copySync(templateDirectory, targetPath);
|
|
182
|
+
} else {
|
|
183
|
+
this._logger.error(LOGS.templateNotFound);
|
|
184
|
+
process.exit(1);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
36
187
|
}
|
|
188
|
+
|
|
189
|
+
const LOGS = {
|
|
190
|
+
newLine: "\n",
|
|
191
|
+
creatingAddOn: "Creating a new Add-on ...",
|
|
192
|
+
mayTakeAMinute: "This may take a minute ...",
|
|
193
|
+
installingDevDependencies: "Installing dev dependencies ...",
|
|
194
|
+
scaffoldingProjectFromTemplate: "Scaffolding project from template: {templateName} ...",
|
|
195
|
+
templateNotFound: "Could not find the artifacts for the selected template."
|
|
196
|
+
};
|
|
@@ -28,7 +28,7 @@ import type { EntrypointType } from "@adobe/ccweb-add-on-manifest";
|
|
|
28
28
|
/**
|
|
29
29
|
* Class to manage the Add-on project requirements.
|
|
30
30
|
*/
|
|
31
|
-
export class
|
|
31
|
+
export class PackageManager {
|
|
32
32
|
/**
|
|
33
33
|
* Get package.json for the Add-on project.
|
|
34
34
|
* @param entrypointType - Entrypoint type of Add-on. For example: panel, command, etc.
|