create-venture 0.0.0-stage → 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/LICENSE +21 -0
- package/index.mjs +176 -0
- package/package.json +23 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Torian Johnson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/index.mjs
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// create-venture: Naive's generator, the way create-next-app is Next.js's (I-1, I-3, I-7). It asks for a
|
|
3
|
+
// name, offers the recommended defaults or lets you customize them, creates the venture in a new or
|
|
4
|
+
// empty directory, installs the framework with your package manager, and initializes git.
|
|
5
|
+
//
|
|
6
|
+
// npx create-venture [dir] [--yes] [--phase <phase>] [--layers a,b] [--legal-form <form>] [--dump <file>]
|
|
7
|
+
// [--use-npm | --use-pnpm | --use-yarn | --use-bun] [--skip-install] [--no-git]
|
|
8
|
+
// [--framework <spec>] [--reset-preferences]
|
|
9
|
+
//
|
|
10
|
+
// --yes takes the recommended defaults: the discovery phase, the phase's packages, checks on, and
|
|
11
|
+
// AGENTS.md. Answers to the setup questions are kept
|
|
12
|
+
// in ~/.config/naive/create-venture.json, so the next venture can reuse them.
|
|
13
|
+
|
|
14
|
+
import { spawnSync } from "node:child_process";
|
|
15
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { homedir } from "node:os";
|
|
17
|
+
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
18
|
+
import { createInterface } from "node:readline/promises";
|
|
19
|
+
import { fileURLToPath } from "node:url";
|
|
20
|
+
|
|
21
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
22
|
+
// The framework: the checkout this package sits in, or the installed naive-framework package.
|
|
23
|
+
const framework = (() => {
|
|
24
|
+
const checkout = resolve(here, "../..");
|
|
25
|
+
if (existsSync(join(checkout, "schema/init-venture.mjs"))) return checkout;
|
|
26
|
+
try { return dirname(fileURLToPath(import.meta.resolve("naive-framework/package.json"))); } catch { return null; }
|
|
27
|
+
})();
|
|
28
|
+
if (!framework) { console.error("create-venture could not find the Naive framework (naive-framework) to create the venture with"); process.exit(1); }
|
|
29
|
+
const fw = JSON.parse(readFileSync(join(framework, "package.json"), "utf8"));
|
|
30
|
+
const { layers: PHASE_LAYERS } = JSON.parse(readFileSync(join(framework, "schema/scaffold/defaults.json"), "utf8"));
|
|
31
|
+
const PHASES = Object.keys(PHASE_LAYERS);
|
|
32
|
+
const LAYERS = ["purpose", "knowledge", "operations", "evidence", "governance", "interface"];
|
|
33
|
+
|
|
34
|
+
const argv = process.argv.slice(2);
|
|
35
|
+
const opt = (n) => { const i = argv.indexOf(`--${n}`); return i >= 0 ? argv[i + 1] : undefined; };
|
|
36
|
+
const flag = (n) => argv.includes(`--${n}`);
|
|
37
|
+
const valued = new Set(["phase", "layers", "legal-form", "dump", "framework"]);
|
|
38
|
+
const positional = argv.filter((a, i) => !a.startsWith("--") && !(i > 0 && valued.has(argv[i - 1].slice(2))));
|
|
39
|
+
const bold = (s) => (process.stdout.isTTY ? `\x1b[1m${s}\x1b[22m` : s);
|
|
40
|
+
const cyan = (s) => (process.stdout.isTTY ? `\x1b[36m${s}\x1b[39m` : s);
|
|
41
|
+
const fail = (m) => { console.error(m); process.exit(1); };
|
|
42
|
+
const slug = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
43
|
+
|
|
44
|
+
// Preferences, so a second venture can reuse the first one's answers (create-next-app's "reuse previous settings").
|
|
45
|
+
const prefsFile = join(process.env.XDG_CONFIG_HOME ?? join(homedir(), ".config"), "naive", "create-venture.json");
|
|
46
|
+
if (flag("reset-preferences")) { rmSync(prefsFile, { force: true }); console.log("Preferences reset."); if (!positional.length) process.exit(0); }
|
|
47
|
+
const prefs = (() => { try { return JSON.parse(readFileSync(prefsFile, "utf8")); } catch { return null; } })();
|
|
48
|
+
|
|
49
|
+
// CREATE_VENTURE_PROMPTS=1 asks the questions with piped input, so tests can answer them.
|
|
50
|
+
const interactive = ((process.stdin.isTTY && process.stdout.isTTY) || process.env.CREATE_VENTURE_PROMPTS === "1") && !flag("yes");
|
|
51
|
+
// At a terminal, readline asks; with piped answers (CREATE_VENTURE_PROMPTS=1), each line answers the next question.
|
|
52
|
+
const piped = interactive && !process.stdin.isTTY ? readFileSync(0, "utf8").split("\n") : null;
|
|
53
|
+
const rl = interactive && !piped ? createInterface({ input: process.stdin, output: process.stdout }) : null;
|
|
54
|
+
const ask = async (q, fallback) => {
|
|
55
|
+
const prompt = `${cyan("?")} ${bold(q)} ${fallback ? `(${fallback}) ` : ""}`;
|
|
56
|
+
const a = piped ? (process.stdout.write(prompt + "\n"), (piped.shift() ?? "")) : await rl.question(prompt);
|
|
57
|
+
return a.trim() || fallback;
|
|
58
|
+
};
|
|
59
|
+
const choose = async (q, options, fallback) => {
|
|
60
|
+
const a = await ask(`${q} ${options.join(" / ")}`, fallback);
|
|
61
|
+
if (!options.includes(a)) { console.log(` choose one of: ${options.join(", ")}`); if (piped && !piped.length) fail("no answer left to choose with"); return choose(q, options, fallback); }
|
|
62
|
+
return a;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// 1. The name and the directory.
|
|
66
|
+
let target = positional[0];
|
|
67
|
+
if (!target) {
|
|
68
|
+
if (!interactive) fail("usage: create-venture <dir> [--yes]: name the directory for the new venture");
|
|
69
|
+
target = await ask("What is your venture named?", "my-venture");
|
|
70
|
+
}
|
|
71
|
+
const dir = resolve(target);
|
|
72
|
+
const id = slug(basename(dir));
|
|
73
|
+
if (!id) fail(`${basename(dir)} has no letters or digits to make a venture id from`);
|
|
74
|
+
if (existsSync(dir) && readdirSync(dir).length) fail(`${dir} already exists and is not empty. create-venture only creates new ventures; to bring an existing project in, create one here and run naive port or naive migrate.`);
|
|
75
|
+
|
|
76
|
+
// 2. Defaults, the last venture's answers, or your own (I-3, I-7).
|
|
77
|
+
const recommended = { phase: "discovery", layers: null, legalForm: null, dump: null };
|
|
78
|
+
let answers = { ...recommended };
|
|
79
|
+
const given = opt("phase") || opt("layers") || opt("legal-form") || opt("dump");
|
|
80
|
+
if (given) answers = { phase: opt("phase") ?? "discovery", layers: opt("layers") ?? null, legalForm: opt("legal-form") ?? null, dump: opt("dump") ?? null };
|
|
81
|
+
else if (interactive) {
|
|
82
|
+
const modes = prefs ? ["recommended", "previous", "customize"] : ["recommended", "customize"];
|
|
83
|
+
const mode = await choose("Would you like to use the recommended Naive defaults?", modes, "recommended");
|
|
84
|
+
if (mode === "previous") answers = { ...recommended, ...prefs };
|
|
85
|
+
if (mode === "customize") {
|
|
86
|
+
answers.phase = await choose("Which phase is the venture in?", PHASES, "discovery");
|
|
87
|
+
const l = await ask(`Which layers should be on? (comma separated, from ${LAYERS.join(", ")}; empty for the phase's defaults: ${PHASE_LAYERS[answers.phase].join(", ")})`, "");
|
|
88
|
+
answers.layers = l || null;
|
|
89
|
+
const f = await choose("Is the venture a legal entity yet?", ["none", "llc", "corporation", "partnership", "nonprofit"], "none");
|
|
90
|
+
answers.legalForm = f === "none" ? null : f;
|
|
91
|
+
const d = await ask("Paste the path of an idea dump to start from (optional)", "");
|
|
92
|
+
answers.dump = d || null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (!PHASES.includes(answers.phase)) fail(`unknown phase ${answers.phase}: one of ${PHASES.join(", ")}`);
|
|
96
|
+
if (answers.dump && !existsSync(resolve(answers.dump))) fail(`no idea dump at ${answers.dump}`);
|
|
97
|
+
|
|
98
|
+
// 3. The package manager: the flag, else whichever ran this (npm_config_user_agent), else npm.
|
|
99
|
+
const pm = ["npm", "pnpm", "yarn", "bun"].find((p) => flag(`use-${p}`)) ?? (process.env.npm_config_user_agent ?? "").split("/")[0].replace(/^npx$/, "npm") ?? "npm";
|
|
100
|
+
const manager = ["npm", "pnpm", "yarn", "bun"].includes(pm) ? pm : "npm";
|
|
101
|
+
rl?.close();
|
|
102
|
+
|
|
103
|
+
// 4. The venture itself, by the framework's own scaffold.
|
|
104
|
+
console.log(`\nCreating a new Naive venture in ${bold(dir)}.\n`);
|
|
105
|
+
const init = spawnSync("node", [join(framework, "schema/init-venture.mjs"), dir, id, "--phase", answers.phase,
|
|
106
|
+
...(answers.layers ? ["--layers", answers.layers] : []), ...(answers.legalForm ? ["--legal-form", answers.legalForm] : [])], { encoding: "utf8" });
|
|
107
|
+
if (init.status !== 0) fail((init.stderr || init.stdout).trim());
|
|
108
|
+
const vfile = join(dir, "venture.json");
|
|
109
|
+
const venture = JSON.parse(readFileSync(vfile, "utf8"));
|
|
110
|
+
venture.name = basename(dir);
|
|
111
|
+
writeFileSync(vfile, JSON.stringify(venture, null, 2) + "\n");
|
|
112
|
+
|
|
113
|
+
const { agentFromEnv, record } = await import(join(framework, "interface/provenance.mjs"));
|
|
114
|
+
if (answers.dump) {
|
|
115
|
+
mkdirSync(join(dir, "raw"), { recursive: true });
|
|
116
|
+
copyFileSync(resolve(answers.dump), join(dir, "raw/dump.md"));
|
|
117
|
+
record(dir, { entity: "raw/dump.md", route: "raw/dump", activity: "create", agent: agentFromEnv("person", "create-venture"), note: `the founder's idea dump, verbatim, from ${resolve(answers.dump)}` });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// The venture's package.json: the framework as a dev dependency and the four scripts (I-17).
|
|
121
|
+
const fromClone = existsSync(join(framework, "test.mjs")) && !framework.split("/").includes("node_modules");
|
|
122
|
+
const spec = opt("framework") ?? (fromClone ? `file:${framework}` : `${fw.name}@^${fw.version}`);
|
|
123
|
+
writeFileSync(join(dir, "package.json"), JSON.stringify({
|
|
124
|
+
name: id, private: true, type: "module",
|
|
125
|
+
scripts: { dev: "naive dev", build: "naive build", start: "naive start", check: "naive check" },
|
|
126
|
+
devDependencies: { [fw.name]: spec },
|
|
127
|
+
}, null, 2) + "\n");
|
|
128
|
+
writeFileSync(join(dir, ".gitignore"), "node_modules/\n.naive/\n.DS_Store\n# Founder-supplied originals stay out of git (EE-070).\n**/raw/**/original.*\n");
|
|
129
|
+
|
|
130
|
+
// Editor completion for records (I-26): every record file is mapped to its JSON Schema in the installed framework.
|
|
131
|
+
const { routes } = await import(join(framework, "interface/router.mjs"));
|
|
132
|
+
const schemas = new Map();
|
|
133
|
+
for (const r of routes()) if (r.kind === "record" && r.schema && r.form !== "md") for (const f of r.files ?? []) if (f.endsWith(".json")) schemas.set(r.schema, [...(schemas.get(r.schema) ?? []), `/${f}`]);
|
|
134
|
+
mkdirSync(join(dir, ".vscode"), { recursive: true });
|
|
135
|
+
writeFileSync(join(dir, ".vscode/settings.json"), JSON.stringify({
|
|
136
|
+
"json.schemas": [...schemas].map(([schema, fileMatch]) => ({ fileMatch: [...new Set(fileMatch)], url: `./node_modules/${fw.name}/${schema}` })),
|
|
137
|
+
}, null, 2) + "\n");
|
|
138
|
+
|
|
139
|
+
// 5. Install, then git, as create-next-app does.
|
|
140
|
+
if (!flag("skip-install")) {
|
|
141
|
+
console.log(`Installing the framework with ${manager}:\n- ${fw.name}\n`);
|
|
142
|
+
const r = spawnSync(manager, ["install"], { cwd: dir, stdio: "inherit" });
|
|
143
|
+
if (r.status !== 0) fail(`${manager} install failed in ${dir}. Fix the error above, then run ${manager} install there.`);
|
|
144
|
+
}
|
|
145
|
+
let git = "skipped (--no-git)";
|
|
146
|
+
if (!flag("no-git") && spawnSync("git", ["--version"]).status === 0 && spawnSync("git", ["rev-parse", "--is-inside-work-tree"], { cwd: dirname(dir) }).status !== 0) {
|
|
147
|
+
spawnSync("git", ["init", "-q"], { cwd: dir });
|
|
148
|
+
spawnSync("git", ["add", "-A"], { cwd: dir });
|
|
149
|
+
const c = spawnSync("git", ["commit", "-q", "-m", "Initial commit from create-venture"], { cwd: dir, encoding: "utf8" });
|
|
150
|
+
git = c.status === 0 ? "initialized, with a first commit" : "initialized; the first commit was skipped because git has no user.name and user.email";
|
|
151
|
+
} else if (!flag("no-git")) git = "skipped (already inside a git repository)";
|
|
152
|
+
|
|
153
|
+
try { mkdirSync(dirname(prefsFile), { recursive: true }); writeFileSync(prefsFile, JSON.stringify({ phase: answers.phase, layers: answers.layers, legalForm: answers.legalForm }, null, 2) + "\n"); } catch {}
|
|
154
|
+
|
|
155
|
+
const runScript = (s) => (manager === "npm" ? `npm run ${s}` : `${manager} ${s}`);
|
|
156
|
+
const cd = relative(process.cwd(), dir) || ".";
|
|
157
|
+
console.log(`
|
|
158
|
+
${bold("Success!")} Created ${basename(dir)} at ${dir}
|
|
159
|
+
Git: ${git}
|
|
160
|
+
|
|
161
|
+
Inside that directory, you can run:
|
|
162
|
+
|
|
163
|
+
${cyan(runScript("dev"))}
|
|
164
|
+
Opens the board at http://127.0.0.1:4331 and checks each record as you save it.
|
|
165
|
+
|
|
166
|
+
${cyan(runScript("check"))}
|
|
167
|
+
Runs every check that applies to the venture.
|
|
168
|
+
|
|
169
|
+
${cyan(runScript("build"))}
|
|
170
|
+
Checks every package and writes a release.
|
|
171
|
+
|
|
172
|
+
We suggest that you begin by typing:
|
|
173
|
+
|
|
174
|
+
${cyan(`cd ${cd}`)}
|
|
175
|
+
${cyan(runScript("dev"))}
|
|
176
|
+
`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-venture",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Create a new Naive venture: npx create-venture my-venture",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/tchjhnsn/everything-ecosystem.git",
|
|
10
|
+
"directory": "interface/create-venture"
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=20"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"create-venture": "index.mjs"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"index.mjs",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"naive-framework": "^0.1.0"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/README.md
DELETED