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