create-crust 0.0.6 → 0.0.8
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/README.md +3 -1
- package/dist/index.js +55 -46
- package/package.json +4 -2
- package/templates/base/README.md +24 -0
- package/templates/base/_gitignore +32 -0
- package/templates/base/package.json +9 -5
- package/templates/base/src/cli.ts +2 -8
package/README.md
CHANGED
|
@@ -8,11 +8,13 @@ Scaffold a new [Crust](https://crustjs.com) CLI project in seconds.
|
|
|
8
8
|
bun create crust my-cli
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
This will prompt for project
|
|
11
|
+
This will prompt for your project directory, install dependencies, and optionally initialize a git repository. The package name is inferred from the directory name. The generated project includes:
|
|
12
12
|
|
|
13
13
|
- `src/cli.ts` — entry point with a sample command
|
|
14
14
|
- `package.json` — configured with `crust build` and `bun run` dev scripts
|
|
15
15
|
- `tsconfig.json` — strict TypeScript config
|
|
16
|
+
- `README.md` — getting started instructions
|
|
17
|
+
- `.gitignore` — sensible defaults for Node/Bun projects
|
|
16
18
|
|
|
17
19
|
## Documentation
|
|
18
20
|
|
package/dist/index.js
CHANGED
|
@@ -4,13 +4,9 @@
|
|
|
4
4
|
// src/index.ts
|
|
5
5
|
import { existsSync } from "fs";
|
|
6
6
|
import { basename, resolve } from "path";
|
|
7
|
-
import {
|
|
8
|
-
import { runSteps, scaffold } from "@crustjs/create";
|
|
9
|
-
|
|
10
|
-
const suffix = defaultValue ? ` (${defaultValue})` : "";
|
|
11
|
-
const answer = await rl.question(`${question}${suffix}: `);
|
|
12
|
-
return answer.trim() || defaultValue;
|
|
13
|
-
}
|
|
7
|
+
import { defineCommand, runMain } from "@crustjs/core";
|
|
8
|
+
import { detectPackageManager, runSteps, scaffold } from "@crustjs/create";
|
|
9
|
+
import { confirm, input, spinner } from "@crustjs/prompts";
|
|
14
10
|
var INVALID_NAME_CHARS = /[<>:"|?*\\]/;
|
|
15
11
|
function validateProjectName(name) {
|
|
16
12
|
if (!name) {
|
|
@@ -19,61 +15,74 @@ function validateProjectName(name) {
|
|
|
19
15
|
if (INVALID_NAME_CHARS.test(name)) {
|
|
20
16
|
return `Project name contains invalid characters: ${name}`;
|
|
21
17
|
}
|
|
22
|
-
return
|
|
18
|
+
return true;
|
|
23
19
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
var command = defineCommand({
|
|
21
|
+
meta: {
|
|
22
|
+
name: "create-crust",
|
|
23
|
+
description: "Scaffold a new Crust CLI project"
|
|
24
|
+
},
|
|
25
|
+
args: [
|
|
26
|
+
{
|
|
27
|
+
name: "directory",
|
|
28
|
+
type: "string",
|
|
29
|
+
description: "Project directory to scaffold into"
|
|
33
30
|
}
|
|
31
|
+
],
|
|
32
|
+
async run({ args }) {
|
|
33
|
+
const targetDir = args.directory ?? await input({
|
|
34
|
+
message: "Project directory",
|
|
35
|
+
placeholder: "my-cli",
|
|
36
|
+
validate: validateProjectName
|
|
37
|
+
});
|
|
34
38
|
const resolvedDir = resolve(process.cwd(), targetDir);
|
|
35
39
|
const dirName = basename(resolvedDir);
|
|
36
|
-
if (existsSync(resolvedDir)) {
|
|
37
|
-
const
|
|
38
|
-
|
|
40
|
+
if (targetDir !== "." && existsSync(resolvedDir)) {
|
|
41
|
+
const overwrite = await confirm({
|
|
42
|
+
message: `Directory "${dirName}" already exists. Overwrite?`,
|
|
43
|
+
default: false
|
|
44
|
+
});
|
|
45
|
+
if (!overwrite) {
|
|
39
46
|
console.log("Aborted.");
|
|
40
47
|
return;
|
|
41
48
|
}
|
|
42
49
|
}
|
|
43
|
-
const name =
|
|
44
|
-
const nameError = validateProjectName(name);
|
|
45
|
-
if (nameError) {
|
|
46
|
-
throw new Error(nameError);
|
|
47
|
-
}
|
|
48
|
-
const description = await prompt(rl, "Description", "A CLI built with Crust");
|
|
49
|
-
const author = await prompt(rl, "Author", "");
|
|
50
|
+
const name = dirName;
|
|
50
51
|
await scaffold({
|
|
51
|
-
template: "
|
|
52
|
+
template: "./templates/base",
|
|
52
53
|
dest: resolvedDir,
|
|
53
|
-
|
|
54
|
-
context: { name, description, author },
|
|
54
|
+
context: { name },
|
|
55
55
|
conflict: "overwrite"
|
|
56
56
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
const installDeps = await confirm({
|
|
58
|
+
message: "Install dependencies?",
|
|
59
|
+
default: true
|
|
60
|
+
});
|
|
61
|
+
if (installDeps) {
|
|
62
|
+
const pm = detectPackageManager(resolvedDir);
|
|
63
|
+
const installCmd = pm === "npm" ? "npm install" : `${pm} install`;
|
|
64
|
+
await runSteps([{ type: "command", cmd: installCmd }], resolvedDir);
|
|
65
|
+
}
|
|
66
|
+
const initGit = await confirm({
|
|
67
|
+
message: "Initialize a git repository?",
|
|
68
|
+
default: true
|
|
69
|
+
});
|
|
70
|
+
if (initGit) {
|
|
71
|
+
await spinner({
|
|
72
|
+
message: "Initializing git repository...",
|
|
73
|
+
task: () => runSteps([{ type: "git-init", commit: "chore: initial commit" }], resolvedDir)
|
|
74
|
+
});
|
|
75
|
+
}
|
|
62
76
|
console.log(`
|
|
63
77
|
Created ${name}!
|
|
64
78
|
`);
|
|
65
79
|
console.log("Next steps:");
|
|
66
|
-
|
|
80
|
+
if (targetDir !== ".") {
|
|
81
|
+
const relativeDir = targetDir.startsWith("/") ? targetDir : `./${targetDir}`;
|
|
82
|
+
console.log(` cd ${relativeDir}`);
|
|
83
|
+
}
|
|
67
84
|
console.log(" bun run dev");
|
|
68
85
|
console.log(" bun run build");
|
|
69
|
-
} finally {
|
|
70
|
-
rl.close();
|
|
71
86
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (isMainModule) {
|
|
75
|
-
main();
|
|
76
|
-
}
|
|
77
|
-
export {
|
|
78
|
-
main
|
|
79
|
-
};
|
|
87
|
+
});
|
|
88
|
+
runMain(command);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-crust",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Scaffold a new Crust CLI project.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,9 @@
|
|
|
40
40
|
"test": "bun test"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@crustjs/
|
|
43
|
+
"@crustjs/core": "0.0.6",
|
|
44
|
+
"@crustjs/create": "0.0.2",
|
|
45
|
+
"@crustjs/prompts": "0.0.2"
|
|
44
46
|
},
|
|
45
47
|
"devDependencies": {
|
|
46
48
|
"@crustjs/config": "0.0.0",
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# {{name}}
|
|
2
|
+
|
|
3
|
+
A CLI built with [Crust](https://crustjs.com).
|
|
4
|
+
|
|
5
|
+
## Development
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
# Run in dev mode
|
|
9
|
+
bun run dev
|
|
10
|
+
|
|
11
|
+
# Type-check
|
|
12
|
+
bun run check:types
|
|
13
|
+
|
|
14
|
+
# Build standalone executable
|
|
15
|
+
bun run build
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
# Run the CLI
|
|
22
|
+
{{name}} world
|
|
23
|
+
{{name}} --greet Hey world
|
|
24
|
+
```
|
|
@@ -1,2 +1,34 @@
|
|
|
1
|
+
# dependencies (bun install)
|
|
1
2
|
node_modules
|
|
3
|
+
|
|
4
|
+
# output
|
|
5
|
+
out
|
|
2
6
|
dist
|
|
7
|
+
*.tgz
|
|
8
|
+
|
|
9
|
+
# code coverage
|
|
10
|
+
coverage
|
|
11
|
+
*.lcov
|
|
12
|
+
|
|
13
|
+
# logs
|
|
14
|
+
logs
|
|
15
|
+
_.log
|
|
16
|
+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
|
17
|
+
|
|
18
|
+
# dotenv environment variable files
|
|
19
|
+
.env
|
|
20
|
+
.env.development.local
|
|
21
|
+
.env.test.local
|
|
22
|
+
.env.production.local
|
|
23
|
+
.env.local
|
|
24
|
+
|
|
25
|
+
# caches
|
|
26
|
+
.eslintcache
|
|
27
|
+
.cache
|
|
28
|
+
*.tsbuildinfo
|
|
29
|
+
|
|
30
|
+
# IntelliJ based IDEs
|
|
31
|
+
.idea
|
|
32
|
+
|
|
33
|
+
# Finder (MacOS) folder config
|
|
34
|
+
.DS_Store
|
|
@@ -2,19 +2,23 @@
|
|
|
2
2
|
"name": "{{name}}",
|
|
3
3
|
"version": "0.0.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "
|
|
6
|
-
"author": "{{author}}",
|
|
5
|
+
"description": "A CLI built with Crust",
|
|
7
6
|
"bin": {
|
|
8
|
-
"{{name}}": "dist/cli
|
|
7
|
+
"{{name}}": "dist/cli"
|
|
9
8
|
},
|
|
10
9
|
"scripts": {
|
|
10
|
+
"dev": "bun run src/cli.ts",
|
|
11
11
|
"build": "crust build",
|
|
12
|
-
"
|
|
12
|
+
"start": "./dist/cli",
|
|
13
|
+
"check:types": "tsc --noEmit"
|
|
13
14
|
},
|
|
14
15
|
"dependencies": {
|
|
15
|
-
"@crustjs/
|
|
16
|
+
"@crustjs/core": "latest",
|
|
17
|
+
"@crustjs/plugins": "latest"
|
|
16
18
|
},
|
|
17
19
|
"devDependencies": {
|
|
20
|
+
"@crustjs/crust": "latest",
|
|
21
|
+
"@types/bun": "latest",
|
|
18
22
|
"typescript": "^5"
|
|
19
23
|
}
|
|
20
24
|
}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
defineCommand,
|
|
5
|
-
helpPlugin,
|
|
6
|
-
runMain,
|
|
7
|
-
versionPlugin,
|
|
8
|
-
} from "@crustjs/crust";
|
|
1
|
+
import { defineCommand, runMain } from "@crustjs/core";
|
|
2
|
+
import { helpPlugin, versionPlugin } from "@crustjs/plugins";
|
|
9
3
|
import pkg from "../package.json";
|
|
10
4
|
|
|
11
5
|
const main = defineCommand({
|