@sys-designer/create-vue 1.0.0 → 1.0.2
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/cli.mjs +40 -15
- package/package.json +1 -1
package/cli.mjs
CHANGED
|
@@ -60,16 +60,20 @@ function copyDir(src, dest, vars) {
|
|
|
60
60
|
function printHelp() {
|
|
61
61
|
console.log(`
|
|
62
62
|
Usage:
|
|
63
|
-
create-
|
|
63
|
+
create-vue [project-name] [options]
|
|
64
64
|
|
|
65
65
|
Options:
|
|
66
|
-
-h, --help
|
|
67
|
-
-d, --dir <dir>
|
|
66
|
+
-h, --help Show this help
|
|
67
|
+
-d, --dir <dir> Target directory (default: ./<project-name>)
|
|
68
|
+
-y, --yes Skip all prompts, use defaults (non-interactive)
|
|
69
|
+
-f, --force Overwrite target directory if it already exists
|
|
70
|
+
--author <name> Set package author
|
|
68
71
|
|
|
69
72
|
Examples:
|
|
70
|
-
create-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
create-vue my-app
|
|
74
|
+
create-vue my-app --yes --force
|
|
75
|
+
npm create @sys-designer/vue@latest my-app -- -y -f
|
|
76
|
+
npx @sys-designer/create-vue my-app
|
|
73
77
|
`);
|
|
74
78
|
}
|
|
75
79
|
|
|
@@ -82,18 +86,32 @@ async function main() {
|
|
|
82
86
|
|
|
83
87
|
let projectName = '';
|
|
84
88
|
let targetDir = '';
|
|
89
|
+
let author = process.env.USER || process.env.USERNAME || '';
|
|
90
|
+
let skipPrompts = false;
|
|
91
|
+
let force = false;
|
|
85
92
|
for (let i = 0; i < args.length; i++) {
|
|
86
|
-
|
|
93
|
+
const a = args[i];
|
|
94
|
+
if (a === '-y' || a === '--yes') {
|
|
95
|
+
skipPrompts = true;
|
|
96
|
+
} else if (a === '-f' || a === '--force') {
|
|
97
|
+
force = true;
|
|
98
|
+
} else if (a === '--author') {
|
|
99
|
+
author = args[++i];
|
|
100
|
+
} else if (a === '-d' || a === '--dir') {
|
|
87
101
|
targetDir = args[++i];
|
|
88
102
|
} else if (!projectName) {
|
|
89
|
-
projectName =
|
|
103
|
+
projectName = a;
|
|
90
104
|
}
|
|
91
105
|
}
|
|
92
106
|
|
|
93
107
|
if (!projectName) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
108
|
+
if (skipPrompts) {
|
|
109
|
+
projectName = 'sys-designer-vue-app';
|
|
110
|
+
} else {
|
|
111
|
+
const rl = readline.createInterface({ input: stdin, output: stdout });
|
|
112
|
+
projectName = (await rl.question('Project name: ')).trim();
|
|
113
|
+
await rl.close();
|
|
114
|
+
}
|
|
97
115
|
}
|
|
98
116
|
if (!projectName) {
|
|
99
117
|
console.error('Error: project name is required.');
|
|
@@ -104,16 +122,23 @@ async function main() {
|
|
|
104
122
|
const pkgName = toValidPackageName(projectName);
|
|
105
123
|
const destRoot = targetDir ? path.resolve(targetDir) : path.resolve(process.cwd(), pkgName);
|
|
106
124
|
|
|
107
|
-
if (fs.existsSync(destRoot)
|
|
108
|
-
|
|
109
|
-
|
|
125
|
+
if (fs.existsSync(destRoot)) {
|
|
126
|
+
const files = fs.readdirSync(destRoot);
|
|
127
|
+
if (files.length > 0) {
|
|
128
|
+
if (force) {
|
|
129
|
+
fs.rmSync(destRoot, { recursive: true, force: true });
|
|
130
|
+
} else {
|
|
131
|
+
console.error(`Error: target directory "${destRoot}" is not empty. Use --force to overwrite.`);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
110
135
|
}
|
|
111
136
|
|
|
112
137
|
console.log(`\nScaffolding project in ${destRoot} ...`);
|
|
113
138
|
copyDir(TEMPLATE_DIR, destRoot, {
|
|
114
139
|
projectName: pkgName,
|
|
115
140
|
name: pkgName,
|
|
116
|
-
author
|
|
141
|
+
author,
|
|
117
142
|
});
|
|
118
143
|
|
|
119
144
|
console.log(`
|