@adobe/create-ccweb-add-on 2.5.0 → 3.1.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/.mocharc.json +9 -2
- package/README.md +2 -2
- package/bin/run.js +2 -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/{AddOnManager.d.ts → PackageManager.d.ts} +4 -4
- package/dist/app/PackageManager.d.ts.map +1 -0
- package/dist/app/{AddOnManager.js → PackageManager.js} +5 -6
- 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 +6 -10
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +11 -37
- package/dist/config/inversify.config.d.ts +2 -1
- package/dist/config/inversify.config.d.ts.map +1 -1
- package/dist/config/inversify.config.js +8 -6
- package/dist/config/inversify.types.d.ts.map +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/models/CLIOptions.d.ts +4 -4
- package/dist/models/CLIOptions.d.ts.map +1 -1
- package/dist/models/CLIOptions.js +5 -5
- package/dist/templates/react-javascript/template/src/components/App.jsx +2 -2
- package/dist/templates/react-javascript/template/webpack.config.js +1 -0
- package/dist/templates/react-javascript/template.json +4 -4
- package/dist/templates/react-javascript-with-document-sandbox/template/src/ui/components/App.jsx +2 -2
- package/dist/templates/react-javascript-with-document-sandbox/template/webpack.config.js +1 -0
- package/dist/templates/react-javascript-with-document-sandbox/template.json +4 -4
- package/dist/templates/react-typescript/template/src/components/App.tsx +2 -2
- package/dist/templates/react-typescript/template/webpack.config.js +1 -0
- package/dist/templates/react-typescript/template.json +4 -4
- package/dist/templates/react-typescript-with-document-sandbox/template/src/ui/components/App.tsx +2 -2
- package/dist/templates/react-typescript-with-document-sandbox/template/webpack.config.js +1 -0
- package/dist/templates/react-typescript-with-document-sandbox/template.json +4 -4
- package/dist/templates/swc-javascript/template/src/components/App.js +2 -2
- package/dist/templates/swc-javascript/template/webpack.config.js +1 -0
- package/dist/templates/swc-javascript/template.json +4 -4
- package/dist/templates/swc-javascript-with-document-sandbox/template/src/ui/components/App.js +2 -2
- package/dist/templates/swc-javascript-with-document-sandbox/template/webpack.config.js +1 -0
- package/dist/templates/swc-javascript-with-document-sandbox/template.json +4 -4
- package/dist/templates/swc-typescript/template/src/components/App.css.ts +2 -2
- package/dist/templates/swc-typescript/template/src/components/App.ts +4 -4
- package/dist/templates/swc-typescript/template/src/index.ts +2 -2
- package/dist/templates/swc-typescript/template/webpack.config.js +1 -0
- package/dist/templates/swc-typescript/template.json +4 -4
- package/dist/templates/swc-typescript-with-document-sandbox/template/src/ui/components/App.css.ts +2 -2
- package/dist/templates/swc-typescript-with-document-sandbox/template/src/ui/components/App.ts +4 -4
- package/dist/templates/swc-typescript-with-document-sandbox/template/src/ui/index.ts +2 -2
- package/dist/templates/swc-typescript-with-document-sandbox/template/webpack.config.js +1 -0
- package/dist/templates/swc-typescript-with-document-sandbox/template.json +4 -4
- 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 +26 -20
- package/src/app/AddOnFactory.ts +164 -4
- package/src/app/{AddOnManager.ts → PackageManager.ts} +4 -6
- package/src/app/TemplateSelector.ts +157 -5
- package/src/app/index.ts +1 -3
- package/src/commands/create.ts +24 -48
- package/src/config/inversify.config.ts +11 -9
- package/src/config/inversify.types.ts +7 -1
- package/src/constants.ts +2 -2
- package/src/index.ts +25 -0
- package/src/models/CLIOptions.ts +5 -5
- package/src/test/app/{WxpAddOnFactory.spec.ts → AddOnFactory.spec.ts} +18 -17
- package/src/test/app/{AddOnManager.spec.ts → PackageManager.spec.ts} +6 -6
- package/src/test/app/{AddOnTemplateSelector.spec.ts → TemplateSelector.spec.ts} +57 -26
- package/src/test/commands/command.spec.ts +80 -0
- package/src/test/commands/create.spec.ts +44 -18
- package/src/test/models/CLIOptions.spec.ts +4 -4
- package/src/test/validators/{AddOnDirectoryValidator.spec.ts → DirectoryValidator.spec.ts} +29 -21
- package/src/test/validators/{NodeEnvironmentValidator.spec.ts → EnvironmentValidator.spec.ts} +11 -24
- 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/src/components/App.jsx +2 -2
- package/templates/react-javascript/template/webpack.config.js +1 -0
- package/templates/react-javascript/template.json +4 -4
- package/templates/react-javascript-with-document-sandbox/template/src/ui/components/App.jsx +2 -2
- package/templates/react-javascript-with-document-sandbox/template/webpack.config.js +1 -0
- package/templates/react-javascript-with-document-sandbox/template.json +4 -4
- package/templates/react-typescript/template/src/components/App.tsx +2 -2
- package/templates/react-typescript/template/webpack.config.js +1 -0
- package/templates/react-typescript/template.json +4 -4
- package/templates/react-typescript-with-document-sandbox/template/src/ui/components/App.tsx +2 -2
- package/templates/react-typescript-with-document-sandbox/template/webpack.config.js +1 -0
- package/templates/react-typescript-with-document-sandbox/template.json +4 -4
- package/templates/swc-javascript/template/src/components/App.js +2 -2
- package/templates/swc-javascript/template/webpack.config.js +1 -0
- package/templates/swc-javascript/template.json +4 -4
- package/templates/swc-javascript-with-document-sandbox/template/src/ui/components/App.js +2 -2
- package/templates/swc-javascript-with-document-sandbox/template/webpack.config.js +1 -0
- package/templates/swc-javascript-with-document-sandbox/template.json +4 -4
- package/templates/swc-typescript/template/src/components/App.css.ts +2 -2
- package/templates/swc-typescript/template/src/components/App.ts +4 -4
- package/templates/swc-typescript/template/src/index.ts +2 -2
- package/templates/swc-typescript/template/webpack.config.js +1 -0
- package/templates/swc-typescript/template.json +4 -4
- package/templates/swc-typescript-with-document-sandbox/template/src/ui/components/App.css.ts +2 -2
- package/templates/swc-typescript-with-document-sandbox/template/src/ui/components/App.ts +4 -4
- package/templates/swc-typescript-with-document-sandbox/template/src/ui/index.ts +2 -2
- package/templates/swc-typescript-with-document-sandbox/template/webpack.config.js +1 -0
- package/templates/swc-typescript-with-document-sandbox/template.json +4 -4
- package/tsconfig.json +3 -1
- package/dist/app/AddOnManager.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
|
@@ -1,193 +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 { AnalyticsService } from "@adobe/ccweb-add-on-analytics";
|
|
26
|
-
import { ITypes as IAnalyticsTypes } from "@adobe/ccweb-add-on-analytics";
|
|
27
|
-
import type { Logger } from "@adobe/ccweb-add-on-core";
|
|
28
|
-
import { ITypes as ICoreTypes, isNullOrWhiteSpace } from "@adobe/ccweb-add-on-core";
|
|
29
|
-
import { EntrypointType } from "@adobe/ccweb-add-on-manifest";
|
|
30
|
-
import chalk from "chalk";
|
|
31
|
-
import { inject, injectable } from "inversify";
|
|
32
|
-
import prompts from "prompts";
|
|
33
|
-
import "reflect-metadata";
|
|
34
|
-
import format from "string-template";
|
|
35
|
-
import { AnalyticsErrorMarkers } from "../AnalyticsMarkers.js";
|
|
36
|
-
import { ADD_ON_TEMPLATES, AVAILABLE_ADD_ON_TEMPLATES, PROGRAM_NAME, WITH_DOCUMENT_SANDBOX } from "../constants.js";
|
|
37
|
-
import type { CLIOptions } from "../models/index.js";
|
|
38
|
-
import type { TemplateSelector } from "./TemplateSelector.js";
|
|
39
|
-
|
|
40
|
-
@injectable()
|
|
41
|
-
export class AddOnTemplateSelector implements TemplateSelector {
|
|
42
|
-
private readonly _logger: Logger;
|
|
43
|
-
private readonly _analyticsService: AnalyticsService;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Instantiate {@link AddOnTemplateSelector}.
|
|
47
|
-
* @param logger - {@link Logger} reference.
|
|
48
|
-
* @param analyticsService - {@link AnalyticsService} reference.
|
|
49
|
-
* @returns Reference to a new {@link AddOnTemplateSelector} instance.
|
|
50
|
-
*/
|
|
51
|
-
constructor(
|
|
52
|
-
@inject(ICoreTypes.Logger) logger: Logger,
|
|
53
|
-
@inject(IAnalyticsTypes.AnalyticsService) analyticsService: AnalyticsService
|
|
54
|
-
) {
|
|
55
|
-
this._logger = logger;
|
|
56
|
-
this._analyticsService = analyticsService;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Sets up a template, as selected/provided by the user
|
|
61
|
-
* for scaffolding the add-on project.
|
|
62
|
-
* @param options - {@link CLIOptions}.
|
|
63
|
-
* @returns User selected/provided template name.
|
|
64
|
-
*/
|
|
65
|
-
async setupTemplate(options: CLIOptions): Promise<string> {
|
|
66
|
-
await this._validateAddOnKind(options.addOnKind);
|
|
67
|
-
|
|
68
|
-
if (!isNullOrWhiteSpace(options.templateName)) {
|
|
69
|
-
if (AVAILABLE_ADD_ON_TEMPLATES.includes(options.templateName)) {
|
|
70
|
-
return options.templateName;
|
|
71
|
-
} else {
|
|
72
|
-
this._logger.warning(LOGS.chooseValidTemplate, { prefix: LOGS.newLine });
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Add a line break for better log readability.
|
|
77
|
-
console.log();
|
|
78
|
-
|
|
79
|
-
const templateChoices = [];
|
|
80
|
-
for (const [templateName, description] of ADD_ON_TEMPLATES.entries()) {
|
|
81
|
-
templateChoices.push({
|
|
82
|
-
title: this._promptMessageOption(templateName, description),
|
|
83
|
-
value: templateName
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const templateResponse = await prompts.prompt({
|
|
88
|
-
type: "select",
|
|
89
|
-
name: "selectedTemplate",
|
|
90
|
-
message: this._promptMessage(LOGS.setupTemplate),
|
|
91
|
-
choices: templateChoices,
|
|
92
|
-
initial: 0
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
if (!templateResponse || !templateResponse.selectedTemplate) {
|
|
96
|
-
console.log();
|
|
97
|
-
return process.exit(0);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/* c8 ignore next 4 */
|
|
101
|
-
/* All templates are currently available. */
|
|
102
|
-
if (!AVAILABLE_ADD_ON_TEMPLATES.includes(`${templateResponse.selectedTemplate}-${WITH_DOCUMENT_SANDBOX}`)) {
|
|
103
|
-
return templateResponse.selectedTemplate;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const documentSandboxChoices = [
|
|
107
|
-
{
|
|
108
|
-
title: this._promptMessageOption(LOGS.no),
|
|
109
|
-
value: false
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
title: this._promptMessageOption(LOGS.yes),
|
|
113
|
-
value: true
|
|
114
|
-
}
|
|
115
|
-
];
|
|
116
|
-
const documentSandboxResponse = await prompts.prompt({
|
|
117
|
-
type: "select",
|
|
118
|
-
name: "includeDocumentSandbox",
|
|
119
|
-
message: this._promptMessage(LOGS.includeDocumentSandbox),
|
|
120
|
-
choices: documentSandboxChoices,
|
|
121
|
-
initial: 0
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
if (!documentSandboxResponse || documentSandboxResponse.includeDocumentSandbox === undefined) {
|
|
125
|
-
console.log();
|
|
126
|
-
return process.exit(0);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Append `with-document-sandbox` to the template name if user wants to include document sandbox
|
|
130
|
-
return documentSandboxResponse.includeDocumentSandbox
|
|
131
|
-
? `${templateResponse.selectedTemplate}-${WITH_DOCUMENT_SANDBOX}`
|
|
132
|
-
: templateResponse.selectedTemplate;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
private _promptMessage(message: string): string {
|
|
136
|
-
return chalk.cyan(message);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
private _promptMessageOption(option: string, description?: string): string {
|
|
140
|
-
if (description) {
|
|
141
|
-
return `${chalk.hex("#E59400").bold(`[${option}]:`)} ${chalk.green(description)}`;
|
|
142
|
-
}
|
|
143
|
-
return chalk.green.bold(option);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Validate whether addOnKind is valid or not.
|
|
148
|
-
* @param addOnKind - Kind of Add-on. For example: panel.
|
|
149
|
-
*/
|
|
150
|
-
private async _validateAddOnKind(addOnKind: EntrypointType): Promise<void> {
|
|
151
|
-
if (addOnKind !== EntrypointType.PANEL) {
|
|
152
|
-
this._logger.warning(LOGS.chooseValidKind);
|
|
153
|
-
this._logger.warning(
|
|
154
|
-
format(LOGS.executeProgramWithValidKind, {
|
|
155
|
-
PROGRAM_NAME
|
|
156
|
-
}),
|
|
157
|
-
{
|
|
158
|
-
prefix: LOGS.tab
|
|
159
|
-
}
|
|
160
|
-
);
|
|
161
|
-
this._logger.message(LOGS.forExample, { prefix: LOGS.newLine });
|
|
162
|
-
this._logger.information(
|
|
163
|
-
format(LOGS.executeProgramWithValidKindExample, {
|
|
164
|
-
PROGRAM_NAME
|
|
165
|
-
}),
|
|
166
|
-
{
|
|
167
|
-
prefix: LOGS.tab
|
|
168
|
-
}
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
await this._analyticsService.postEvent(
|
|
172
|
-
AnalyticsErrorMarkers.ERROR_INVALID_KIND,
|
|
173
|
-
LOGS.analyticsInvalidKind,
|
|
174
|
-
false
|
|
175
|
-
);
|
|
176
|
-
return process.exit(0);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
const LOGS = {
|
|
181
|
-
newLine: "\n",
|
|
182
|
-
tab: " ",
|
|
183
|
-
setupTemplate: "Please select a template which you want to scaffold the Add-on project with",
|
|
184
|
-
chooseValidKind: "Please choose a valid Add-on kind (valid kind: panel)",
|
|
185
|
-
executeProgramWithValidKind: "{PROGRAM_NAME} <add-on-name> --kind <panel>",
|
|
186
|
-
executeProgramWithValidKindExample: "{PROGRAM_NAME} my-add-on --kind panel",
|
|
187
|
-
chooseValidTemplate: "You have chosen an invalid template.",
|
|
188
|
-
forExample: "For example:",
|
|
189
|
-
analyticsInvalidKind: "Invalid Add-on kind specified",
|
|
190
|
-
includeDocumentSandbox: "Do you want to include document sandbox runtime?",
|
|
191
|
-
yes: "Yes",
|
|
192
|
-
no: "No"
|
|
193
|
-
};
|
|
@@ -1,196 +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 { 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";
|
|
42
|
-
import type { CLIOptions } from "../models/CLIOptions.js";
|
|
43
|
-
import type { DirectoryValidator, EnvironmentValidator } from "../validators/index.js";
|
|
44
|
-
import type { AddOnFactory } from "./AddOnFactory.js";
|
|
45
|
-
import { AddOnManager } from "./AddOnManager.js";
|
|
46
|
-
import type { TemplateSelector } from "./TemplateSelector.js";
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* AddOn factory implementation class.
|
|
50
|
-
*/
|
|
51
|
-
@injectable()
|
|
52
|
-
export class WxpAddOnFactory implements 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
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Instantiate {@link WxpAddOnFactory}.
|
|
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 WxpAddOnFactory} 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.
|
|
98
|
-
* @param options - {@link CLIOptions}.
|
|
99
|
-
*/
|
|
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.creatingWxpAddOn);
|
|
113
|
-
this._logger.message(LOGS.mayTakeAMinute);
|
|
114
|
-
|
|
115
|
-
const templateName = await this._templateSelector.setupTemplate(options);
|
|
116
|
-
|
|
117
|
-
const packageJson = AddOnManager.getPackageJson(options.addOnKind, 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.addOnKind,
|
|
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
|
-
"--kind",
|
|
160
|
-
options.addOnKind,
|
|
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
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const LOGS = {
|
|
190
|
-
newLine: "\n",
|
|
191
|
-
creatingWxpAddOn: "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
|
-
};
|
|
@@ -1,207 +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 { AnalyticsService } from "@adobe/ccweb-add-on-analytics";
|
|
26
|
-
import { ITypes as IAnalyticsTypes } from "@adobe/ccweb-add-on-analytics";
|
|
27
|
-
import type { Logger } from "@adobe/ccweb-add-on-core";
|
|
28
|
-
import { ITypes as ICoreTypes, isNullOrWhiteSpace } from "@adobe/ccweb-add-on-core";
|
|
29
|
-
import fs from "fs-extra";
|
|
30
|
-
import { inject, injectable } from "inversify";
|
|
31
|
-
import path from "path";
|
|
32
|
-
import process from "process";
|
|
33
|
-
import "reflect-metadata";
|
|
34
|
-
import format from "string-template";
|
|
35
|
-
import validate from "validate-npm-package-name";
|
|
36
|
-
import { AnalyticsErrorMarkers } from "../AnalyticsMarkers.js";
|
|
37
|
-
import { PROGRAM_NAME } from "../constants.js";
|
|
38
|
-
|
|
39
|
-
import type { DirectoryValidator } from "./DirectoryValidator.js";
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Directory validator implementation class to validate
|
|
43
|
-
* whether the directory can be used to create the add-on project.
|
|
44
|
-
*/
|
|
45
|
-
@injectable()
|
|
46
|
-
export class AddOnDirectoryValidator implements DirectoryValidator {
|
|
47
|
-
private readonly _logger: Logger;
|
|
48
|
-
private readonly _analyticsService: AnalyticsService;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Instantiate {@link AddOnDirectoryValidator}.
|
|
52
|
-
* @param logger - {@link Logger} reference.
|
|
53
|
-
* @param analyticsService - {@link AnalyticsService} reference.
|
|
54
|
-
* @returns Reference to a new {@link AddOnDirectoryValidator} instance.
|
|
55
|
-
*/
|
|
56
|
-
constructor(
|
|
57
|
-
@inject(ICoreTypes.Logger) logger: Logger,
|
|
58
|
-
@inject(IAnalyticsTypes.AnalyticsService) analyticsService: AnalyticsService
|
|
59
|
-
) {
|
|
60
|
-
this._logger = logger;
|
|
61
|
-
this._analyticsService = analyticsService;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Validate the Add-on name.
|
|
66
|
-
* @param addOnName - Name of the Add-on.
|
|
67
|
-
*/
|
|
68
|
-
async validateAddOnName(addOnName: string): Promise<void> {
|
|
69
|
-
if (isNullOrWhiteSpace(addOnName)) {
|
|
70
|
-
this._logger.warning(LOGS.specifyAddOnName);
|
|
71
|
-
this._chooseDifferentAddOnName();
|
|
72
|
-
await this._analyticsService.postEvent(
|
|
73
|
-
AnalyticsErrorMarkers.ERROR_NO_ADD_ON_NAME,
|
|
74
|
-
LOGS.analyticsNoAddOnName,
|
|
75
|
-
false
|
|
76
|
-
);
|
|
77
|
-
return process.exit(0);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const isValid = validate(addOnName).validForNewPackages;
|
|
81
|
-
if (!isValid) {
|
|
82
|
-
this._logger.warning(format(LOGS.npmNamingRestriction, { addOnName }));
|
|
83
|
-
this._chooseDifferentAddOnName();
|
|
84
|
-
await this._analyticsService.postEvent(
|
|
85
|
-
AnalyticsErrorMarkers.ERROR_INVALID_NAME_NPM,
|
|
86
|
-
LOGS.analyticsInvalidAddOnNameNPM,
|
|
87
|
-
false
|
|
88
|
-
);
|
|
89
|
-
return process.exit(0);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const dependencies = new Set([
|
|
93
|
-
"@adobe/create-ccweb-add-on",
|
|
94
|
-
"create-ccweb-add-on",
|
|
95
|
-
"@adobe/ccweb-add-on-scripts",
|
|
96
|
-
"ccweb-add-on-scripts",
|
|
97
|
-
"@adobe/ccweb-add-on-scaffolder",
|
|
98
|
-
"ccweb-add-on-scaffolder"
|
|
99
|
-
]);
|
|
100
|
-
if (dependencies.has(addOnName)) {
|
|
101
|
-
this._logger.warning(format(LOGS.dependencyNamingRestriction, { addOnName }));
|
|
102
|
-
this._chooseDifferentAddOnName();
|
|
103
|
-
await this._analyticsService.postEvent(
|
|
104
|
-
AnalyticsErrorMarkers.ERROR_INVALID_NAME_DEP,
|
|
105
|
-
LOGS.analyticsInvalidAddOnNameDependency,
|
|
106
|
-
false
|
|
107
|
-
);
|
|
108
|
-
return process.exit(0);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Validate the addOn directory.
|
|
114
|
-
* @param addOnDirectory - Root directory of the addOn.
|
|
115
|
-
* @param addOnName - Name of the addOn.
|
|
116
|
-
*/
|
|
117
|
-
async validateAddOnDirectory(addOnDirectory: string, addOnName: string): Promise<void> {
|
|
118
|
-
fs.ensureDirSync(addOnName);
|
|
119
|
-
|
|
120
|
-
const validFiles = [
|
|
121
|
-
".DS_Store",
|
|
122
|
-
".git",
|
|
123
|
-
".gitattributes",
|
|
124
|
-
".gitignore",
|
|
125
|
-
".gitlab-ci.yml",
|
|
126
|
-
".hg",
|
|
127
|
-
".hgcheck",
|
|
128
|
-
".hgignore",
|
|
129
|
-
".idea",
|
|
130
|
-
".npmignore",
|
|
131
|
-
".travis.yml",
|
|
132
|
-
"docs",
|
|
133
|
-
"LICENSE",
|
|
134
|
-
"README.md",
|
|
135
|
-
"mkdocs.yml",
|
|
136
|
-
"Thumbs.db"
|
|
137
|
-
];
|
|
138
|
-
|
|
139
|
-
const errorLogFilePatterns = ["npm-debug.log"];
|
|
140
|
-
|
|
141
|
-
const isErrorLog = (file: string) => {
|
|
142
|
-
return errorLogFilePatterns.some(pattern => file.startsWith(pattern));
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const existingFiles = fs.readdirSync(addOnDirectory, { withFileTypes: true });
|
|
146
|
-
const conflictingFiles = existingFiles
|
|
147
|
-
.filter(file => !validFiles.includes(file.name))
|
|
148
|
-
.filter(file => !/\.iml$/.test(file.name))
|
|
149
|
-
.filter(file => !isErrorLog(file.name));
|
|
150
|
-
|
|
151
|
-
if (conflictingFiles.length === 0) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
this._logger.warning(format(LOGS.directoryContainsFiles, { addOnName }), {
|
|
156
|
-
postfix: LOGS.newLine
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
for (const file of conflictingFiles) {
|
|
160
|
-
try {
|
|
161
|
-
if (fs.lstatSync(path.join(addOnDirectory, file.name)).isDirectory()) {
|
|
162
|
-
this._logger.warning(`${file.name}/`, { prefix: LOGS.tab });
|
|
163
|
-
} else {
|
|
164
|
-
this._logger.warning(`${file.name}`, { prefix: LOGS.tab });
|
|
165
|
-
}
|
|
166
|
-
} catch {
|
|
167
|
-
this._logger.warning(`${file.name}`, { prefix: LOGS.tab });
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
this._logger.information(LOGS.newAddOnOrRemoveFiles, { prefix: LOGS.newLine });
|
|
172
|
-
await this._analyticsService.postEvent(
|
|
173
|
-
AnalyticsErrorMarkers.ERROR_INVALID_NAME_DIR,
|
|
174
|
-
LOGS.analyticsInvalidAddOnDir,
|
|
175
|
-
false
|
|
176
|
-
);
|
|
177
|
-
return process.exit(0);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
private _chooseDifferentAddOnName() {
|
|
181
|
-
this._logger.warning(format(LOGS.executeProgram, { PROGRAM_NAME }), { prefix: LOGS.tab });
|
|
182
|
-
this._logger.message(LOGS.forExample, { prefix: LOGS.newLine });
|
|
183
|
-
this._logger.information(format(LOGS.executeProgramExample, { PROGRAM_NAME }), {
|
|
184
|
-
prefix: LOGS.tab,
|
|
185
|
-
postfix: LOGS.newLine
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const LOGS = {
|
|
191
|
-
newLine: "\n",
|
|
192
|
-
tab: " ",
|
|
193
|
-
specifyAddOnName: "Please specify an Add-on name",
|
|
194
|
-
executeProgram: "{PROGRAM_NAME} <add-on-name> --kind <panel> --template <javascript>",
|
|
195
|
-
executeProgramExample: "{PROGRAM_NAME} my-add-on --kind panel --template javascript",
|
|
196
|
-
forExample: "For example:",
|
|
197
|
-
npmNamingRestriction: "Cannot create a project named {addOnName} because of NPM naming restrictions.",
|
|
198
|
-
dependencyNamingRestriction:
|
|
199
|
-
"Cannot create a project named {addOnName} because a dependency with the same name exists.",
|
|
200
|
-
chooseDifferentAddOnName: "Please choose a different Add-on name:",
|
|
201
|
-
directoryContainsFiles: "The directory {addOnName} contains files that could conflict:",
|
|
202
|
-
newAddOnOrRemoveFiles: "Either try using a new Add-on name, or remove the files listed above.",
|
|
203
|
-
analyticsNoAddOnName: "Add-on name was not specified",
|
|
204
|
-
analyticsInvalidAddOnNameNPM: "Invalid Add-on name. Npm name check failed",
|
|
205
|
-
analyticsInvalidAddOnNameDependency: "Invalid Add-on name. Dependency with same name exists",
|
|
206
|
-
analyticsInvalidAddOnDir: "Invalid Add-on name. Conflicting directory with same name exists"
|
|
207
|
-
};
|