create-crust 0.0.5 → 0.0.6
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.js +10 -101
- package/package.json +6 -2
- package/templates/base/_gitignore +2 -0
- package/templates/base/package.json +20 -0
- package/templates/base/src/cli.ts +39 -0
- package/templates/base/tsconfig.json +17 -0
package/dist/index.js
CHANGED
|
@@ -2,92 +2,10 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/index.ts
|
|
5
|
-
import { existsSync
|
|
5
|
+
import { existsSync } from "fs";
|
|
6
6
|
import { basename, resolve } from "path";
|
|
7
7
|
import { createInterface } from "readline/promises";
|
|
8
|
-
|
|
9
|
-
const pkg = {
|
|
10
|
-
name,
|
|
11
|
-
version: "0.0.0",
|
|
12
|
-
type: "module",
|
|
13
|
-
bin: {
|
|
14
|
-
[name]: "dist/cli.js"
|
|
15
|
-
},
|
|
16
|
-
scripts: {
|
|
17
|
-
build: "crust build",
|
|
18
|
-
dev: "bun run src/cli.ts"
|
|
19
|
-
},
|
|
20
|
-
dependencies: {
|
|
21
|
-
"@crustjs/crust": "latest"
|
|
22
|
-
},
|
|
23
|
-
devDependencies: {
|
|
24
|
-
typescript: "^5"
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
if (description) {
|
|
28
|
-
pkg.description = description;
|
|
29
|
-
}
|
|
30
|
-
if (author) {
|
|
31
|
-
pkg.author = author;
|
|
32
|
-
}
|
|
33
|
-
return JSON.stringify(pkg, null, 2);
|
|
34
|
-
}
|
|
35
|
-
function templateTsconfig() {
|
|
36
|
-
return JSON.stringify({
|
|
37
|
-
compilerOptions: {
|
|
38
|
-
lib: ["ESNext"],
|
|
39
|
-
target: "ESNext",
|
|
40
|
-
module: "Preserve",
|
|
41
|
-
moduleDetection: "force",
|
|
42
|
-
moduleResolution: "bundler",
|
|
43
|
-
allowImportingTsExtensions: true,
|
|
44
|
-
verbatimModuleSyntax: true,
|
|
45
|
-
noEmit: true,
|
|
46
|
-
strict: true,
|
|
47
|
-
skipLibCheck: true,
|
|
48
|
-
noFallthroughCasesInSwitch: true,
|
|
49
|
-
noUncheckedIndexedAccess: true
|
|
50
|
-
},
|
|
51
|
-
include: ["src"]
|
|
52
|
-
}, null, 2);
|
|
53
|
-
}
|
|
54
|
-
function templateCliTs(name) {
|
|
55
|
-
return `#!/usr/bin/env bun
|
|
56
|
-
|
|
57
|
-
import { defineCommand, helpPlugin, runMain, versionPlugin } from "@crustjs/crust";
|
|
58
|
-
import pkg from "../package.json";
|
|
59
|
-
|
|
60
|
-
const main = defineCommand({
|
|
61
|
-
meta: {
|
|
62
|
-
name: "${name}",
|
|
63
|
-
description: "A CLI built with Crust",
|
|
64
|
-
},
|
|
65
|
-
args: [
|
|
66
|
-
{
|
|
67
|
-
name: "name",
|
|
68
|
-
type: "string",
|
|
69
|
-
description: "Your name",
|
|
70
|
-
default: "world",
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
flags: {
|
|
74
|
-
greet: {
|
|
75
|
-
type: "string",
|
|
76
|
-
description: "Greeting to use",
|
|
77
|
-
default: "Hello",
|
|
78
|
-
alias: "g",
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
run({ args, flags }) {
|
|
82
|
-
console.log(\`\${flags.greet}, \${args.name}!\`);
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
runMain(main, {
|
|
87
|
-
plugins: [versionPlugin(pkg.version), helpPlugin()],
|
|
88
|
-
});
|
|
89
|
-
`;
|
|
90
|
-
}
|
|
8
|
+
import { runSteps, scaffold } from "@crustjs/create";
|
|
91
9
|
async function prompt(rl, question, defaultValue) {
|
|
92
10
|
const suffix = defaultValue ? ` (${defaultValue})` : "";
|
|
93
11
|
const answer = await rl.question(`${question}${suffix}: `);
|
|
@@ -103,15 +21,6 @@ function validateProjectName(name) {
|
|
|
103
21
|
}
|
|
104
22
|
return null;
|
|
105
23
|
}
|
|
106
|
-
function scaffold(options) {
|
|
107
|
-
const { dir, name, description, author } = options;
|
|
108
|
-
mkdirSync(resolve(dir, "src"), { recursive: true });
|
|
109
|
-
writeFileSync(resolve(dir, "package.json"), `${templatePackageJson(name, description, author)}
|
|
110
|
-
`);
|
|
111
|
-
writeFileSync(resolve(dir, "tsconfig.json"), `${templateTsconfig()}
|
|
112
|
-
`);
|
|
113
|
-
writeFileSync(resolve(dir, "src", "cli.ts"), templateCliTs(name));
|
|
114
|
-
}
|
|
115
24
|
async function main(argv = process.argv.slice(2)) {
|
|
116
25
|
const rl = createInterface({
|
|
117
26
|
input: process.stdin,
|
|
@@ -138,16 +47,17 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
138
47
|
}
|
|
139
48
|
const description = await prompt(rl, "Description", "A CLI built with Crust");
|
|
140
49
|
const author = await prompt(rl, "Author", "");
|
|
141
|
-
scaffold({
|
|
50
|
+
await scaffold({
|
|
51
|
+
template: "../templates/base",
|
|
52
|
+
dest: resolvedDir,
|
|
53
|
+
importMeta: import.meta.url,
|
|
54
|
+
context: { name, description, author },
|
|
55
|
+
conflict: "overwrite"
|
|
56
|
+
});
|
|
142
57
|
console.log(`
|
|
143
58
|
Installing dependencies...
|
|
144
59
|
`);
|
|
145
|
-
|
|
146
|
-
cwd: resolvedDir,
|
|
147
|
-
stdout: "inherit",
|
|
148
|
-
stderr: "inherit"
|
|
149
|
-
});
|
|
150
|
-
await install.exited;
|
|
60
|
+
await runSteps([{ type: "install" }], resolvedDir);
|
|
151
61
|
const relativeDir = targetDir.startsWith("/") ? targetDir : `./${targetDir}`;
|
|
152
62
|
console.log(`
|
|
153
63
|
Created ${name}!
|
|
@@ -165,6 +75,5 @@ if (isMainModule) {
|
|
|
165
75
|
main();
|
|
166
76
|
}
|
|
167
77
|
export {
|
|
168
|
-
scaffold,
|
|
169
78
|
main
|
|
170
79
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-crust",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Scaffold a new Crust CLI project.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"crust"
|
|
25
25
|
],
|
|
26
26
|
"files": [
|
|
27
|
-
"dist"
|
|
27
|
+
"dist",
|
|
28
|
+
"templates"
|
|
28
29
|
],
|
|
29
30
|
"publishConfig": {
|
|
30
31
|
"access": "public"
|
|
@@ -38,6 +39,9 @@
|
|
|
38
39
|
"check:types": "tsc --noEmit",
|
|
39
40
|
"test": "bun test"
|
|
40
41
|
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@crustjs/create": "0.0.1"
|
|
44
|
+
},
|
|
41
45
|
"devDependencies": {
|
|
42
46
|
"@crustjs/config": "0.0.0",
|
|
43
47
|
"bunup": "^0.16.29"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{name}}",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "{{description}}",
|
|
6
|
+
"author": "{{author}}",
|
|
7
|
+
"bin": {
|
|
8
|
+
"{{name}}": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "crust build",
|
|
12
|
+
"dev": "bun run src/cli.ts"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@crustjs/crust": "latest"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
defineCommand,
|
|
5
|
+
helpPlugin,
|
|
6
|
+
runMain,
|
|
7
|
+
versionPlugin,
|
|
8
|
+
} from "@crustjs/crust";
|
|
9
|
+
import pkg from "../package.json";
|
|
10
|
+
|
|
11
|
+
const main = defineCommand({
|
|
12
|
+
meta: {
|
|
13
|
+
name: "{{name}}",
|
|
14
|
+
description: "A CLI built with Crust",
|
|
15
|
+
},
|
|
16
|
+
args: [
|
|
17
|
+
{
|
|
18
|
+
name: "name",
|
|
19
|
+
type: "string",
|
|
20
|
+
description: "Your name",
|
|
21
|
+
default: "world",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
flags: {
|
|
25
|
+
greet: {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "Greeting to use",
|
|
28
|
+
default: "Hello",
|
|
29
|
+
alias: "g",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
run({ args, flags }) {
|
|
33
|
+
console.log(`${flags.greet}, ${args.name}!`);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
runMain(main, {
|
|
38
|
+
plugins: [versionPlugin(pkg.version), helpPlugin()],
|
|
39
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": ["ESNext"],
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"module": "Preserve",
|
|
6
|
+
"moduleDetection": "force",
|
|
7
|
+
"moduleResolution": "bundler",
|
|
8
|
+
"allowImportingTsExtensions": true,
|
|
9
|
+
"verbatimModuleSyntax": true,
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"noFallthroughCasesInSwitch": true,
|
|
14
|
+
"noUncheckedIndexedAccess": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src"]
|
|
17
|
+
}
|