@adobe/ccweb-add-on-scaffolder 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 +5 -1
- package/.mocharc.json +3 -1
- package/dist/app/AddOnBuilder.d.ts +27 -7
- package/dist/app/AddOnBuilder.d.ts.map +1 -1
- package/dist/app/AddOnBuilder.js +247 -0
- package/dist/app/AddOnScaffolder.d.ts +29 -2
- package/dist/app/AddOnScaffolder.d.ts.map +1 -1
- package/dist/app/AddOnScaffolder.js +106 -1
- package/dist/app/PackageBuilder.d.ts +21 -7
- package/dist/app/PackageBuilder.d.ts.map +1 -1
- package/dist/app/PackageBuilder.js +68 -1
- package/dist/app/index.d.ts +0 -3
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +0 -3
- package/dist/config/inversify.config.js +8 -6
- package/dist/config/inversify.types.d.ts +0 -1
- package/dist/config/inversify.types.d.ts.map +1 -1
- package/dist/config/inversify.types.js +0 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/validators/TemplateValidator.d.ts +12 -2
- package/dist/validators/TemplateValidator.d.ts.map +1 -1
- package/dist/validators/TemplateValidator.js +54 -1
- package/dist/validators/index.d.ts +0 -1
- package/dist/validators/index.d.ts.map +1 -1
- package/dist/validators/index.js +0 -1
- package/package.json +8 -8
- package/src/app/AddOnBuilder.ts +258 -15
- package/src/app/AddOnScaffolder.ts +120 -3
- package/src/app/PackageBuilder.ts +75 -9
- package/src/app/index.ts +0 -3
- package/src/config/inversify.config.ts +8 -8
- package/src/config/inversify.types.ts +0 -2
- package/src/index.ts +1 -1
- package/src/test/app/{TemplateAddOnBuilder.spec.ts → AddOnBuilder.spec.ts} +21 -22
- package/src/test/app/{TemplateAddOnScaffolder.spec.ts → AddOnScaffolder.spec.ts} +11 -13
- package/src/test/app/{TemplatePackageBuilder.spec.ts → PackageBuilder.spec.ts} +13 -14
- package/src/test/models/ScaffolderOptions.spec.ts +1 -1
- package/src/test/validators/{AppTemplateValidator.spec.ts → TemplateValidator.spec.ts} +2 -3
- package/src/validators/TemplateValidator.ts +46 -3
- package/src/validators/index.ts +0 -1
- package/dist/app/TemplateAddOnBuilder.d.ts +0 -90
- package/dist/app/TemplateAddOnBuilder.d.ts.map +0 -1
- package/dist/app/TemplateAddOnBuilder.js +0 -273
- package/dist/app/TemplateAddOnScaffolder.d.ts +0 -63
- package/dist/app/TemplateAddOnScaffolder.d.ts.map +0 -1
- package/dist/app/TemplateAddOnScaffolder.js +0 -130
- package/dist/app/TemplatePackageBuilder.d.ts +0 -49
- package/dist/app/TemplatePackageBuilder.d.ts.map +0 -1
- package/dist/app/TemplatePackageBuilder.js +0 -92
- package/dist/validators/AddOnTemplateValidator.d.ts +0 -46
- package/dist/validators/AddOnTemplateValidator.d.ts.map +0 -1
- package/dist/validators/AddOnTemplateValidator.js +0 -78
- package/src/app/TemplateAddOnBuilder.ts +0 -319
- package/src/app/TemplateAddOnScaffolder.ts +0 -153
- package/src/app/TemplatePackageBuilder.ts +0 -102
- package/src/validators/AddOnTemplateValidator.ts +0 -79
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* MIT License
|
|
3
|
-
|
|
4
|
-
* © Copyright 2023 Adobe. All rights reserved.
|
|
5
|
-
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
********************************************************************************/
|
|
24
|
-
import { __decorate, __metadata, __param } from "tslib";
|
|
25
|
-
import { ITypes as ICoreTypes, isNullOrWhiteSpace } from "@adobe/ccweb-add-on-core";
|
|
26
|
-
import { inject, injectable } from "inversify";
|
|
27
|
-
import process from "process";
|
|
28
|
-
import "reflect-metadata";
|
|
29
|
-
import format from "string-template";
|
|
30
|
-
import { PROGRAM_NAME } from "../constants.js";
|
|
31
|
-
/**
|
|
32
|
-
* Template validator implementation class to validate user selected template..
|
|
33
|
-
*/
|
|
34
|
-
let AddOnTemplateValidator = class AddOnTemplateValidator {
|
|
35
|
-
_logger;
|
|
36
|
-
/**
|
|
37
|
-
* Instantiate {@link AppTemplateValidator}.
|
|
38
|
-
*
|
|
39
|
-
* @param logger - {@link Logger} reference.
|
|
40
|
-
* @returns Reference to a new {@link AppTemplateValidator} instance.
|
|
41
|
-
*/
|
|
42
|
-
constructor(logger) {
|
|
43
|
-
this._logger = logger;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Validate the template.
|
|
47
|
-
*
|
|
48
|
-
* @param templateName - Name of the template.
|
|
49
|
-
*/
|
|
50
|
-
validateTemplate(templateName) {
|
|
51
|
-
if (isNullOrWhiteSpace(templateName)) {
|
|
52
|
-
this._logger.warning(LOGS.specifyValidTemplateName);
|
|
53
|
-
this._logger.warning(format(LOGS.executeProgram, { PROGRAM_NAME }), {
|
|
54
|
-
prefix: LOGS.tab
|
|
55
|
-
});
|
|
56
|
-
this._logger.message(LOGS.forExample, { prefix: LOGS.newLine });
|
|
57
|
-
this._logger.information(format(LOGS.executeProgramExample, { PROGRAM_NAME }), {
|
|
58
|
-
prefix: LOGS.tab
|
|
59
|
-
});
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
AddOnTemplateValidator = __decorate([
|
|
65
|
-
injectable(),
|
|
66
|
-
__param(0, inject(ICoreTypes.Logger)),
|
|
67
|
-
__metadata("design:paramtypes", [Object])
|
|
68
|
-
], AddOnTemplateValidator);
|
|
69
|
-
export { AddOnTemplateValidator };
|
|
70
|
-
const LOGS = {
|
|
71
|
-
newLine: "\n",
|
|
72
|
-
tab: " ",
|
|
73
|
-
specifyValidTemplateName: "Please specify a valid template name:",
|
|
74
|
-
executeProgram: "{PROGRAM_NAME} --template <template-name>",
|
|
75
|
-
executeProgramExample: "{PROGRAM_NAME} --template javascript",
|
|
76
|
-
forExample: "For example:"
|
|
77
|
-
};
|
|
78
|
-
//# sourceMappingURL=AddOnTemplateValidator.js.map
|
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* MIT License
|
|
3
|
-
|
|
4
|
-
* © Copyright 2023 Adobe. All rights reserved.
|
|
5
|
-
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
********************************************************************************/
|
|
24
|
-
|
|
25
|
-
import type { Logger } from "@adobe/ccweb-add-on-core";
|
|
26
|
-
import {
|
|
27
|
-
ADDITIONAL_ADD_ON_INFO,
|
|
28
|
-
DEFAULT_ADD_ON_VERSION,
|
|
29
|
-
ITypes as ICoreTypes,
|
|
30
|
-
PackageJson,
|
|
31
|
-
TemplateJson,
|
|
32
|
-
getJSONString,
|
|
33
|
-
isNullOrWhiteSpace
|
|
34
|
-
} from "@adobe/ccweb-add-on-core";
|
|
35
|
-
import type { CreateManifestResult, ManifestEntrypoint } from "@adobe/ccweb-add-on-manifest";
|
|
36
|
-
import { AddOnManifest, EntrypointType } from "@adobe/ccweb-add-on-manifest";
|
|
37
|
-
import fs from "fs-extra";
|
|
38
|
-
import { inject, injectable } from "inversify";
|
|
39
|
-
import { createRequire } from "module";
|
|
40
|
-
import os from "os";
|
|
41
|
-
import path from "path";
|
|
42
|
-
import "reflect-metadata";
|
|
43
|
-
import format from "string-template";
|
|
44
|
-
import { v4 as uuidv4 } from "uuid";
|
|
45
|
-
import { MANIFEST_JSON, PACKAGE_JSON, TEMPLATE_JSON, TEMP_TEMPLATE_PATH } from "../constants.js";
|
|
46
|
-
import type { ScaffolderOptions } from "../models/ScaffolderOptions.js";
|
|
47
|
-
import type { AddOnBuilder } from "./AddOnBuilder.js";
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* App builder implementation class for constructing the Add-on project.
|
|
51
|
-
*/
|
|
52
|
-
@injectable()
|
|
53
|
-
export class TemplateAddOnBuilder implements AddOnBuilder {
|
|
54
|
-
private readonly _logger: Logger;
|
|
55
|
-
|
|
56
|
-
private _options!: ScaffolderOptions;
|
|
57
|
-
private _require!: NodeRequire;
|
|
58
|
-
private _templateRootDirectory!: string;
|
|
59
|
-
|
|
60
|
-
private _gitignoreExists = false;
|
|
61
|
-
private _readmeExists = false;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Instantiate {@link TemplateAddOnBuilder}.
|
|
65
|
-
*
|
|
66
|
-
* @param options - {@link ScaffolderOptions}.
|
|
67
|
-
* @param logger - {@link Logger} reference.
|
|
68
|
-
* @returns Reference to a new {@link TemplateAddOnBuilder} instance.
|
|
69
|
-
*/
|
|
70
|
-
constructor(options: ScaffolderOptions, @inject(ICoreTypes.Logger) logger: Logger) {
|
|
71
|
-
this._options = options;
|
|
72
|
-
this._logger = logger;
|
|
73
|
-
|
|
74
|
-
this._require = createRequire(import.meta.url);
|
|
75
|
-
this._templateRootDirectory = path.join(process.cwd(), TEMP_TEMPLATE_PATH);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Get {@link PackageJson}.
|
|
80
|
-
*
|
|
81
|
-
* @returns Reference of {@link PackageJson}.
|
|
82
|
-
*/
|
|
83
|
-
getPackageJson(): PackageJson {
|
|
84
|
-
const packageJsonPath = path.join(this._options.addOnDirectory, PACKAGE_JSON);
|
|
85
|
-
return new PackageJson(this._require(packageJsonPath));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Get {@link TemplateJson}.
|
|
90
|
-
*
|
|
91
|
-
* @returns Reference of {@link TemplateJson}.
|
|
92
|
-
*/
|
|
93
|
-
getTemplateJson(): TemplateJson {
|
|
94
|
-
const templateJsonPath = path.join(this._templateRootDirectory, TEMPLATE_JSON);
|
|
95
|
-
return fs.existsSync(templateJsonPath)
|
|
96
|
-
? new TemplateJson(this._require(templateJsonPath))
|
|
97
|
-
: new TemplateJson({});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Get template devDependencies.
|
|
102
|
-
*
|
|
103
|
-
* @param template - {@link TemplateJson}
|
|
104
|
-
* @returns Set of template devDependencies.
|
|
105
|
-
*/
|
|
106
|
-
getDevDependenciesToInstall(template: TemplateJson): Set<string> {
|
|
107
|
-
const devDependencies = new Set<string>();
|
|
108
|
-
if (template.devDependencies) {
|
|
109
|
-
template.devDependencies.forEach((value, key) => {
|
|
110
|
-
devDependencies.add(`${key}@${value}`);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return devDependencies;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Get template dependencies.
|
|
119
|
-
*
|
|
120
|
-
* @param template - {@link TemplateJson}
|
|
121
|
-
* @returns Set of template dependencies.
|
|
122
|
-
*/
|
|
123
|
-
getDependenciesToInstall(template: TemplateJson): Set<string> {
|
|
124
|
-
const dependencies = new Set<string>();
|
|
125
|
-
if (template.dependencies) {
|
|
126
|
-
template.dependencies.forEach((value, key) => {
|
|
127
|
-
dependencies.add(`${key}@${value}`);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return dependencies;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Build the Add-on.
|
|
136
|
-
*
|
|
137
|
-
* @param packageJson - {@link PackageJson}
|
|
138
|
-
*/
|
|
139
|
-
build(packageJson: string): void {
|
|
140
|
-
fs.writeFileSync(path.join(this._options.addOnDirectory, PACKAGE_JSON), packageJson + os.EOL);
|
|
141
|
-
|
|
142
|
-
this._updateReadMe();
|
|
143
|
-
this._copyTemplateFiles();
|
|
144
|
-
this._updateGitIgnore();
|
|
145
|
-
this._updateManifest();
|
|
146
|
-
this._removeTemplateTempFiles();
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Display success message.
|
|
151
|
-
*/
|
|
152
|
-
displaySuccess(): void {
|
|
153
|
-
let cdPath;
|
|
154
|
-
if (
|
|
155
|
-
!isNullOrWhiteSpace(this._options.rootDirectory) &&
|
|
156
|
-
path.join(this._options.rootDirectory, this._options.addOnName) === this._options.addOnDirectory
|
|
157
|
-
) {
|
|
158
|
-
cdPath = this._options.addOnName;
|
|
159
|
-
} else {
|
|
160
|
-
cdPath = this._options.addOnDirectory;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
this._logger.success(
|
|
164
|
-
format(LOGS.successCreatedAddOn, {
|
|
165
|
-
addOnName: this._options.addOnName,
|
|
166
|
-
addOnDirectory: this._options.addOnDirectory
|
|
167
|
-
})
|
|
168
|
-
);
|
|
169
|
-
this._logger.success(LOGS.insideDirectoryCommandsToRun, { postfix: LOGS.newLine });
|
|
170
|
-
|
|
171
|
-
this._logger.information(LOGS.npmRunBuild, { prefix: `${LOGS.tab}` });
|
|
172
|
-
this._logger.message(LOGS.buildsTheAddOn, { prefix: `${LOGS.tab}${LOGS.tab}` });
|
|
173
|
-
this._logger.information(LOGS.npmRunStart, { prefix: LOGS.tab });
|
|
174
|
-
this._logger.message(LOGS.startsTheAddOn, { prefix: `${LOGS.tab}${LOGS.tab}` });
|
|
175
|
-
|
|
176
|
-
this._logger.message(LOGS.suggestBeginByTyping, {
|
|
177
|
-
prefix: LOGS.newLine,
|
|
178
|
-
postfix: LOGS.newLine
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
this._logger.warning(format(LOGS.changeDirectoryIntoCreatedApp, { cdPath }), {
|
|
182
|
-
prefix: LOGS.tab
|
|
183
|
-
});
|
|
184
|
-
this._logger.information(LOGS.npmRunBuild, { prefix: LOGS.tab });
|
|
185
|
-
this._logger.information(LOGS.npmRunStart, { prefix: LOGS.tab, postfix: LOGS.newLine });
|
|
186
|
-
|
|
187
|
-
if (this._readmeExists) {
|
|
188
|
-
this._logger.warning(LOGS.renamedReadme, { postfix: LOGS.newLine });
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (this._gitignoreExists) {
|
|
192
|
-
this._logger.warning(LOGS.mergedGitIgnore, { postfix: LOGS.newLine });
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
this._logger.warning(LOGS.whatWillYouCreateToday, { postfix: LOGS.newLine });
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
private _updateReadMe(): void {
|
|
199
|
-
this._readmeExists = fs.existsSync(path.join(this._options.addOnDirectory, "README.md"));
|
|
200
|
-
if (this._readmeExists) {
|
|
201
|
-
fs.renameSync(
|
|
202
|
-
path.join(this._options.addOnDirectory, "README.md"),
|
|
203
|
-
path.join(this._options.addOnDirectory, "README.OLD.md")
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
private _copyTemplateFiles(): void {
|
|
209
|
-
const templateContentDirectory = path.join(this._templateRootDirectory, "template");
|
|
210
|
-
if (fs.existsSync(templateContentDirectory)) {
|
|
211
|
-
fs.copySync(templateContentDirectory, this._options.addOnDirectory);
|
|
212
|
-
} else {
|
|
213
|
-
this._logger.warning(format(LOGS.couldNotLocateTemplate, { templateContentDirectory }));
|
|
214
|
-
process.exit(1);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
private _updateGitIgnore(): void {
|
|
219
|
-
this._gitignoreExists = fs.existsSync(path.join(this._options.addOnDirectory, ".gitignore"));
|
|
220
|
-
if (this._gitignoreExists) {
|
|
221
|
-
const data = fs.readFileSync(path.join(this._options.addOnDirectory, "gitignore"));
|
|
222
|
-
fs.appendFileSync(path.join(this._options.addOnDirectory, ".gitignore"), data);
|
|
223
|
-
fs.unlinkSync(path.join(this._options.addOnDirectory, "gitignore"));
|
|
224
|
-
} else {
|
|
225
|
-
fs.moveSync(
|
|
226
|
-
path.join(this._options.addOnDirectory, "gitignore"),
|
|
227
|
-
path.join(this._options.addOnDirectory, ".gitignore")
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
private _updateManifest(): void {
|
|
233
|
-
const manifestJsonPath = path.join(this._options.addOnDirectory, "src", MANIFEST_JSON);
|
|
234
|
-
const manifestExists = fs.existsSync(manifestJsonPath);
|
|
235
|
-
|
|
236
|
-
let createManifestResult: CreateManifestResult;
|
|
237
|
-
if (manifestExists) {
|
|
238
|
-
const manifestFile = this._require(manifestJsonPath);
|
|
239
|
-
const addOnName = this._getAddOnName(this._options.addOnName);
|
|
240
|
-
const manifestEntryPoints = (manifestFile.entryPoints as ManifestEntrypoint[]) ?? [];
|
|
241
|
-
createManifestResult = AddOnManifest.createManifest({
|
|
242
|
-
manifest: {
|
|
243
|
-
...manifestFile,
|
|
244
|
-
testId: uuidv4(),
|
|
245
|
-
name: addOnName,
|
|
246
|
-
version: DEFAULT_ADD_ON_VERSION,
|
|
247
|
-
entryPoints: manifestEntryPoints
|
|
248
|
-
},
|
|
249
|
-
additionalInfo: ADDITIONAL_ADD_ON_INFO
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
fs.unlinkSync(manifestJsonPath);
|
|
253
|
-
} else {
|
|
254
|
-
createManifestResult = AddOnManifest.createManifest({
|
|
255
|
-
manifest: {
|
|
256
|
-
testId: uuidv4(),
|
|
257
|
-
name: this._getAddOnName(this._options.addOnName),
|
|
258
|
-
version: DEFAULT_ADD_ON_VERSION,
|
|
259
|
-
manifestVersion: 2,
|
|
260
|
-
requirements: {
|
|
261
|
-
apps: [
|
|
262
|
-
{
|
|
263
|
-
name: "Express",
|
|
264
|
-
apiVersion: 1
|
|
265
|
-
}
|
|
266
|
-
]
|
|
267
|
-
},
|
|
268
|
-
entryPoints: [
|
|
269
|
-
{
|
|
270
|
-
type: EntrypointType.PANEL,
|
|
271
|
-
id: this._options.addOnName,
|
|
272
|
-
main: ""
|
|
273
|
-
}
|
|
274
|
-
]
|
|
275
|
-
},
|
|
276
|
-
additionalInfo: ADDITIONAL_ADD_ON_INFO
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if (createManifestResult.manifest === undefined) {
|
|
281
|
-
return this._logger.warning(
|
|
282
|
-
format(LOGS.invalidManifestInTemplate, {
|
|
283
|
-
templateName: this._options.templateName,
|
|
284
|
-
error: getJSONString(createManifestResult.manifestValidationResult)
|
|
285
|
-
})
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
fs.writeFileSync(manifestJsonPath, getJSONString(createManifestResult.manifest.manifestProperties) + os.EOL);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
private _getAddOnName(addOnName: string): string {
|
|
293
|
-
const camelCase = addOnName.replace(/[-_]\w/g, text => text.replace(/[-_]/, "").toUpperCase());
|
|
294
|
-
const wordCase = camelCase.replace(/([A-Z])/g, " $1");
|
|
295
|
-
return wordCase.charAt(0).toUpperCase() + wordCase.slice(1);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
private _removeTemplateTempFiles(): void {
|
|
299
|
-
fs.removeSync(this._templateRootDirectory);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const LOGS = {
|
|
304
|
-
newLine: "\n",
|
|
305
|
-
tab: " ",
|
|
306
|
-
couldNotLocateTemplate: "Could not locate template: {templateContentDirectory}",
|
|
307
|
-
invalidManifestInTemplate: "Invalid manifest in the template: {templateName}. Error: {error}",
|
|
308
|
-
successCreatedAddOn: "Success! Created {addOnName} at {addOnDirectory}.",
|
|
309
|
-
insideDirectoryCommandsToRun: "Inside this directory, you can run the following commands:",
|
|
310
|
-
npmRunBuild: "npm run build",
|
|
311
|
-
npmRunStart: "npm run start",
|
|
312
|
-
buildsTheAddOn: "Builds the Add-on.",
|
|
313
|
-
startsTheAddOn: "Starts the development server and hosts the Add-on.",
|
|
314
|
-
suggestBeginByTyping: "We suggest that you begin by typing:",
|
|
315
|
-
changeDirectoryIntoCreatedApp: "cd {cdPath}",
|
|
316
|
-
renamedReadme: "You had a 'README.md' file, we renamed it to 'README.OLD.md'",
|
|
317
|
-
mergedGitIgnore: "You had a '.gitignore' file, we merged it with the template '.gitignore'",
|
|
318
|
-
whatWillYouCreateToday: "So what will you create today?"
|
|
319
|
-
};
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* MIT License
|
|
3
|
-
|
|
4
|
-
* © Copyright 2023 Adobe. All rights reserved.
|
|
5
|
-
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
********************************************************************************/
|
|
24
|
-
|
|
25
|
-
import type { Logger, Process } from "@adobe/ccweb-add-on-core";
|
|
26
|
-
import { DEFAULT_HOST_NAME, ITypes as ICoreTypes } from "@adobe/ccweb-add-on-core";
|
|
27
|
-
import type { CommandExecutor as SSLCommandExecutor } from "@adobe/ccweb-add-on-ssl";
|
|
28
|
-
import { ITypes as ISSLTypes, SetupCommandOptions } from "@adobe/ccweb-add-on-ssl";
|
|
29
|
-
import { inject, injectable, named } from "inversify";
|
|
30
|
-
import "reflect-metadata";
|
|
31
|
-
import { ITypes } from "../config/inversify.types.js";
|
|
32
|
-
import type { ScaffolderOptions } from "../models/ScaffolderOptions.js";
|
|
33
|
-
import type { TemplateValidator } from "../validators/index.js";
|
|
34
|
-
import type { AddOnBuilderFactory } from "./AddOnBuilder.js";
|
|
35
|
-
import type { AddOnScaffolder } from "./AddOnScaffolder.js";
|
|
36
|
-
import type { PackageBuilderFactory } from "./PackageBuilder.js";
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Add-on scaffolder implementation class for orchestrating the creation of the Add-on project.
|
|
40
|
-
*/
|
|
41
|
-
@injectable()
|
|
42
|
-
export class TemplateAddOnScaffolder implements AddOnScaffolder {
|
|
43
|
-
private readonly _addOnBuilderFactory: AddOnBuilderFactory;
|
|
44
|
-
private readonly _packageBuilderFactory: PackageBuilderFactory;
|
|
45
|
-
private readonly _templateValidator: TemplateValidator;
|
|
46
|
-
|
|
47
|
-
private readonly _sslCommandExecutor: SSLCommandExecutor;
|
|
48
|
-
|
|
49
|
-
private readonly _process: Process;
|
|
50
|
-
private readonly _logger: Logger;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Instantiate {@link TemplateAppScaffolder}.
|
|
54
|
-
* @param addOnBuilderFactory - {@link AddOnBuilderFactory} reference.
|
|
55
|
-
* @param packageBuilderFactory - {@link PackageBuilderFactory} reference.
|
|
56
|
-
* @param templateValidator - {@link TemplateValidator} reference.
|
|
57
|
-
* @param sslCommandExecutor - {@link SSLCommandExecutor} reference.
|
|
58
|
-
* @param cliProcess - {@link Process} reference.
|
|
59
|
-
* @param logger - {@link Logger} reference.
|
|
60
|
-
* @returns Reference to a new {@link TemplateAppScaffolder} instance.
|
|
61
|
-
*/
|
|
62
|
-
constructor(
|
|
63
|
-
@inject(ITypes.AddOnBuilder) addOnBuilderFactory: AddOnBuilderFactory,
|
|
64
|
-
@inject(ITypes.PackageBuilder) packageBuilderFactory: PackageBuilderFactory,
|
|
65
|
-
@inject(ITypes.TemplateValidator) templateValidator: TemplateValidator,
|
|
66
|
-
@inject(ISSLTypes.CommandExecutor) @named("setup") sslCommandExecutor: SSLCommandExecutor,
|
|
67
|
-
@inject(ICoreTypes.Process) cliProcess: Process,
|
|
68
|
-
@inject(ICoreTypes.Logger) logger: Logger
|
|
69
|
-
) {
|
|
70
|
-
this._addOnBuilderFactory = addOnBuilderFactory;
|
|
71
|
-
this._packageBuilderFactory = packageBuilderFactory;
|
|
72
|
-
this._templateValidator = templateValidator;
|
|
73
|
-
|
|
74
|
-
this._sslCommandExecutor = sslCommandExecutor;
|
|
75
|
-
|
|
76
|
-
this._process = cliProcess;
|
|
77
|
-
this._logger = logger;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Run the scaffolder to create the Add-on project from the provided options.
|
|
82
|
-
* @param options - {@link ScaffolderOptions} reference.
|
|
83
|
-
* @returns Promise.
|
|
84
|
-
*/
|
|
85
|
-
async run(options: ScaffolderOptions): Promise<void> {
|
|
86
|
-
try {
|
|
87
|
-
this._templateValidator.validateTemplate(options.templateName);
|
|
88
|
-
|
|
89
|
-
const addOnBuilder = this._addOnBuilderFactory(options);
|
|
90
|
-
const packageJson = addOnBuilder.getPackageJson();
|
|
91
|
-
const templateJson = addOnBuilder.getTemplateJson();
|
|
92
|
-
|
|
93
|
-
const packageBuilder = this._packageBuilderFactory(packageJson)(templateJson);
|
|
94
|
-
const combinedPackage = packageBuilder.build();
|
|
95
|
-
|
|
96
|
-
addOnBuilder.build(combinedPackage.toJSON());
|
|
97
|
-
|
|
98
|
-
const templateDevDependencies = addOnBuilder.getDevDependenciesToInstall(templateJson);
|
|
99
|
-
await this._installDevDependencies(templateDevDependencies, options.verbose);
|
|
100
|
-
|
|
101
|
-
const templateDependencies = addOnBuilder.getDependenciesToInstall(templateJson);
|
|
102
|
-
await this._installDependencies(templateDependencies, options.verbose);
|
|
103
|
-
|
|
104
|
-
await this._setupSSL(options.verbose);
|
|
105
|
-
|
|
106
|
-
addOnBuilder.displaySuccess();
|
|
107
|
-
} catch (error) {
|
|
108
|
-
this._process.handleError(error);
|
|
109
|
-
process.exit(1);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private async _installDevDependencies(templateDevDependencies: Set<string>, verbose: boolean) {
|
|
114
|
-
if (templateDevDependencies.size > 0) {
|
|
115
|
-
const devDependencyArgs = ["install", "--save-dev", "--save-exact", ...templateDevDependencies];
|
|
116
|
-
if (verbose) {
|
|
117
|
-
devDependencyArgs.push("--verbose");
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
this._logger.information(LOGS.installingTemplateDevDependencies, {
|
|
121
|
-
prefix: LOGS.newLine
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
await this._process.execute("npm", devDependencyArgs, { stdio: "inherit" });
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
private async _installDependencies(templateDependencies: Set<string>, verbose: boolean) {
|
|
129
|
-
if (templateDependencies.size > 0) {
|
|
130
|
-
const dependencyArgs = ["install", "--save", "--save-exact", ...templateDependencies];
|
|
131
|
-
if (verbose) {
|
|
132
|
-
dependencyArgs.push("--verbose");
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
this._logger.information(LOGS.installingTemplateDependencies, {
|
|
136
|
-
prefix: LOGS.newLine
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
await this._process.execute("npm", dependencyArgs, { stdio: "inherit" });
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
private async _setupSSL(verbose: boolean): Promise<void> {
|
|
144
|
-
const setupCommandOptions = new SetupCommandOptions(DEFAULT_HOST_NAME, true, verbose);
|
|
145
|
-
await this._sslCommandExecutor.execute(setupCommandOptions);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const LOGS = {
|
|
150
|
-
newLine: "\n",
|
|
151
|
-
installingTemplateDevDependencies: "Installing template dev dependencies ...",
|
|
152
|
-
installingTemplateDependencies: "Installing template dependencies ..."
|
|
153
|
-
};
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* MIT License
|
|
3
|
-
|
|
4
|
-
* © Copyright 2023 Adobe. All rights reserved.
|
|
5
|
-
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
********************************************************************************/
|
|
24
|
-
|
|
25
|
-
import type { TemplateJson } from "@adobe/ccweb-add-on-core";
|
|
26
|
-
import { PackageJson } from "@adobe/ccweb-add-on-core";
|
|
27
|
-
import { injectable } from "inversify";
|
|
28
|
-
import type { PackageBuilder } from "./PackageBuilder.js";
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Package builder implementation class for constructing the package.json of the Add-on project.
|
|
32
|
-
*/
|
|
33
|
-
@injectable()
|
|
34
|
-
export class TemplatePackageBuilder implements PackageBuilder {
|
|
35
|
-
private _combinedPackage: PackageJson;
|
|
36
|
-
private _templateJson: TemplateJson;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Instantiate {@link TemplatePackageBuilder}.
|
|
40
|
-
*
|
|
41
|
-
* @param packageJson - {@link PackageJson}.
|
|
42
|
-
* @param templateJson - {@link TemplateJson}.
|
|
43
|
-
* @returns Reference to a new {@link TemplatePackageBuilder} instance.
|
|
44
|
-
*/
|
|
45
|
-
constructor(packageJson: PackageJson, templateJson: TemplateJson) {
|
|
46
|
-
this._combinedPackage = new PackageJson({ ...packageJson });
|
|
47
|
-
this._templateJson = templateJson;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Build {@link PackageJson}.
|
|
52
|
-
*/
|
|
53
|
-
build(): PackageJson {
|
|
54
|
-
this._buildDevDependencies();
|
|
55
|
-
this._buildDependencies();
|
|
56
|
-
this._buildScripts();
|
|
57
|
-
|
|
58
|
-
return this._combinedPackage;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private _buildDevDependencies(): void {
|
|
62
|
-
if (!this._templateJson.devDependencies || this._templateJson.devDependencies.size === 0) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
this._templateJson.devDependencies.forEach((value, key) => {
|
|
67
|
-
if (!this._combinedPackage.devDependencies) {
|
|
68
|
-
this._combinedPackage.devDependencies = new Map<string, string>();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
this._combinedPackage.devDependencies.set(key, value);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private _buildDependencies(): void {
|
|
76
|
-
if (!this._templateJson.dependencies || this._templateJson.dependencies.size === 0) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
this._templateJson.dependencies.forEach((value, key) => {
|
|
81
|
-
if (!this._combinedPackage.dependencies) {
|
|
82
|
-
this._combinedPackage.dependencies = new Map<string, string>();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
this._combinedPackage.dependencies.set(key, value);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
private _buildScripts(): void {
|
|
90
|
-
if (!this._templateJson.scripts || this._templateJson.scripts.size === 0) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
this._templateJson.scripts.forEach((value, key) => {
|
|
95
|
-
if (!this._combinedPackage.scripts) {
|
|
96
|
-
this._combinedPackage.scripts = new Map<string, string>();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
this._combinedPackage.scripts.set(key, value);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|