create-barefootjs 0.1.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/dist/index.js +149 -0
- package/package.json +41 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { existsSync, mkdirSync, readdirSync } from "node:fs";
|
|
5
|
+
import { basename, resolve } from "node:path";
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
8
|
+
|
|
9
|
+
// src/text.ts
|
|
10
|
+
import readline from "node:readline";
|
|
11
|
+
var TextCancelled = class extends Error {
|
|
12
|
+
constructor(reason) {
|
|
13
|
+
super(`text prompt cancelled by user (${reason})`);
|
|
14
|
+
this.name = "TextCancelled";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
async function text(args) {
|
|
18
|
+
const input = args.input ?? process.stdin;
|
|
19
|
+
const output = args.output ?? process.stdout;
|
|
20
|
+
if (!input.isTTY || !output.isTTY) {
|
|
21
|
+
return args.defaultValue;
|
|
22
|
+
}
|
|
23
|
+
const rl = readline.createInterface({ input, output, terminal: true });
|
|
24
|
+
const prompt = `\x1B[33m?\x1B[0m \x1B[1m${args.message}\x1B[0m \x1B[2m(${args.defaultValue})\x1B[0m `;
|
|
25
|
+
return new Promise((resolve2, reject) => {
|
|
26
|
+
const onSigInt = () => {
|
|
27
|
+
rl.close();
|
|
28
|
+
output.write("\n");
|
|
29
|
+
reject(new TextCancelled("sigint"));
|
|
30
|
+
};
|
|
31
|
+
rl.once("SIGINT", onSigInt);
|
|
32
|
+
rl.question(prompt, (answer) => {
|
|
33
|
+
rl.close();
|
|
34
|
+
const trimmed = answer.trim();
|
|
35
|
+
const value = trimmed.length > 0 ? trimmed : args.defaultValue;
|
|
36
|
+
output.write("\x1B[1A\x1B[2K");
|
|
37
|
+
resolve2(value);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/index.ts
|
|
43
|
+
var require2 = createRequire(import.meta.url);
|
|
44
|
+
var DEFAULT_PROJECT_NAME = "my-app";
|
|
45
|
+
var DEFAULT_ADAPTER = "hono";
|
|
46
|
+
var DEFAULT_CSS = "unocss";
|
|
47
|
+
function highlight(value) {
|
|
48
|
+
return process.stdout.isTTY ? `\x1B[1;32m${value}\x1B[0m` : value;
|
|
49
|
+
}
|
|
50
|
+
function dim(value) {
|
|
51
|
+
return process.stdout.isTTY ? `\x1B[2m${value}\x1B[0m` : value;
|
|
52
|
+
}
|
|
53
|
+
var { version: CREATE_BAREFOOTJS_VERSION } = require2("../package.json");
|
|
54
|
+
function usage() {
|
|
55
|
+
console.log(`Usage: npm create barefootjs@latest [<project-name>] [-- --adapter <name>]
|
|
56
|
+
|
|
57
|
+
Scaffolds a runnable BarefootJS app. If <project-name> is omitted you'll
|
|
58
|
+
be prompted for one (defaults to "${DEFAULT_PROJECT_NAME}").
|
|
59
|
+
|
|
60
|
+
Options:
|
|
61
|
+
-y, --yes Accept all defaults (project name "${DEFAULT_PROJECT_NAME}", adapter hono, css unocss).
|
|
62
|
+
Skips every prompt \u2014 useful for CI and dotfiles.
|
|
63
|
+
-h, --help Show this message.
|
|
64
|
+
|
|
65
|
+
Forwarded to \`bf init\`:
|
|
66
|
+
--adapter <name> Adapter to use (default: hono)
|
|
67
|
+
--css <name> CSS library to use (default: unocss)
|
|
68
|
+
|
|
69
|
+
After scaffolding:
|
|
70
|
+
cd <project-name>
|
|
71
|
+
npm install
|
|
72
|
+
npm run dev
|
|
73
|
+
`);
|
|
74
|
+
process.exit(0);
|
|
75
|
+
}
|
|
76
|
+
function fail(msg) {
|
|
77
|
+
console.error(`Error: ${msg}`);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
async function main() {
|
|
81
|
+
const args = process.argv.slice(2);
|
|
82
|
+
if (args.includes("--help") || args.includes("-h")) usage();
|
|
83
|
+
console.log(dim(`create-barefootjs version ${CREATE_BAREFOOTJS_VERSION}`));
|
|
84
|
+
console.log();
|
|
85
|
+
const skipPrompts = args.includes("--yes") || args.includes("-y");
|
|
86
|
+
const positional = args.find((a) => !a.startsWith("-"));
|
|
87
|
+
const passthrough = args.filter(
|
|
88
|
+
(a) => a !== positional && a !== "--yes" && a !== "-y"
|
|
89
|
+
);
|
|
90
|
+
let projectName;
|
|
91
|
+
if (positional) {
|
|
92
|
+
projectName = positional;
|
|
93
|
+
} else if (skipPrompts) {
|
|
94
|
+
projectName = DEFAULT_PROJECT_NAME;
|
|
95
|
+
} else {
|
|
96
|
+
projectName = await text({
|
|
97
|
+
message: "Target directory",
|
|
98
|
+
defaultValue: DEFAULT_PROJECT_NAME
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
console.log(`\u2714 Target directory ${highlight(projectName)}`);
|
|
102
|
+
const targetDir = resolve(process.cwd(), projectName);
|
|
103
|
+
if (existsSync(targetDir)) {
|
|
104
|
+
const entries = readdirSync(targetDir).filter((e) => !e.startsWith("."));
|
|
105
|
+
if (entries.length > 0) {
|
|
106
|
+
fail(`target directory "${projectName}" exists and is not empty.`);
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
mkdirSync(targetDir, { recursive: true });
|
|
110
|
+
}
|
|
111
|
+
let cliBin;
|
|
112
|
+
try {
|
|
113
|
+
cliBin = require2.resolve("@barefootjs/cli/dist/index.js");
|
|
114
|
+
} catch {
|
|
115
|
+
fail(
|
|
116
|
+
"unable to resolve @barefootjs/cli. Reinstall create-barefootjs or report this if it persists."
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
const initArgs = ["--name", basename(projectName)];
|
|
120
|
+
if (skipPrompts) {
|
|
121
|
+
if (!passthrough.includes("--adapter")) initArgs.push("--adapter", DEFAULT_ADAPTER);
|
|
122
|
+
if (!passthrough.includes("--css")) initArgs.push("--css", DEFAULT_CSS);
|
|
123
|
+
}
|
|
124
|
+
for (const arg of passthrough) initArgs.push(arg);
|
|
125
|
+
const result = spawnSync("node", [cliBin, "init", ...initArgs], {
|
|
126
|
+
cwd: targetDir,
|
|
127
|
+
stdio: "inherit",
|
|
128
|
+
env: {
|
|
129
|
+
...process.env,
|
|
130
|
+
// Init reads this when rendering the "cd <path>" Next-steps
|
|
131
|
+
// line so a "foo/bar/bazz" positional shows as `cd foo/bar/bazz`
|
|
132
|
+
// instead of just `cd bazz`.
|
|
133
|
+
BAREFOOT_INIT_PROJECT_PATH: projectName,
|
|
134
|
+
// Sentinel — the only way `bf init` runs. Direct invocations
|
|
135
|
+
// (without this var) are bounced with a redirect to
|
|
136
|
+
// `npm create barefootjs@latest`. See packages/cli/src/commands/init.ts.
|
|
137
|
+
BAREFOOT_INIT_VIA_CREATE: "1"
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
process.exit(result.status ?? 1);
|
|
141
|
+
}
|
|
142
|
+
main().catch((err) => {
|
|
143
|
+
if (err && typeof err === "object" && "name" in err && err.name === "TextCancelled") {
|
|
144
|
+
console.error("\nCancelled \u2014 nothing scaffolded.");
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
console.error(err);
|
|
148
|
+
process.exit(1);
|
|
149
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-barefootjs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Scaffold a new BarefootJS app — `npm create barefootjs@latest <dir>`",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"create-barefootjs": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=22"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "node ./scripts/build.mjs",
|
|
18
|
+
"clean": "rm -rf dist",
|
|
19
|
+
"test": "bun test"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@barefootjs/cli": "workspace:*"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"esbuild": "^0.25.0",
|
|
26
|
+
"@types/node": "^22.0.0"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"barefootjs",
|
|
30
|
+
"create",
|
|
31
|
+
"starter",
|
|
32
|
+
"scaffold"
|
|
33
|
+
],
|
|
34
|
+
"author": "kobaken <kentafly88@gmail.com>",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/piconic-ai/barefootjs",
|
|
38
|
+
"directory": "packages/create-barefootjs"
|
|
39
|
+
},
|
|
40
|
+
"license": "MIT"
|
|
41
|
+
}
|