okforest 0.4.0 → 0.5.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/README.md
CHANGED
|
@@ -8,7 +8,7 @@ v0.2 trees.
|
|
|
8
8
|
npx okforest validate . # exit 1 on errors; warnings never fail
|
|
9
9
|
npx okforest validate . --format json # for CI and tools
|
|
10
10
|
npx okforest inventory . # types, tags, keys, near-duplicates
|
|
11
|
-
npx okforest init sales-okf --template company --
|
|
11
|
+
npx okforest init sales-okf --template company --name "Sales knowledge"
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
To also check D2 and Mermaid diagram syntax, install the optional packages
|
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
-
import { spawnSync } from "node:child_process";
|
|
4
3
|
import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
5
4
|
import { basename, join, resolve } from "node:path";
|
|
6
5
|
import { fileURLToPath } from "node:url";
|
|
@@ -52,7 +51,7 @@ function formatOption(value) {
|
|
|
52
51
|
}
|
|
53
52
|
//#endregion
|
|
54
53
|
//#region src/commands/init.ts
|
|
55
|
-
const HELP$3 = `Usage: okforest init [path] --template <name> [--
|
|
54
|
+
const HELP$3 = `Usage: okforest init [path] --template <name> [--name <name>]
|
|
56
55
|
|
|
57
56
|
Create a new OKF v0.2 tree at path (default: the current directory, which must
|
|
58
57
|
be empty apart from .git) from a starter template. Starter concepts are drafts
|
|
@@ -60,16 +59,13 @@ for you to fill in.
|
|
|
60
59
|
|
|
61
60
|
Options
|
|
62
61
|
--template <name> Starter template (available: company).
|
|
63
|
-
--
|
|
64
|
-
|
|
65
|
-
--title <title> Display title (default: "<Tree> knowledge").
|
|
62
|
+
--name <name> The bundle's name, up to 100 characters
|
|
63
|
+
(default: "<Folder> knowledge", without a -okf suffix).
|
|
66
64
|
`;
|
|
67
65
|
async function initCommand(args, io) {
|
|
68
66
|
const { values, path } = parseCommand(args, {
|
|
69
67
|
template: { type: "string" },
|
|
70
|
-
|
|
71
|
-
tree: { type: "string" },
|
|
72
|
-
title: { type: "string" }
|
|
68
|
+
name: { type: "string" }
|
|
73
69
|
});
|
|
74
70
|
if (values.help) {
|
|
75
71
|
io.stdout(HELP$3);
|
|
@@ -81,16 +77,12 @@ async function initCommand(args, io) {
|
|
|
81
77
|
const target = resolve(io.cwd, path);
|
|
82
78
|
const blocking = (await readdir(target).catch(() => [])).filter((name) => name !== ".git" && name !== ".DS_Store");
|
|
83
79
|
if (blocking.length > 0) throw new UsageError(`${path} is not empty (${blocking.slice(0, 3).join(", ")}${blocking.length > 3 ? ", ..." : ""}).`);
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
86
|
-
const tree = slug(typeof values.tree === "string" ? values.tree : basename(target).replace(/-okf$/, "")) || "company";
|
|
87
|
-
const title = typeof values.title === "string" && values.title.trim() !== "" ? values.title.trim() : `${capitalize(tree)} knowledge`;
|
|
80
|
+
const name = typeof values.name === "string" ? values.name.trim() : `${capitalize(slug(basename(target).replace(/-okf$/, "")) || "company")} knowledge`;
|
|
81
|
+
if (name === "" || [...name].length > 100) throw new UsageError(`--name must be 1 to 100 characters (got ${[...name].length.toLocaleString("en-US")}).`);
|
|
88
82
|
const now = /* @__PURE__ */ new Date();
|
|
89
83
|
const tokens = {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
title,
|
|
93
|
-
title_yaml: JSON.stringify(title),
|
|
84
|
+
name,
|
|
85
|
+
name_yaml: JSON.stringify(name),
|
|
94
86
|
version: VERSION,
|
|
95
87
|
date: now.toISOString().slice(0, 10),
|
|
96
88
|
now: `${now.toISOString().slice(0, 19)}Z`
|
|
@@ -99,7 +91,7 @@ async function initCommand(args, io) {
|
|
|
99
91
|
const where = path;
|
|
100
92
|
const drafts = written.filter((f) => f.endsWith(".md") && !/(^|\/)(index|log|README)\.md$/.test(f));
|
|
101
93
|
io.stdout(`Created a ${template} tree in ${where} (${written.length} files).\n\nNext steps
|
|
102
|
-
1. Review .okforest/
|
|
94
|
+
1. Review .okforest/settings.yaml (name: ${name}).\n 2. Fill in the draft concepts: ${drafts.join(", ")}.\n 3. Validate: npx okforest validate ${where}\n 4. Commit and push; the included workflow validates every pull request.
|
|
103
95
|
`);
|
|
104
96
|
return EXIT.ok;
|
|
105
97
|
}
|
|
@@ -127,15 +119,6 @@ async function copyTemplate(from, to, tokens) {
|
|
|
127
119
|
await walk("");
|
|
128
120
|
return written;
|
|
129
121
|
}
|
|
130
|
-
function gitEmail(target, cwd) {
|
|
131
|
-
for (const dir of [target, cwd]) {
|
|
132
|
-
const result = spawnSync("git", ["config", "user.email"], {
|
|
133
|
-
cwd: dir,
|
|
134
|
-
encoding: "utf8"
|
|
135
|
-
});
|
|
136
|
-
if (result.status === 0 && result.stdout.trim()) return result.stdout.trim();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
122
|
function slug(value) {
|
|
140
123
|
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
141
124
|
}
|
|
@@ -298,7 +281,7 @@ const HELP = `okforest ${VERSION}: validate, inventory, and scaffold Open Knowle
|
|
|
298
281
|
Usage
|
|
299
282
|
okforest validate [path] [--format text|json]
|
|
300
283
|
okforest inventory [path] [--format text|json]
|
|
301
|
-
okforest init [path] --template company [--
|
|
284
|
+
okforest init [path] --template company [--name <name>]
|
|
302
285
|
|
|
303
286
|
Commands
|
|
304
287
|
validate Check a tree against OKF v0.2 and OKForest conventions.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "okforest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "The OKForest CLI: validate Open Knowledge Format (OKF) v0.2 trees, inventory their metadata, and scaffold new trees from templates.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"okf",
|
|
@@ -32,15 +32,15 @@
|
|
|
32
32
|
"node": ">=22"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@okforest/okf": "0.
|
|
36
|
-
"@okforest/validate": "0.
|
|
35
|
+
"@okforest/okf": "0.5.0",
|
|
36
|
+
"@okforest/validate": "0.5.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^26.6.5",
|
|
40
|
-
"@vitest/coverage-v8": "^5.0.
|
|
40
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
41
41
|
"tsdown": "^0.23.0",
|
|
42
42
|
"typescript": "^7.0.2",
|
|
43
|
-
"vitest": "^5.0.
|
|
43
|
+
"vitest": "^5.0.5"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "tsdown",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# yaml-language-server: $schema=https://www.okforest.ai/schemas/settings.schema.json
|
|
2
|
+
# OKForest's settings for this bundle (an OKForest convention, not part of OKF).
|
|
3
|
+
# Every setting is optional: https://www.okforest.ai/docs/settings/
|
|
4
|
+
name: {{name_yaml}}
|
|
5
|
+
# description: What this bundle covers, in up to 4,000 characters.
|
|
6
|
+
# Markdown files that are not concepts; every other .md file is one.
|
|
7
|
+
ignore:
|
|
8
|
+
- README.md
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# {{
|
|
1
|
+
# {{name}}
|
|
2
2
|
|
|
3
3
|
An [Open Knowledge Format (OKF)](https://github.com/GoogleCloudPlatform/open-knowledge-format)
|
|
4
4
|
v0.2 tree: one markdown file per concept, with YAML frontmatter.
|
|
@@ -7,7 +7,8 @@ v0.2 tree: one markdown file per concept, with YAML frontmatter.
|
|
|
7
7
|
every other `.md` file is a concept.
|
|
8
8
|
- The starter concepts are drafts (`status: draft`): fill them in, then remove
|
|
9
9
|
the guidance comments.
|
|
10
|
-
-
|
|
10
|
+
- This README is not a concept: [`.okforest/settings.yaml`](.okforest/settings.yaml)
|
|
11
|
+
lists it under `ignore`.
|
|
11
12
|
- Validate with `npx okforest validate .`; the workflow in
|
|
12
13
|
`.github/workflows/okforest-validate.yml` runs it on every pull request.
|
|
13
14
|
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# yaml-language-server: $schema=https://www.okforest.ai/schemas/tree.schema.json
|
|
2
|
-
# OKForest settings for this tree (an OKForest convention, not part of OKF).
|
|
3
|
-
# Every setting: https://www.okforest.ai/docs/tree-settings/
|
|
4
|
-
tree: {{tree}}
|
|
5
|
-
title: {{title_yaml}}
|
|
6
|
-
owner: user:{{owner}} # exactly one person, accountable for the tree
|
|
7
|
-
# backup_owner: user:... # optional; acts for the Owner during absences
|
|
8
|
-
stewards: # review and approve changes; groups are recommended
|
|
9
|
-
- user: {{owner}}
|
|
10
|
-
sensitivity_default: internal
|
|
11
|
-
# Files that are not concepts, in addition to README.md, LICENSE.md,
|
|
12
|
-
# CONTRIBUTING.md, CHANGELOG.md, SECURITY.md, and CODE_OF_CONDUCT.md at the
|
|
13
|
-
# root. Globs are relative to the tree root.
|
|
14
|
-
# ignore:
|
|
15
|
-
# - FOLLOWUPS.md
|