create-nowaki 0.9.1 → 0.10.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/index.js +140 -14
- package/package.json +1 -1
- package/template/README.md +36 -0
- package/template/_gitignore +12 -0
- package/template/nowaki-env.d.ts +42 -0
- package/template/package.json +1 -1
- package/template/tsconfig.json +33 -0
package/index.js
CHANGED
|
@@ -1,31 +1,157 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
// `npm create nowaki` のスキャフォールダ。依存ゼロ(Node 組み込みのみ)。
|
|
3
|
+
// 対話ウィザード(TTY 時): プロジェクト名・パッケージマネージャ・git・依存インストール。
|
|
4
|
+
// 非対話(CI / `-y` / パイプ)では既定値で黙って生成する。
|
|
5
|
+
//
|
|
6
|
+
// フラグ: -y/--yes(質問を飛ばす), --install(非対話でも入れる), --no-install,
|
|
7
|
+
// --no-git, --pm <npm|pnpm|yarn|bun>
|
|
8
|
+
|
|
9
|
+
import { cp, mkdir, readdir, readFile, writeFile, rename } from "node:fs/promises";
|
|
3
10
|
import path from "node:path";
|
|
4
11
|
import { fileURLToPath } from "node:url";
|
|
12
|
+
import { createInterface } from "node:readline/promises";
|
|
13
|
+
import { execFileSync } from "node:child_process";
|
|
14
|
+
import process from "node:process";
|
|
15
|
+
|
|
16
|
+
const { stdin, stdout, env, argv, platform } = process;
|
|
17
|
+
|
|
18
|
+
// --- 色(NO_COLOR と非 TTY を尊重)---
|
|
19
|
+
const useColor = !!stdout.isTTY && !env.NO_COLOR;
|
|
20
|
+
const wrap = (code) => (s) => (useColor ? `\x1b[${code}m${s}\x1b[0m` : `${s}`);
|
|
21
|
+
const cyan = wrap("36");
|
|
22
|
+
const dim = wrap("2");
|
|
23
|
+
const bold = wrap("1");
|
|
24
|
+
const green = wrap("32");
|
|
25
|
+
const red = wrap("31");
|
|
26
|
+
const yellow = wrap("33");
|
|
27
|
+
|
|
28
|
+
// --- 引数 ---
|
|
29
|
+
const args = argv.slice(2);
|
|
30
|
+
const flags = new Set(args.filter((a) => a.startsWith("-")));
|
|
31
|
+
const positionals = args.filter((a) => !a.startsWith("-"));
|
|
32
|
+
const pmFlag = (() => {
|
|
33
|
+
const i = args.indexOf("--pm");
|
|
34
|
+
return i >= 0 ? args[i + 1] : null;
|
|
35
|
+
})();
|
|
36
|
+
const yes = flags.has("-y") || flags.has("--yes");
|
|
37
|
+
const noInstall = flags.has("--no-install");
|
|
38
|
+
const forceInstall = flags.has("--install");
|
|
39
|
+
const noGit = flags.has("--no-git");
|
|
40
|
+
const interactive = !!stdin.isTTY && !!stdout.isTTY && !yes;
|
|
41
|
+
|
|
42
|
+
const templateDir = path.join(path.dirname(fileURLToPath(import.meta.url)), "template");
|
|
43
|
+
|
|
44
|
+
// --- パッケージマネージャ検出(`npm create` の user-agent から)---
|
|
45
|
+
function detectPM() {
|
|
46
|
+
const ua = env.npm_config_user_agent || "";
|
|
47
|
+
if (ua.startsWith("pnpm")) return "pnpm";
|
|
48
|
+
if (ua.startsWith("yarn")) return "yarn";
|
|
49
|
+
if (ua.startsWith("bun")) return "bun";
|
|
50
|
+
return "npm";
|
|
51
|
+
}
|
|
5
52
|
|
|
6
|
-
|
|
53
|
+
// --- バナー ---
|
|
54
|
+
console.log();
|
|
55
|
+
console.log(` ${cyan(bold("Nowaki"))} ${dim("野分")} ${dim("· create a new app")}`);
|
|
56
|
+
console.log();
|
|
57
|
+
|
|
58
|
+
const rl = interactive ? createInterface({ input: stdin, output: stdout }) : null;
|
|
59
|
+
async function ask(question, def) {
|
|
60
|
+
if (!rl) return def;
|
|
61
|
+
const a = (await rl.question(` ${question} ${dim(`(${def})`)} `)).trim();
|
|
62
|
+
return a || def;
|
|
63
|
+
}
|
|
64
|
+
async function confirm(question, def = true) {
|
|
65
|
+
if (!rl) return def;
|
|
66
|
+
const a = (await rl.question(` ${question} ${dim(def ? "(Y/n)" : "(y/N)")} `)).trim().toLowerCase();
|
|
67
|
+
if (!a) return def;
|
|
68
|
+
return a === "y" || a === "yes";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// --- 質問 ---
|
|
72
|
+
let name = positionals[0] || (await ask("Project name?", interactive ? "my-app" : "nowaki-app"));
|
|
73
|
+
name = name.trim() || "nowaki-app";
|
|
74
|
+
// package.json の name は valid な npm 名に正規化(ディレクトリ名は入力のまま)
|
|
75
|
+
const pkgName = name.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[._-]+/, "") || "nowaki-app";
|
|
7
76
|
const dest = path.resolve(process.cwd(), name);
|
|
8
|
-
const templateDir = path.join(
|
|
9
|
-
path.dirname(fileURLToPath(import.meta.url)),
|
|
10
|
-
"template",
|
|
11
|
-
);
|
|
12
77
|
|
|
13
|
-
//
|
|
78
|
+
// 既存の空でないディレクトリは中止
|
|
14
79
|
try {
|
|
15
80
|
const existing = await readdir(dest);
|
|
16
81
|
if (existing.length > 0) {
|
|
17
|
-
console.error(
|
|
82
|
+
console.error(`\n ${red("✗")} "${name}" already exists and is not empty. Aborting.\n`);
|
|
83
|
+
rl?.close();
|
|
18
84
|
process.exit(1);
|
|
19
85
|
}
|
|
20
86
|
} catch {
|
|
21
|
-
//
|
|
87
|
+
// 無ければOK
|
|
22
88
|
}
|
|
23
89
|
|
|
90
|
+
let pm = pmFlag || detectPM();
|
|
91
|
+
if (interactive && !pmFlag) pm = (await ask("Package manager?", pm)).trim() || pm;
|
|
92
|
+
if (!["npm", "pnpm", "yarn", "bun"].includes(pm)) pm = "npm";
|
|
93
|
+
const doGit = noGit ? false : await confirm("Initialize a git repository?", false);
|
|
94
|
+
// 依存インストール: 対話なら確認(既定 Yes)。非対話(-y / CI / パイプ)は自動実行しない
|
|
95
|
+
//(驚き防止)。非対話で入れたいときは --install。--no-install は常にスキップ。
|
|
96
|
+
const doInstall = noInstall
|
|
97
|
+
? false
|
|
98
|
+
: forceInstall
|
|
99
|
+
? true
|
|
100
|
+
: interactive
|
|
101
|
+
? await confirm(`Install dependencies with ${pm}?`, true)
|
|
102
|
+
: false;
|
|
103
|
+
rl?.close();
|
|
104
|
+
|
|
105
|
+
// --- 生成 ---
|
|
24
106
|
await mkdir(dest, { recursive: true });
|
|
25
107
|
await cp(templateDir, dest, { recursive: true });
|
|
26
108
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
109
|
+
// npm は公開時に .gitignore を除外するので、テンプレートでは _gitignore で持ち、ここで戻す。
|
|
110
|
+
try {
|
|
111
|
+
await rename(path.join(dest, "_gitignore"), path.join(dest, ".gitignore"));
|
|
112
|
+
} catch {
|
|
113
|
+
// _gitignore が無ければ素通し
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// package.json の name を設定
|
|
117
|
+
try {
|
|
118
|
+
const pkgPath = path.join(dest, "package.json");
|
|
119
|
+
const pkg = JSON.parse(await readFile(pkgPath, "utf8"));
|
|
120
|
+
pkg.name = pkgName;
|
|
121
|
+
await writeFile(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
122
|
+
} catch {
|
|
123
|
+
// package.json が無ければ素通し
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
console.log(`\n ${green("✓")} created ${bold(name)} ${dim(`(${path.relative(process.cwd(), dest) || "."})`)}`);
|
|
127
|
+
|
|
128
|
+
// git init(任意)
|
|
129
|
+
if (doGit) {
|
|
130
|
+
try {
|
|
131
|
+
execFileSync("git", ["init", "-q"], { cwd: dest, stdio: "ignore" });
|
|
132
|
+
console.log(` ${green("✓")} initialized a git repository`);
|
|
133
|
+
} catch {
|
|
134
|
+
console.log(` ${yellow("!")} skipped git init (git not found)`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 依存インストール(任意)
|
|
139
|
+
let installed = false;
|
|
140
|
+
if (doInstall) {
|
|
141
|
+
console.log(`\n ${dim(`installing dependencies with ${pm}…`)}\n`);
|
|
142
|
+
try {
|
|
143
|
+
execFileSync(pm, ["install"], { cwd: dest, stdio: "inherit", shell: platform === "win32" });
|
|
144
|
+
installed = true;
|
|
145
|
+
console.log(`\n ${green("✓")} dependencies installed`);
|
|
146
|
+
} catch {
|
|
147
|
+
console.log(`\n ${red("✗")} \`${pm} install\` failed — run it yourself after \`cd ${name}\`.`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// --- 次のステップ ---
|
|
152
|
+
const runDev = pm === "npm" || pm === "bun" ? `${pm} run dev` : `${pm} dev`;
|
|
153
|
+
console.log(`\n ${bold("Next steps:")}`);
|
|
154
|
+
console.log(` cd ${name}`);
|
|
155
|
+
if (!installed) console.log(` ${pm} install`);
|
|
156
|
+
console.log(` ${cyan(runDev)} ${dim("# → http://localhost:3000")}`);
|
|
157
|
+
console.log(`\n ${dim("Docs:")} ${cyan("https://nowaki.dev/docs")}\n`);
|
package/package.json
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Nowaki app
|
|
2
|
+
|
|
3
|
+
A full-stack app built with [Nowaki](https://nowaki.dev) — full-stack like
|
|
4
|
+
Next.js, islands like Astro, on a Rust toolchain. Pages render to HTML; only the
|
|
5
|
+
components under `islands/` ship JavaScript and hydrate.
|
|
6
|
+
|
|
7
|
+
## Develop
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install
|
|
11
|
+
npm run dev # http://localhost:3000
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Other scripts: `npm run build`, `npm run start`, `npm run prerender`.
|
|
15
|
+
Pass `--host` to expose dev on your LAN, `--open` to open the browser:
|
|
16
|
+
`npm run dev -- --host --open`.
|
|
17
|
+
|
|
18
|
+
## Structure
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
routes/ pages + API (file-based). _layout.tsx, _middleware.ts, [slug].tsx, api/*.ts
|
|
22
|
+
islands/ interactive components — the only things that ship JS
|
|
23
|
+
components/ shared server components (no client JS)
|
|
24
|
+
lib/ shared server code
|
|
25
|
+
actions/ "use server" RPC modules (optional)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Notes
|
|
29
|
+
|
|
30
|
+
- Write **Preact** — import hooks from `preact/hooks`. (`react` is aliased to
|
|
31
|
+
`preact/compat`, so many React libraries work.)
|
|
32
|
+
- Use **explicit file extensions** in relative imports: `../islands/Counter.tsx`.
|
|
33
|
+
- A route's `loader` runs only on the server; `action` handles non-GET requests.
|
|
34
|
+
- `AGENTS.md` documents the conventions for AI coding agents.
|
|
35
|
+
|
|
36
|
+
Docs: <https://nowaki.dev/docs>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Nowaki アンビエント型。CSS / アセット / 仮想モジュールの import をエディタが理解できるように。
|
|
2
|
+
// 編集不要(フレームワークの import 規約を型に伝えるだけ)。
|
|
3
|
+
|
|
4
|
+
declare module "*.module.css" {
|
|
5
|
+
const classes: Record<string, string>;
|
|
6
|
+
export default classes;
|
|
7
|
+
}
|
|
8
|
+
declare module "*.css" {
|
|
9
|
+
const css: string;
|
|
10
|
+
export default css;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// アセット import は配信 URL(文字列)になる。
|
|
14
|
+
declare module "*.svg" { const url: string; export default url; }
|
|
15
|
+
declare module "*.png" { const url: string; export default url; }
|
|
16
|
+
declare module "*.jpg" { const url: string; export default url; }
|
|
17
|
+
declare module "*.jpeg" { const url: string; export default url; }
|
|
18
|
+
declare module "*.gif" { const url: string; export default url; }
|
|
19
|
+
declare module "*.webp" { const url: string; export default url; }
|
|
20
|
+
declare module "*.avif" { const url: string; export default url; }
|
|
21
|
+
declare module "*.ico" { const url: string; export default url; }
|
|
22
|
+
declare module "*.woff" { const url: string; export default url; }
|
|
23
|
+
declare module "*.woff2" { const url: string; export default url; }
|
|
24
|
+
declare module "*.ttf" { const url: string; export default url; }
|
|
25
|
+
declare module "*.otf" { const url: string; export default url; }
|
|
26
|
+
declare module "*.mp4" { const url: string; export default url; }
|
|
27
|
+
declare module "*.webm" { const url: string; export default url; }
|
|
28
|
+
declare module "*.mp3" { const url: string; export default url; }
|
|
29
|
+
declare module "*.wav" { const url: string; export default url; }
|
|
30
|
+
declare module "*.pdf" { const url: string; export default url; }
|
|
31
|
+
|
|
32
|
+
// プラグインの仮想モジュール(nowaki.config の resolveId/load)。任意の export を許す。
|
|
33
|
+
declare module "virtual:*";
|
|
34
|
+
|
|
35
|
+
// import.meta.env(PUBLIC_* と MODE がビルド時に inline される)。
|
|
36
|
+
interface ImportMetaEnv {
|
|
37
|
+
readonly MODE: string;
|
|
38
|
+
readonly [key: `PUBLIC_${string}`]: string | undefined;
|
|
39
|
+
}
|
|
40
|
+
interface ImportMeta {
|
|
41
|
+
readonly env: ImportMetaEnv;
|
|
42
|
+
}
|
package/template/package.json
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"allowImportingTsExtensions": true,
|
|
7
|
+
"verbatimModuleSyntax": false,
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
|
15
|
+
"jsx": "react-jsx",
|
|
16
|
+
"jsxImportSource": "preact",
|
|
17
|
+
"types": [],
|
|
18
|
+
"paths": {
|
|
19
|
+
"react": ["./node_modules/preact/compat"],
|
|
20
|
+
"react-dom": ["./node_modules/preact/compat"],
|
|
21
|
+
"react/jsx-runtime": ["./node_modules/preact/jsx-runtime"]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"include": [
|
|
25
|
+
"nowaki-env.d.ts",
|
|
26
|
+
"nowaki.config.*",
|
|
27
|
+
"routes",
|
|
28
|
+
"islands",
|
|
29
|
+
"components",
|
|
30
|
+
"lib",
|
|
31
|
+
"actions"
|
|
32
|
+
]
|
|
33
|
+
}
|