create-cabloy 5.0.0 → 5.0.1
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/dist/index.mjs +33 -34
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import * as p from '@clack/prompts';
|
|
3
|
+
import mri from 'mri';
|
|
2
4
|
import { createWriteStream, existsSync } from 'node:fs';
|
|
3
5
|
import { unlink, mkdir } from 'node:fs/promises';
|
|
4
|
-
import { join, dirname, resolve
|
|
5
|
-
import mri from 'mri';
|
|
6
|
-
import * as p from '@clack/prompts';
|
|
6
|
+
import { join, dirname, resolve } from 'node:path';
|
|
7
7
|
import pc from 'picocolors';
|
|
8
|
-
import { pipeline } from 'node:stream/promises';
|
|
9
|
-
import { tmpdir } from 'node:os';
|
|
10
8
|
import spawn from 'cross-spawn';
|
|
9
|
+
import { tmpdir } from 'node:os';
|
|
10
|
+
import { pipeline } from 'node:stream/promises';
|
|
11
11
|
|
|
12
12
|
const NPM_REGISTRY = "https://registry.npmjs.org";
|
|
13
13
|
const PACKAGE_NAME = "cabloy";
|
|
@@ -44,7 +44,13 @@ async function downloadTarball(tarballUrl) {
|
|
|
44
44
|
}
|
|
45
45
|
async function extractTarball(tarballPath, targetDir) {
|
|
46
46
|
await mkdir(targetDir, { recursive: true });
|
|
47
|
-
const exitCode = await spawnAsync("tar", [
|
|
47
|
+
const exitCode = await spawnAsync("tar", [
|
|
48
|
+
"--strip-components=1",
|
|
49
|
+
"-xzf",
|
|
50
|
+
tarballPath,
|
|
51
|
+
"-C",
|
|
52
|
+
targetDir
|
|
53
|
+
]);
|
|
48
54
|
if (exitCode !== 0) {
|
|
49
55
|
throw new Error("Failed to extract tarball");
|
|
50
56
|
}
|
|
@@ -73,15 +79,18 @@ function spawnAsync(command, args, options) {
|
|
|
73
79
|
|
|
74
80
|
async function runPrompts(options) {
|
|
75
81
|
p.intro(pc.bgCyan(pc.black(" Create Cabloy ")));
|
|
76
|
-
let projectName
|
|
82
|
+
let projectName;
|
|
77
83
|
if (options.projectName) {
|
|
78
84
|
projectName = isValidPackageName(options.projectName) ? options.projectName : toValidPackageName(options.projectName);
|
|
79
85
|
} else {
|
|
80
86
|
const name = await p.text({
|
|
81
|
-
message: "Project name
|
|
87
|
+
message: "Project name",
|
|
82
88
|
placeholder: "cabloy-app",
|
|
83
89
|
validate: (v) => {
|
|
84
|
-
if (v.trim()
|
|
90
|
+
if (!v.trim()) {
|
|
91
|
+
return "Project name is required";
|
|
92
|
+
}
|
|
93
|
+
if (!isValidPackageName(v) && !isValidPackageName(toValidPackageName(v))) {
|
|
85
94
|
return "Invalid package name";
|
|
86
95
|
}
|
|
87
96
|
return void 0;
|
|
@@ -91,11 +100,7 @@ async function runPrompts(options) {
|
|
|
91
100
|
p.cancel("Operation cancelled");
|
|
92
101
|
return null;
|
|
93
102
|
}
|
|
94
|
-
|
|
95
|
-
projectName = isValidPackageName(name) ? name : toValidPackageName(name);
|
|
96
|
-
} else {
|
|
97
|
-
projectName = null;
|
|
98
|
-
}
|
|
103
|
+
projectName = isValidPackageName(name) ? name : toValidPackageName(name);
|
|
99
104
|
}
|
|
100
105
|
return {
|
|
101
106
|
projectName,
|
|
@@ -104,13 +109,13 @@ async function runPrompts(options) {
|
|
|
104
109
|
}
|
|
105
110
|
|
|
106
111
|
function printHelp() {
|
|
107
|
-
|
|
112
|
+
p.log.info(`
|
|
108
113
|
${pc.bold("create-cabloy")} - Create a new Cabloy project
|
|
109
114
|
|
|
110
115
|
${pc.bold("Usage:")}
|
|
111
|
-
${pc.cyan("npm create cabloy")} ${pc.dim("
|
|
112
|
-
${pc.cyan("pnpm create cabloy")} ${pc.dim("
|
|
113
|
-
${pc.cyan("yarn create cabloy")} ${pc.dim("
|
|
116
|
+
${pc.cyan("npm create cabloy")} ${pc.dim("<project-name>")}
|
|
117
|
+
${pc.cyan("pnpm create cabloy")} ${pc.dim("<project-name>")}
|
|
118
|
+
${pc.cyan("yarn create cabloy")} ${pc.dim("<project-name>")}
|
|
114
119
|
|
|
115
120
|
${pc.bold("Options:")}
|
|
116
121
|
--force Overwrite existing directory
|
|
@@ -130,7 +135,7 @@ async function main() {
|
|
|
130
135
|
}
|
|
131
136
|
if (args.version) {
|
|
132
137
|
const { default: pkg } = await import('./chunks/package.mjs');
|
|
133
|
-
|
|
138
|
+
p.log.info(pkg.version);
|
|
134
139
|
process.exit(0);
|
|
135
140
|
}
|
|
136
141
|
const result = await runPrompts({
|
|
@@ -140,26 +145,19 @@ async function main() {
|
|
|
140
145
|
if (!result) {
|
|
141
146
|
process.exit(0);
|
|
142
147
|
}
|
|
143
|
-
|
|
144
|
-
if (
|
|
145
|
-
targetDir = resolve(process.cwd(), result.projectName);
|
|
146
|
-
result.projectName;
|
|
147
|
-
} else {
|
|
148
|
-
targetDir = process.cwd();
|
|
149
|
-
basename(targetDir);
|
|
150
|
-
}
|
|
151
|
-
if (existsSync(targetDir) && result.projectName) {
|
|
148
|
+
const targetDir = resolve(process.cwd(), result.projectName);
|
|
149
|
+
if (existsSync(targetDir)) {
|
|
152
150
|
const files = await import('node:fs/promises').then((fs) => fs.readdir(targetDir));
|
|
153
151
|
if (files.length > 0 && !result.force) {
|
|
154
152
|
p.log.error(
|
|
155
|
-
pc.red(
|
|
153
|
+
pc.red(
|
|
154
|
+
`Directory "${result.projectName}" already exists and is not empty. Use --force to overwrite.`
|
|
155
|
+
)
|
|
156
156
|
);
|
|
157
157
|
process.exit(1);
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
-
|
|
161
|
-
await mkdir(targetDir, { recursive: true });
|
|
162
|
-
}
|
|
160
|
+
await mkdir(targetDir, { recursive: true });
|
|
163
161
|
const s = p.spinner();
|
|
164
162
|
s.start("Downloading cabloy from npm registry...");
|
|
165
163
|
try {
|
|
@@ -182,8 +180,9 @@ async function main() {
|
|
|
182
180
|
s2.stop("Project initialized successfully!");
|
|
183
181
|
}
|
|
184
182
|
p.outro(
|
|
185
|
-
pc.green(" Done! ")
|
|
186
|
-
|
|
183
|
+
`${pc.green(" Done! ")}Next steps:
|
|
184
|
+
${pc.dim(` cd ${result.projectName}
|
|
185
|
+
`)}${pc.dim(" npm run dev\n")}`
|
|
187
186
|
);
|
|
188
187
|
}
|
|
189
188
|
main().catch((err) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-cabloy",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Create a new Cabloy project - npm create cabloy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cabloy",
|
|
@@ -21,6 +21,12 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"type": "module",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"dev": "unbuild --stub",
|
|
26
|
+
"build": "unbuild",
|
|
27
|
+
"release-patch": "npm version patch && npm publish && git push --follow-tags",
|
|
28
|
+
"release-minor": "npm version minor && npm publish && git push --follow-tags"
|
|
29
|
+
},
|
|
24
30
|
"dependencies": {
|
|
25
31
|
"@clack/prompts": "^0.9.1",
|
|
26
32
|
"cross-spawn": "^7.0.6",
|
|
@@ -35,11 +41,5 @@
|
|
|
35
41
|
},
|
|
36
42
|
"engines": {
|
|
37
43
|
"node": ">=20.19.0"
|
|
38
|
-
},
|
|
39
|
-
"scripts": {
|
|
40
|
-
"dev": "unbuild --stub",
|
|
41
|
-
"build": "unbuild",
|
|
42
|
-
"release-patch": "npm version patch && npm publish && git push --follow-tags",
|
|
43
|
-
"release-minor": "npm version minor && npm publish && git push --follow-tags"
|
|
44
44
|
}
|
|
45
|
-
}
|
|
45
|
+
}
|