create-lwr 0.22.2 → 0.22.7
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/build/es/index.js +33 -9
- package/build/es/utils.d.ts +1 -0
- package/build/es/utils.js +1 -1
- package/package.json +3 -5
package/build/es/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import minimist from 'minimist';
|
|
5
|
-
import { emptyDir, copy, pkgFromUserAgent, promptForAnswers, updateLwrVersion } from './utils.js';
|
|
5
|
+
import { emptyDir, copy, pkgFromUserAgent, promptForAnswers, toValidPackageName, updateLwrVersion, } from './utils.js';
|
|
6
6
|
import { dirname } from 'path';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
import { dim } from 'kolorist';
|
|
@@ -11,7 +11,7 @@ const cwd = process.cwd();
|
|
|
11
11
|
const rooDir = path.join(__dirname, '../../');
|
|
12
12
|
const rootPkg = JSON.parse(fs.readFileSync(path.join(rooDir, `package.json`), 'utf-8'));
|
|
13
13
|
const LWR_VERSION = rootPkg.version;
|
|
14
|
-
const argv = minimist(process.argv.slice(2), { string: ['_'] });
|
|
14
|
+
const argv = minimist(process.argv.slice(2), { string: ['_'], boolean: ['yes', 'y'] });
|
|
15
15
|
const renameFiles = {
|
|
16
16
|
_gitignore: '.gitignore',
|
|
17
17
|
};
|
|
@@ -24,12 +24,32 @@ export async function init() {
|
|
|
24
24
|
defaultProjectName: !targetDir ? 'lwr-project' : targetDir,
|
|
25
25
|
};
|
|
26
26
|
let userFeedback = {};
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
if (argv.yes || argv.y) {
|
|
28
|
+
// Non-interactive mode for CI/automation - use defaults
|
|
29
|
+
const targetDir = metadata.targetDir || metadata.defaultProjectName;
|
|
30
|
+
const template = metadata.template || 'lwc-ts';
|
|
31
|
+
userFeedback = {
|
|
32
|
+
results: {
|
|
33
|
+
overwrite: true,
|
|
34
|
+
packageName: toValidPackageName(targetDir),
|
|
35
|
+
template,
|
|
36
|
+
},
|
|
37
|
+
metadata: {
|
|
38
|
+
...metadata,
|
|
39
|
+
targetDir,
|
|
40
|
+
template,
|
|
41
|
+
defaultProjectName: metadata.defaultProjectName,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
29
44
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
45
|
+
else {
|
|
46
|
+
try {
|
|
47
|
+
userFeedback = await promptForAnswers(metadata);
|
|
48
|
+
}
|
|
49
|
+
catch (cancelled) {
|
|
50
|
+
console.log(cancelled.message);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
33
53
|
}
|
|
34
54
|
const { results: { overwrite, packageName, template }, } = userFeedback;
|
|
35
55
|
const { metadata: revisedMetadata } = userFeedback;
|
|
@@ -44,7 +64,7 @@ function createRootDir(projectRoot, metadata, overwrite, template) {
|
|
|
44
64
|
if (overwrite) {
|
|
45
65
|
emptyDir(projectRoot);
|
|
46
66
|
}
|
|
47
|
-
|
|
67
|
+
if (!fs.existsSync(projectRoot)) {
|
|
48
68
|
fs.mkdirSync(projectRoot, { recursive: true });
|
|
49
69
|
}
|
|
50
70
|
// determine template
|
|
@@ -55,7 +75,7 @@ const write = (projectRoot, templateDir, file, content) => {
|
|
|
55
75
|
const targetPath = renameFiles[file]
|
|
56
76
|
? path.join(projectRoot, renameFiles[file])
|
|
57
77
|
: path.join(projectRoot, file);
|
|
58
|
-
if (content) {
|
|
78
|
+
if (content !== undefined) {
|
|
59
79
|
fs.writeFileSync(targetPath, content);
|
|
60
80
|
}
|
|
61
81
|
else {
|
|
@@ -81,6 +101,10 @@ function writePackageFile(projectRoot, templateDir, packageName, metadata) {
|
|
|
81
101
|
// Set nodeLinker in .yarnrc.yml if yarn is the selected package manager.
|
|
82
102
|
// LWR does not work when included in yarn pnp.
|
|
83
103
|
write(projectRoot, templateDir, '.yarnrc.yml', 'nodeLinker: node-modules');
|
|
104
|
+
// Create empty yarn.lock so Yarn treats this as a standalone project when created
|
|
105
|
+
// inside a parent workspace (e.g. LWR monorepo). Without it, "yarn" fails with
|
|
106
|
+
// "The nearest package directory doesn't seem to be part of the project".
|
|
107
|
+
write(projectRoot, templateDir, 'yarn.lock', '');
|
|
84
108
|
}
|
|
85
109
|
return pkgManager;
|
|
86
110
|
}
|
package/build/es/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AnswersWithMetadata, ProjectType, ProjectMetadata } from './types.js';
|
|
2
2
|
export declare const PROJECTS: ProjectType[];
|
|
3
|
+
export declare function toValidPackageName(projectName: string): string;
|
|
3
4
|
export declare function emptyDir(dir: string): void;
|
|
4
5
|
export declare function copy(src: string, dest: string): void;
|
|
5
6
|
export declare function pkgFromUserAgent(userAgent: string | undefined): {
|
package/build/es/utils.js
CHANGED
|
@@ -38,7 +38,7 @@ function isDirEmpty(path) {
|
|
|
38
38
|
function isValidPackageName(projectName) {
|
|
39
39
|
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName);
|
|
40
40
|
}
|
|
41
|
-
function toValidPackageName(projectName) {
|
|
41
|
+
export function toValidPackageName(projectName) {
|
|
42
42
|
return projectName
|
|
43
43
|
.trim()
|
|
44
44
|
.toLowerCase()
|
package/package.json
CHANGED
|
@@ -9,9 +9,7 @@
|
|
|
9
9
|
"bugs": {
|
|
10
10
|
"url": "https://github.com/salesforce-experience-platform-emu/lwr/issues"
|
|
11
11
|
},
|
|
12
|
-
"bin":
|
|
13
|
-
"create-lwr": "build/es/index.js"
|
|
14
|
-
},
|
|
12
|
+
"bin": "build/es/index.js",
|
|
15
13
|
"scripts": {
|
|
16
14
|
"build": "tsc -b",
|
|
17
15
|
"local:bin": "node ./build/es/index.js"
|
|
@@ -22,7 +20,7 @@
|
|
|
22
20
|
},
|
|
23
21
|
"type": "module",
|
|
24
22
|
"types": "build/es/index.d.ts",
|
|
25
|
-
"version": "0.22.
|
|
23
|
+
"version": "0.22.7",
|
|
26
24
|
"module": "build/es/index.js",
|
|
27
25
|
"main": "build/cjs/index.cjs",
|
|
28
26
|
"files": [
|
|
@@ -46,5 +44,5 @@
|
|
|
46
44
|
"volta": {
|
|
47
45
|
"extends": "../../package.json"
|
|
48
46
|
},
|
|
49
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "135ae2766d057181f67bee689ccdf377fd2fbc54"
|
|
50
48
|
}
|