create-webiny-project 5.40.0-beta.2 → 5.40.0-beta.3
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/bin.js +2 -3
- package/index.js +8 -2
- package/package.json +5 -5
- package/utils/GracefulError.d.ts +1 -0
- package/utils/GracefulError.js +3 -0
- package/utils/GracefulYarnError.d.ts +3 -0
- package/utils/GracefulYarnError.js +31 -0
- package/utils/createProject.js +60 -39
- package/utils/gracefulYarnErrorHandlers/index.js +1 -0
- /package/utils/{checkProjectName.js → validateProjectName.js} +0 -0
package/bin.js
CHANGED
|
@@ -8,18 +8,17 @@ const getNpmVersion = require("./utils/getNpmVersion");
|
|
|
8
8
|
const verifyConfig = require("./utils/verifyConfig");
|
|
9
9
|
|
|
10
10
|
(async () => {
|
|
11
|
-
const minNodeVersion = "16";
|
|
12
11
|
const minNpmVersion = "10";
|
|
13
12
|
const minYarnVersion = "1.22.21";
|
|
14
13
|
/**
|
|
15
14
|
* Node
|
|
16
15
|
*/
|
|
17
16
|
const nodeVersion = process.versions.node;
|
|
18
|
-
if (!semver.satisfies(nodeVersion,
|
|
17
|
+
if (!semver.satisfies(nodeVersion, `^18 || ^20`)) {
|
|
19
18
|
console.error(
|
|
20
19
|
chalk.red(
|
|
21
20
|
[
|
|
22
|
-
`You are running Node.js ${nodeVersion}, but Webiny requires version
|
|
21
|
+
`You are running Node.js ${nodeVersion}, but Webiny requires version 18 or 20.`,
|
|
23
22
|
`Please switch to one of the required versions and try again.`,
|
|
24
23
|
"For more information, please visit https://docs.webiny.com/docs/tutorials/install-webiny#prerequisites."
|
|
25
24
|
].join(" ")
|
package/index.js
CHANGED
|
@@ -71,12 +71,18 @@ yargs.command(
|
|
|
71
71
|
});
|
|
72
72
|
yargs.option("log", {
|
|
73
73
|
describe:
|
|
74
|
-
"Creates a log file to see output of installation. Defaults to
|
|
74
|
+
"Creates a log file to see output of installation. Defaults to create-webiny-project-logs.txt in current directory",
|
|
75
75
|
alias: "l",
|
|
76
|
-
default: "
|
|
76
|
+
default: "create-webiny-project-logs.txt",
|
|
77
77
|
type: "string",
|
|
78
78
|
demandOption: false
|
|
79
79
|
});
|
|
80
|
+
yargs.option("debug", {
|
|
81
|
+
describe: "Turn on debug logs",
|
|
82
|
+
default: false,
|
|
83
|
+
type: "boolean",
|
|
84
|
+
demandOption: false
|
|
85
|
+
});
|
|
80
86
|
yargs.option("cleanup", {
|
|
81
87
|
describe: "If an error occurs upon project creation, deletes all generated files",
|
|
82
88
|
alias: "c",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-webiny-project",
|
|
3
|
-
"version": "5.40.0-beta.
|
|
3
|
+
"version": "5.40.0-beta.3",
|
|
4
4
|
"description": "Webiny project bootstrap tool.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"author": "Webiny Ltd.",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@webiny/telemetry": "5.40.0-beta.
|
|
16
|
+
"@webiny/telemetry": "5.40.0-beta.3",
|
|
17
17
|
"chalk": "4.1.2",
|
|
18
18
|
"execa": "5.1.1",
|
|
19
19
|
"find-up": "5.0.0",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"js-yaml": "3.14.1",
|
|
22
22
|
"listr": "0.14.3",
|
|
23
23
|
"load-json-file": "6.2.0",
|
|
24
|
-
"node-fetch": "2.
|
|
24
|
+
"node-fetch": "2.7.0",
|
|
25
25
|
"os": "0.1.1",
|
|
26
26
|
"p-retry": "4.6.2",
|
|
27
|
-
"rimraf": "
|
|
27
|
+
"rimraf": "5.0.5",
|
|
28
28
|
"semver": "7.5.4",
|
|
29
29
|
"uuid": "8.3.2",
|
|
30
30
|
"validate-npm-package-name": "3.0.0",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"access": "public",
|
|
36
36
|
"directory": "."
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "638d8b84063906cd1aa979ed6e0487ad26fbcf2f"
|
|
39
39
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class GracefulError extends Error {}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const { GracefulError } = require("./GracefulError");
|
|
2
|
+
const gracefulYarnErrorHandlers = require("./gracefulYarnErrorHandlers");
|
|
3
|
+
|
|
4
|
+
class GracefulYarnError extends GracefulError {
|
|
5
|
+
static from(e, context) {
|
|
6
|
+
if (e instanceof GracefulError) {
|
|
7
|
+
return e;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
for (const handler of gracefulYarnErrorHandlers) {
|
|
11
|
+
const result = handler({ error: e, context });
|
|
12
|
+
if (!result) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let errorMessage = result;
|
|
17
|
+
if (typeof result === "object") {
|
|
18
|
+
const { message, learnMore } = result;
|
|
19
|
+
|
|
20
|
+
errorMessage = message;
|
|
21
|
+
if (learnMore) {
|
|
22
|
+
errorMessage += ` Learn more: ${learnMore}.`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return new GracefulYarnError(errorMessage, { cause: e });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = { GracefulYarnError };
|
package/utils/createProject.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const { yellow, red, green, gray } = require("chalk");
|
|
2
|
+
const { yellow, red, green, gray, bold } = require("chalk");
|
|
3
3
|
const execa = require("execa");
|
|
4
4
|
const fs = require("fs-extra");
|
|
5
5
|
const Listr = require("listr");
|
|
@@ -8,11 +8,20 @@ const writeJson = require("write-json-file");
|
|
|
8
8
|
const rimraf = require("rimraf");
|
|
9
9
|
const { sendEvent } = require("@webiny/telemetry/cli");
|
|
10
10
|
const getPackageJson = require("./getPackageJson");
|
|
11
|
-
const
|
|
11
|
+
const validateProjectName = require("./validateProjectName");
|
|
12
12
|
const yaml = require("js-yaml");
|
|
13
13
|
const findUp = require("find-up");
|
|
14
|
+
const { GracefulError } = require("./GracefulError");
|
|
14
15
|
|
|
15
16
|
const NOT_APPLICABLE = gray("N/A");
|
|
17
|
+
const HL = bold(gray("—")).repeat(30);
|
|
18
|
+
|
|
19
|
+
const sleep = () =>
|
|
20
|
+
new Promise(resolve => {
|
|
21
|
+
setTimeout(() => {
|
|
22
|
+
resolve();
|
|
23
|
+
}, 500);
|
|
24
|
+
});
|
|
16
25
|
|
|
17
26
|
module.exports = async function createProject({
|
|
18
27
|
projectName,
|
|
@@ -20,6 +29,7 @@ module.exports = async function createProject({
|
|
|
20
29
|
template,
|
|
21
30
|
tag,
|
|
22
31
|
log,
|
|
32
|
+
debug,
|
|
23
33
|
cleanup,
|
|
24
34
|
interactive,
|
|
25
35
|
templateOptions,
|
|
@@ -91,6 +101,8 @@ module.exports = async function createProject({
|
|
|
91
101
|
// @webiny/cli is not installed globally
|
|
92
102
|
}
|
|
93
103
|
|
|
104
|
+
validateProjectName(projectName);
|
|
105
|
+
|
|
94
106
|
console.log(`Initializing a new Webiny project in ${green(projectRoot)}...`);
|
|
95
107
|
|
|
96
108
|
await sendEvent({ event: "create-webiny-project-start" });
|
|
@@ -109,7 +121,6 @@ module.exports = async function createProject({
|
|
|
109
121
|
// Creates root package.json.
|
|
110
122
|
title: "Prepare project folder",
|
|
111
123
|
task: () => {
|
|
112
|
-
checkProjectName(projectName);
|
|
113
124
|
fs.ensureDirSync(projectName);
|
|
114
125
|
writeJson.sync(
|
|
115
126
|
path.join(projectRoot, "package.json"),
|
|
@@ -119,7 +130,7 @@ module.exports = async function createProject({
|
|
|
119
130
|
},
|
|
120
131
|
{
|
|
121
132
|
// Setup yarn
|
|
122
|
-
title: "Setup
|
|
133
|
+
title: "Setup Yarn",
|
|
123
134
|
task: async () => {
|
|
124
135
|
const yarnVersion = "3.6.4";
|
|
125
136
|
const yarnFile = `yarn-${yarnVersion}.cjs`;
|
|
@@ -137,18 +148,22 @@ module.exports = async function createProject({
|
|
|
137
148
|
if (!fs.existsSync(source)) {
|
|
138
149
|
throw new Error(`No yarn binary source file: ${source}`);
|
|
139
150
|
}
|
|
151
|
+
|
|
140
152
|
const target = path.join(projectRoot, yarnReleasesFilePath);
|
|
141
153
|
fs.copyFileSync(source, target);
|
|
142
154
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
155
|
+
// `.yarnrc.yml` file is created here.
|
|
156
|
+
const yarnRcPath = path.join(projectRoot, ".yarnrc.yml");
|
|
157
|
+
|
|
158
|
+
let rawYarnRc = `yarnPath: ${yarnReleasesFilePath}`;
|
|
159
|
+
if (fs.existsSync(yarnRcPath)) {
|
|
160
|
+
rawYarnRc = fs.readFileSync(yarnRcPath, "utf-8");
|
|
146
161
|
}
|
|
147
162
|
|
|
148
|
-
const
|
|
163
|
+
const parsedYarnRc = yaml.load(rawYarnRc);
|
|
149
164
|
|
|
150
|
-
// Default settings are applied here. Currently we only apply the `nodeLinker` param.
|
|
151
|
-
|
|
165
|
+
// Default settings are applied here. Currently, we only apply the `nodeLinker` param.
|
|
166
|
+
parsedYarnRc.nodeLinker = "node-modules";
|
|
152
167
|
|
|
153
168
|
// Enables adding additional params into the `.yarnrc.yml` file.
|
|
154
169
|
if (assignToYarnRc) {
|
|
@@ -162,15 +177,15 @@ module.exports = async function createProject({
|
|
|
162
177
|
}
|
|
163
178
|
|
|
164
179
|
if (parsedAssignToYarnRc) {
|
|
165
|
-
Object.assign(
|
|
180
|
+
Object.assign(parsedYarnRc, parsedAssignToYarnRc);
|
|
166
181
|
}
|
|
167
182
|
}
|
|
168
183
|
|
|
169
|
-
fs.writeFileSync(
|
|
184
|
+
fs.writeFileSync(yarnRcPath, yaml.dump(parsedYarnRc));
|
|
170
185
|
}
|
|
171
186
|
},
|
|
172
187
|
{
|
|
173
|
-
//
|
|
188
|
+
// Yarn adds given template which can be either a real package or a path of a local package.
|
|
174
189
|
title: `Install template package`,
|
|
175
190
|
task: async context => {
|
|
176
191
|
let add;
|
|
@@ -179,6 +194,7 @@ module.exports = async function createProject({
|
|
|
179
194
|
if (template.startsWith(".") || template.startsWith("file:")) {
|
|
180
195
|
templateName =
|
|
181
196
|
"file:" + path.relative(projectName, template.replace("file:", ""));
|
|
197
|
+
templateName = `@webiny/cwp-template-aws@` + templateName;
|
|
182
198
|
add = templateName;
|
|
183
199
|
} else {
|
|
184
200
|
add = `${templateName}@${tag}`;
|
|
@@ -218,10 +234,9 @@ module.exports = async function createProject({
|
|
|
218
234
|
await tasks.run(context);
|
|
219
235
|
|
|
220
236
|
let templateName = context.templateName;
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
templateName = templateName.replace("file:", "");
|
|
237
|
+
if (templateName.includes("file:")) {
|
|
238
|
+
const [, templatePath] = templateName.match(/.*?file\:(.*)/);
|
|
239
|
+
templateName = templatePath;
|
|
225
240
|
}
|
|
226
241
|
|
|
227
242
|
const templatePath = path.dirname(
|
|
@@ -230,11 +245,7 @@ module.exports = async function createProject({
|
|
|
230
245
|
})
|
|
231
246
|
);
|
|
232
247
|
|
|
233
|
-
await
|
|
234
|
-
setTimeout(() => {
|
|
235
|
-
resolve();
|
|
236
|
-
}, 500);
|
|
237
|
-
});
|
|
248
|
+
await sleep();
|
|
238
249
|
|
|
239
250
|
let parsedTemplateOptions = {};
|
|
240
251
|
if (templateOptions) {
|
|
@@ -246,25 +257,36 @@ module.exports = async function createProject({
|
|
|
246
257
|
}
|
|
247
258
|
|
|
248
259
|
console.log();
|
|
260
|
+
|
|
249
261
|
await require(templatePath)({
|
|
250
262
|
log,
|
|
251
263
|
isGitAvailable,
|
|
252
264
|
projectName,
|
|
253
265
|
projectRoot,
|
|
254
266
|
interactive,
|
|
267
|
+
debug,
|
|
255
268
|
templateOptions: parsedTemplateOptions
|
|
256
269
|
});
|
|
257
270
|
|
|
258
271
|
await sendEvent({ event: "create-webiny-project-end" });
|
|
259
272
|
} catch (err) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
273
|
+
if (err instanceof GracefulError) {
|
|
274
|
+
await sendEvent({
|
|
275
|
+
event: "create-webiny-project-error-graceful",
|
|
276
|
+
properties: {
|
|
277
|
+
errorMessage: err.message,
|
|
278
|
+
errorStack: err.stack
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
} else {
|
|
282
|
+
await sendEvent({
|
|
283
|
+
event: "create-webiny-project-error",
|
|
284
|
+
properties: {
|
|
285
|
+
errorMessage: err.message,
|
|
286
|
+
errorStack: err.stack
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
268
290
|
const node = process.versions.node;
|
|
269
291
|
const os = process.platform;
|
|
270
292
|
|
|
@@ -311,18 +333,18 @@ module.exports = async function createProject({
|
|
|
311
333
|
console.log(
|
|
312
334
|
[
|
|
313
335
|
"",
|
|
314
|
-
`${
|
|
315
|
-
|
|
336
|
+
`${bold("Error Logs")}`,
|
|
337
|
+
HL,
|
|
316
338
|
err.message,
|
|
317
339
|
"",
|
|
318
|
-
`${
|
|
319
|
-
|
|
340
|
+
`${bold("System Information")}`,
|
|
341
|
+
HL,
|
|
342
|
+
`create-webiny-project: ${cwp}`,
|
|
320
343
|
`Operating System: ${os}`,
|
|
321
344
|
`Node: ${node}`,
|
|
322
345
|
`Yarn: ${yarn}`,
|
|
323
346
|
`Npm: ${npm}`,
|
|
324
347
|
`Npx: ${npx}`,
|
|
325
|
-
`create-webiny-project: ${cwp}`,
|
|
326
348
|
`Template: ${cwpTemplate}`,
|
|
327
349
|
`Template Options: ${templateOptionsJson}`,
|
|
328
350
|
"",
|
|
@@ -332,18 +354,17 @@ module.exports = async function createProject({
|
|
|
332
354
|
].join("\n")
|
|
333
355
|
);
|
|
334
356
|
|
|
335
|
-
console.log(`Writing
|
|
357
|
+
console.log(`Writing logs to ${green(path.resolve(log))}...`);
|
|
336
358
|
fs.writeFileSync(path.resolve(log), err.toString());
|
|
337
359
|
|
|
360
|
+
console.log();
|
|
338
361
|
if (cleanup) {
|
|
339
|
-
console.log("
|
|
362
|
+
console.log("Deleting created files and folders...");
|
|
340
363
|
rimraf.sync(projectRoot);
|
|
341
|
-
console.log("Done.");
|
|
342
364
|
} else {
|
|
343
365
|
console.log("Project cleanup skipped.");
|
|
344
366
|
}
|
|
345
367
|
|
|
346
|
-
await sendEvent({ event: "create-webiny-project-end" });
|
|
347
368
|
process.exit(1);
|
|
348
369
|
}
|
|
349
370
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = [];
|
|
File without changes
|