create-barefootjs 0.17.1 → 0.18.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.
Files changed (2) hide show
  1. package/dist/index.js +34 -11
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { existsSync, mkdirSync, readdirSync } from "node:fs";
4
+ import { existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
5
5
  import { basename, resolve } from "node:path";
6
6
  import { spawnSync } from "node:child_process";
7
7
  import { createRequire } from "node:module";
@@ -60,10 +60,12 @@ be prompted for one (defaults to "${DEFAULT_PROJECT_NAME}").
60
60
  Options:
61
61
  -y, --yes Accept all defaults (project name "${DEFAULT_PROJECT_NAME}", adapter hono, css unocss).
62
62
  Skips every prompt \u2014 useful for CI and dotfiles.
63
+ --list-adapters Print every adapter id + CSS library option, then exit.
63
64
  -h, --help Show this message.
64
65
 
65
66
  Forwarded to \`bf init\`:
66
- --adapter <name> Adapter to use (default: hono)
67
+ --adapter <name> Adapter to use (default: hono). Run --list-adapters
68
+ to see every adapter id.
67
69
  --css <name> CSS setup to use: "unocss" (default) or "none"
68
70
  ("none" = bring your own CSS: no UnoCSS, no UI
69
71
  components, just the compiler output)
@@ -79,9 +81,26 @@ function fail(msg) {
79
81
  console.error(`Error: ${msg}`);
80
82
  process.exit(1);
81
83
  }
84
+ function resolveCliBin() {
85
+ try {
86
+ return require2.resolve("@barefootjs/cli/dist/index.js");
87
+ } catch {
88
+ fail(
89
+ "unable to resolve @barefootjs/cli. Reinstall create-barefootjs or report this if it persists."
90
+ );
91
+ }
92
+ }
82
93
  async function main() {
83
94
  const args = process.argv.slice(2);
84
95
  if (args.includes("--help") || args.includes("-h")) usage();
96
+ if (args.includes("--list-adapters")) {
97
+ const cliBin2 = resolveCliBin();
98
+ const result2 = spawnSync("node", [cliBin2, "init", "--list-adapters"], {
99
+ stdio: "inherit",
100
+ env: { ...process.env, BAREFOOT_INIT_VIA_CREATE: "1" }
101
+ });
102
+ process.exit(result2.status ?? 1);
103
+ }
85
104
  console.log(dim(`create-barefootjs version ${CREATE_BAREFOOTJS_VERSION}`));
86
105
  console.log();
87
106
  const skipPrompts = args.includes("--yes") || args.includes("-y");
@@ -102,6 +121,7 @@ async function main() {
102
121
  }
103
122
  console.log(`\u2714 Target directory ${highlight(projectName)}`);
104
123
  const targetDir = resolve(process.cwd(), projectName);
124
+ let createdTargetDir = false;
105
125
  if (existsSync(targetDir)) {
106
126
  const entries = readdirSync(targetDir).filter((e) => !e.startsWith("."));
107
127
  if (entries.length > 0) {
@@ -109,15 +129,9 @@ async function main() {
109
129
  }
110
130
  } else {
111
131
  mkdirSync(targetDir, { recursive: true });
132
+ createdTargetDir = true;
112
133
  }
113
- let cliBin;
114
- try {
115
- cliBin = require2.resolve("@barefootjs/cli/dist/index.js");
116
- } catch {
117
- fail(
118
- "unable to resolve @barefootjs/cli. Reinstall create-barefootjs or report this if it persists."
119
- );
120
- }
134
+ const cliBin = resolveCliBin();
121
135
  const initArgs = ["--name", basename(projectName)];
122
136
  if (skipPrompts) {
123
137
  if (!passthrough.includes("--adapter")) initArgs.push("--adapter", DEFAULT_ADAPTER);
@@ -139,7 +153,16 @@ async function main() {
139
153
  BAREFOOT_INIT_VIA_CREATE: "1"
140
154
  }
141
155
  });
142
- process.exit(result.status ?? 1);
156
+ const status = result.status ?? 1;
157
+ if (status !== 0 && createdTargetDir) {
158
+ try {
159
+ if (existsSync(targetDir) && readdirSync(targetDir).length === 0) {
160
+ rmSync(targetDir, { recursive: true });
161
+ }
162
+ } catch {
163
+ }
164
+ }
165
+ process.exit(status);
143
166
  }
144
167
  main().catch((err) => {
145
168
  if (err && typeof err === "object" && "name" in err && err.name === "TextCancelled") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-barefootjs",
3
- "version": "0.17.1",
3
+ "version": "0.18.0",
4
4
  "description": "Scaffold a new BarefootJS app — `npm create barefootjs@latest <dir>`",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,7 +21,7 @@
21
21
  "postpack": "node ../../scripts/swap-publish-config.mjs unpack"
22
22
  },
23
23
  "dependencies": {
24
- "@barefootjs/cli": "0.17.1"
24
+ "@barefootjs/cli": "0.18.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "esbuild": "^0.25.0",