@blockquote/create-wc 2.7.5 → 2.8.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/package.json +1 -1
- package/src/Generator.js +87 -1
package/package.json
CHANGED
package/src/Generator.js
CHANGED
|
@@ -1,4 +1,42 @@
|
|
|
1
|
+
import prompts from 'prompts';
|
|
2
|
+
import {spawn} from 'child_process';
|
|
1
3
|
import _Generator from '@open-wc/create/dist/Generator.js';
|
|
4
|
+
import {writeFilesToDisk} from '@open-wc/create/dist/core.js';
|
|
5
|
+
|
|
6
|
+
const isWindows = process.platform === 'win32';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} command
|
|
10
|
+
* @param {object} options
|
|
11
|
+
*/
|
|
12
|
+
function _install(command = 'npm', options = {}) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const cmdCommand = isWindows ? `${command}.cmd` : command;
|
|
15
|
+
|
|
16
|
+
const install = spawn(cmdCommand, ['install'], {
|
|
17
|
+
...options,
|
|
18
|
+
stdio: 'inherit',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
install.on('close', (code) => {
|
|
22
|
+
if (code === 0) resolve();
|
|
23
|
+
else reject(new Error(`${command} install failed with code ${code}`));
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @param {string} where
|
|
31
|
+
* @param {string} command
|
|
32
|
+
*/
|
|
33
|
+
export async function installNpm(where, command) {
|
|
34
|
+
console.log('');
|
|
35
|
+
console.log('Installing dependencies...');
|
|
36
|
+
console.log(`Using ${command} to install...`);
|
|
37
|
+
await _install(command, {cwd: where});
|
|
38
|
+
console.log('');
|
|
39
|
+
}
|
|
2
40
|
|
|
3
41
|
/**
|
|
4
42
|
* Options for the generator
|
|
@@ -9,13 +47,61 @@ import _Generator from '@open-wc/create/dist/Generator.js';
|
|
|
9
47
|
* @property {'true'|'false'} [writeToDisk] whether to write to disk
|
|
10
48
|
* @property {'yarn'|'npm'|'false'} [installDependencies] whether and with which tool to install dependencies
|
|
11
49
|
*/
|
|
12
|
-
|
|
13
50
|
class Generator extends _Generator.default {
|
|
14
51
|
constructor() {
|
|
15
52
|
super();
|
|
16
53
|
this.wantsRecreateInfo = false;
|
|
17
54
|
this.generatorName = '@blockquote/wc';
|
|
18
55
|
}
|
|
56
|
+
async end() {
|
|
57
|
+
if (this.wantsWriteToDisk) {
|
|
58
|
+
this.options.writeToDisk = await writeFilesToDisk();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (this.wantsNpmInstall) {
|
|
62
|
+
const answers = await prompts(
|
|
63
|
+
[
|
|
64
|
+
{
|
|
65
|
+
type: 'select',
|
|
66
|
+
name: 'installDependencies',
|
|
67
|
+
message: 'Do you want to install dependencies?',
|
|
68
|
+
choices: [
|
|
69
|
+
{title: 'No', value: 'false'},
|
|
70
|
+
{title: 'Yes, with npm', value: 'npm'},
|
|
71
|
+
{title: 'Yes, with pnpm', value: 'pnpm'},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
{
|
|
76
|
+
onCancel: () => {
|
|
77
|
+
process.exit();
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
this.options.installDependencies = answers.installDependencies;
|
|
83
|
+
const {installDependencies} = this.options;
|
|
84
|
+
if (installDependencies === 'pnpm' || installDependencies === 'npm') {
|
|
85
|
+
await installNpm(this.options.destinationPath, installDependencies);
|
|
86
|
+
|
|
87
|
+
await new Promise((resolve, reject) => {
|
|
88
|
+
const cmdInstallDependencies = isWindows
|
|
89
|
+
? `${installDependencies}.cmd`
|
|
90
|
+
: installDependencies;
|
|
91
|
+
|
|
92
|
+
const install = spawn(cmdInstallDependencies, ['run', 'analyze'], {
|
|
93
|
+
cwd: this.options.destinationPath,
|
|
94
|
+
stdio: 'inherit',
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
install.on('close', (code) => {
|
|
98
|
+
if (code === 0) resolve();
|
|
99
|
+
else reject(new Error(`${installDependencies} run analyze failed`));
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
19
105
|
}
|
|
20
106
|
|
|
21
107
|
export default Generator;
|