diff --git a/.changeset/38483-scaffold-names-articles.md b/.changeset/38483-scaffold-names-articles.md new file mode 100644 index 00000000000..7939dfa9c36 --- /dev/null +++ b/.changeset/38483-scaffold-names-articles.md @@ -0,0 +1,11 @@ +--- +'create-objectstack': patch +'@objectstack/example-starter': patch +--- + +fix(create-objectstack, example-starter): the scaffold summary and the descriptions name the help articles + +Clause-②: no +Metadata-protocol: none + +`npm create objectstack` now lists the help articles in the "Your project starts with:" block it prints after creating a project: an Articles line beside Companies and Contacts, pointing at `src/objects/` and `src/views/` and at the sample articles in `src/data/`. The `Template: blank — …` line it prints first, the template table in this package's README, the blank template's description in `objectstack.config.ts` and in `objectstack.manifest.json`, and the Starter's package description (in English and in Simplified Chinese), its app description (in English and in Simplified Chinese) and its `package.json` description now read companies, contacts and help articles, with tasks and notes from the platform in the menu. A scaffolded project still drops the template's description from its own files. diff --git a/content/docs/getting-started/build-with-claude-code.mdx b/content/docs/getting-started/build-with-claude-code.mdx index 5e8bde2e429..7cfc2ee7e8e 100644 --- a/content/docs/getting-started/build-with-claude-code.mdx +++ b/content/docs/getting-started/build-with-claude-code.mdx @@ -79,7 +79,7 @@ The scaffolder does more than copy files. It: ──────────────────────────────────────── Environment: support-desk Namespace: support_desk - Template: blank — Companies and contacts, with platform tasks and notes in the menu — ready to extend + Template: blank — Companies, contacts and help articles, with tasks and notes from the platform in the menu — ready to extend … → Installing AI skills for your coding agent from @objectstack/skills@... … diff --git a/content/docs/getting-started/your-first-project.mdx b/content/docs/getting-started/your-first-project.mdx index 1f2cf294ea5..5ae784f09f6 100644 --- a/content/docs/getting-started/your-first-project.mdx +++ b/content/docs/getting-started/your-first-project.mdx @@ -83,7 +83,7 @@ bundle) with `--skip-skills` if you prefer — `AGENTS.md` is always written. | Template | Source | Description | |:---|:---|:---| -| `blank` *(default)* | bundled, works offline | Companies and contacts, with platform tasks and notes in the menu — ready to extend | +| `blank` *(default)* | bundled, works offline | Companies, contacts and help articles, with tasks and notes from the platform in the menu — ready to extend | ```bash npm create objectstack@latest my-app -- --template blank diff --git a/examples/app-starter/objectstack.config.ts b/examples/app-starter/objectstack.config.ts index ce00c48d4ea..10718aa1362 100644 --- a/examples/app-starter/objectstack.config.ts +++ b/examples/app-starter/objectstack.config.ts @@ -28,7 +28,7 @@ export default defineStack({ version: '0.1.0', type: 'app', name: 'Starter', - description: 'Companies and contacts, with the platform\'s tasks and notes in the menu.', + description: 'Companies, contacts and help articles, with the platform\'s tasks and notes in the menu.', // Protocol major this package is authored against (ADR-0087). engines: { protocol: '^19' }, // A starter is taken over by the organization that installs it: an diff --git a/examples/app-starter/package.json b/examples/app-starter/package.json index abc31f02b34..a2f32b952f5 100644 --- a/examples/app-starter/package.json +++ b/examples/app-starter/package.json @@ -1,7 +1,7 @@ { "name": "@objectstack/example-starter", "version": "0.1.1-next.2", - "description": "Starter app: companies and their contacts, with the platform's tasks and notes in the menu", + "description": "Starter app: companies, contacts and help articles, with the platform's tasks and notes in the menu", "license": "Apache-2.0", "private": true, "main": "./objectstack.config.ts", diff --git a/examples/app-starter/src/translations/starter.translation.ts b/examples/app-starter/src/translations/starter.translation.ts index d56bebc1843..097cf689bb2 100644 --- a/examples/app-starter/src/translations/starter.translation.ts +++ b/examples/app-starter/src/translations/starter.translation.ts @@ -54,7 +54,7 @@ export const StarterTranslationBundle = defineTranslationBundle({ apps: { biz_app: { label: 'Starter', - description: 'Companies and contacts, with tasks and notes', + description: 'Companies, contacts and help articles, with tasks and notes', }, }, }, @@ -62,7 +62,7 @@ export const StarterTranslationBundle = defineTranslationBundle({ 'zh-CN': { // The package's own name, keyed by its manifest id (objectstack#35513). packages: { - 'com.example.starter': { name: '入门示例', description: '公司与联系人,菜单中附带平台的任务和备注。' }, + 'com.example.starter': { name: '入门示例', description: '公司、联系人与知识文章,菜单中附带平台的任务和备注。' }, }, objects: { biz_company: { @@ -176,7 +176,7 @@ export const StarterTranslationBundle = defineTranslationBundle({ apps: { biz_app: { label: '起步应用', - description: '公司和联系人,以及任务和备忘', + description: '公司、联系人与知识文章,菜单中附带平台的任务和备注。', }, }, datasets: { diff --git a/packages/create-objectstack/README.md b/packages/create-objectstack/README.md index f16311575f3..600ce052950 100644 --- a/packages/create-objectstack/README.md +++ b/packages/create-objectstack/README.md @@ -28,7 +28,7 @@ npx create-objectstack my-app --skip-install | Template | Source | Description | | --- | --- | --- | -| `blank` *(default)* | bundled (offline) | Companies and contacts, with platform tasks and notes in the menu — ready to extend | +| `blank` *(default)* | bundled (offline) | Companies, contacts and help articles, with tasks and notes from the platform in the menu — ready to extend | `blank` is bundled inside the npm package, so scaffolding never needs network access. diff --git a/packages/create-objectstack/src/index.ts b/packages/create-objectstack/src/index.ts index 50a2ea22552..5163e677023 100644 --- a/packages/create-objectstack/src/index.ts +++ b/packages/create-objectstack/src/index.ts @@ -31,8 +31,8 @@ * * The template's own `manifest.description` is DROPPED from both * objectstack.manifest.json and objectstack.config.ts rather than carried - * over unrewritten (#9263): it describes the bundled template ("Companies - * and contacts, with tasks and notes from the platform in the menu."), not the project + * over unrewritten (#9263): it describes the bundled template ("Companies, + * contacts and help articles, with tasks and notes from the platform in the menu."), not the project * being scaffolded, and there is nothing but the project name to derive a * replacement from — which would only restate `name`/`displayName`. `os * validate` already omits the description line entirely when the field is @@ -194,7 +194,7 @@ function rewriteProjectIdentity( // file refuses each, and publish refuses `category` and `visibility` — the // list is RETIRED_TEMPLATE_MANIFEST_KEYS in rewrite-identity.ts), and DROP // .description (#9263). The template ships a generic line describing - // ITSELF ("Companies and contacts, with tasks and notes from the platform in the menu."), + // ITSELF ("Companies, contacts and help articles, with tasks and notes from the platform in the menu."), // not the project being scaffolded, and there is nothing but the project // name to derive a replacement from — a name-derived sentence would be a // bare restatement of `name`/`displayName` (e.g. "Support Desk — an @@ -678,12 +678,16 @@ const program = new Command() console.log(''); // What the project holds on day one, so the first `dev` run is not a - // surprise: the bundled template's companies and contacts (the - // platform's Starter app, as source), and the platform's tasks and notes - // in its menu. `blank-template-starter-parity.test.ts` holds these lines - // to the template's tree. + // surprise: the bundled template's companies, contacts and help articles + // (the platform's Starter app, as source) with the sample articles it + // seeds, and the platform's tasks and notes in its menu. + // `blank-template-starter-parity.test.ts` holds these lines to the + // template's tree, and `scaffold-description.test.ts` holds the printed + // block to the template's object files: an object added there fails it + // until a line here names it. console.log(chalk.bold(' Your project starts with:')); console.log(chalk.dim(' Companies and Contacts src/objects/, with their lists in src/views/')); + console.log(chalk.dim(' Articles src/objects/ and src/views/, with sample help articles in src/data/')); console.log(chalk.dim(" Tasks and Notes the platform's own, in the menu of src/apps/main.app.ts")); console.log(''); diff --git a/packages/create-objectstack/src/scaffold-description.test.ts b/packages/create-objectstack/src/scaffold-description.test.ts index dd3ed9a0325..a64c7e7c1f4 100644 --- a/packages/create-objectstack/src/scaffold-description.test.ts +++ b/packages/create-objectstack/src/scaffold-description.test.ts @@ -30,20 +30,22 @@ const TSX = path.join(REPO_ROOT, 'node_modules', '.bin', 'tsx'); const INDEX_TS = path.join(PKG_ROOT, 'src', 'index.ts'); const TEMPLATE_DESCRIPTION_CONFIG = - 'Companies and contacts, with tasks and notes from the platform in the menu.'; + 'Companies, contacts and help articles, with tasks and notes from the platform in the menu.'; const TEMPLATE_DESCRIPTION_MANIFEST = - 'ObjectStack environment that starts with companies and contacts, with tasks and notes from the platform in the menu.'; + 'ObjectStack environment that starts with companies, contacts and help articles, with tasks and notes from the platform in the menu.'; let tmp: string; let projectDir: string; +/** What the scaffolder printed, colour codes stripped. */ +let printed: string; beforeEach(() => { tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'create-objectstack-desc-')); - execFileSync( + printed = execFileSync( TSX, [INDEX_TS, 'support-desk', '--template', 'blank', '--skip-install', '--skip-skills'], - { cwd: tmp, stdio: 'pipe' }, - ); + { cwd: tmp, stdio: 'pipe', encoding: 'utf8' }, + ).replace(/\u001b\[[0-9;]*m/g, ''); projectDir = path.join(tmp, 'support-desk'); }, 30_000); @@ -120,3 +122,63 @@ describe('scaffolded project description (#9263)', () => { expect(messages).toEqual([]); }); }); + +// The closing "Your project starts with:" block lists what a new project holds +// on day one. Its expected entries are derived from the template, not listed +// here: every object file under the template's `src/objects/` must be named by +// its plural label, and a template that seeds sample data must point at +// `src/data/`. So the next object added to the template fails this until the +// summary in index.ts names it. +describe('the scaffolder\'s closing summary names every object the template ships', () => { + const OBJECTS_DIR = path.join(PKG_ROOT, 'src', 'templates', 'blank', 'src', 'objects'); + const DATA_INDEX = path.join(PKG_ROOT, 'src', 'templates', 'blank', 'src', 'data', 'index.ts'); + + /** The printed block: the lines after the heading, up to the first blank line. */ + function summaryBlock(): string { + const lines = printed.split('\n'); + const start = lines.findIndex((l) => l.trim() === 'Your project starts with:'); + expect(start, 'the scaffolder no longer prints "Your project starts with:"').toBeGreaterThanOrEqual(0); + const end = lines.findIndex((l, i) => i > start && l.trim() === ''); + return lines.slice(start + 1, end).join('\n'); + } + + /** Each template object file's `pluralLabel`, one per file. */ + function templateObjectLabels(): string[] { + const files = fs.readdirSync(OBJECTS_DIR).filter((f) => f.endsWith('.object.ts')); + return files.map((f) => { + const label = /\bpluralLabel:\s*'([^']+)'/.exec(fs.readFileSync(path.join(OBJECTS_DIR, f), 'utf8'))?.[1]; + expect(label, `${f} declares no pluralLabel, so the summary cannot be checked against it`).toBeTruthy(); + return label as string; + }); + } + + it('names each template object by its plural label', () => { + const block = summaryBlock(); + const labels = templateObjectLabels(); + // Control: the derivation read real files, so a moved directory cannot pass vacuously. + expect(labels).toEqual(expect.arrayContaining(['Companies', 'Contacts', 'Articles'])); + for (const label of labels) { + expect(block, `the summary does not name ${label}, an object the template ships`).toMatch( + new RegExp(`\\b${label}\\b`), + ); + } + }); + + it('names each template object in the printed Template line too', () => { + // The line comes from the template registry's description, printed before + // the files are written; it describes the same tree, so it is held to it. + const line = printed.split('\n').find((l) => l.trim().startsWith('Template: blank')); + expect(line, 'the scaffolder no longer prints "Template: blank — …"').toBeDefined(); + for (const label of templateObjectLabels()) { + expect(line, `the Template line does not name ${label}, an object the template ships`).toMatch( + new RegExp(`\\b${label}\\b`, 'i'), + ); + } + }); + + it('points at src/data/ while the template seeds sample data', () => { + const seeds = /^export\s/m.test(fs.readFileSync(DATA_INDEX, 'utf8')); + expect(seeds, 'control: the template seeds sample data').toBe(true); + expect(summaryBlock()).toContain('src/data/'); + }); +}); diff --git a/packages/create-objectstack/src/template-registry.ts b/packages/create-objectstack/src/template-registry.ts index 4c909abe933..d460120e9a5 100644 --- a/packages/create-objectstack/src/template-registry.ts +++ b/packages/create-objectstack/src/template-registry.ts @@ -24,7 +24,7 @@ export interface TemplateInfo { */ export const TEMPLATES: Record = { blank: { - description: 'Companies and contacts, with platform tasks and notes in the menu — ready to extend', + description: 'Companies, contacts and help articles, with tasks and notes from the platform in the menu — ready to extend', source: { kind: 'bundled', dir: 'blank' }, }, }; diff --git a/packages/create-objectstack/src/templates/blank/objectstack.config.ts b/packages/create-objectstack/src/templates/blank/objectstack.config.ts index 1675497bb7c..503967d712b 100644 --- a/packages/create-objectstack/src/templates/blank/objectstack.config.ts +++ b/packages/create-objectstack/src/templates/blank/objectstack.config.ts @@ -28,7 +28,7 @@ export default defineStack({ version: '0.1.0', type: 'app', name: 'Blank Starter', - description: 'Companies and contacts, with tasks and notes from the platform in the menu.', + description: 'Companies, contacts and help articles, with tasks and notes from the platform in the menu.', // Protocol compatibility range: the metadata-protocol major this app is // authored against. The runtime checks it before it loads anything, so a // runtime outside the range refuses this app at the boundary with the exact diff --git a/packages/create-objectstack/src/templates/blank/objectstack.manifest.json b/packages/create-objectstack/src/templates/blank/objectstack.manifest.json index ef71e1d6d32..ef04be3821c 100644 --- a/packages/create-objectstack/src/templates/blank/objectstack.manifest.json +++ b/packages/create-objectstack/src/templates/blank/objectstack.manifest.json @@ -2,6 +2,6 @@ "$schema": "https://schemas.objectstack.dev/template-manifest.json", "namespace": "blank", "displayName": "Blank Starter", - "description": "ObjectStack environment that starts with companies and contacts, with tasks and notes from the platform in the menu.", + "description": "ObjectStack environment that starts with companies, contacts and help articles, with tasks and notes from the platform in the menu.", "readmePath": "README.md" } diff --git a/packages/platform-objects/src/managed-api-method-affordance-sweep.test.ts b/packages/platform-objects/src/managed-api-method-affordance-sweep.test.ts index f3ed1028dba..bf4cf2eeb86 100644 --- a/packages/platform-objects/src/managed-api-method-affordance-sweep.test.ts +++ b/packages/platform-objects/src/managed-api-method-affordance-sweep.test.ts @@ -87,7 +87,7 @@ */ import { readdirSync, statSync } from 'node:fs'; -import { join, relative, resolve } from 'node:path'; +import { join, relative, resolve, sep } from 'node:path'; import { beforeAll, describe, expect, it } from 'vitest'; import { MANAGED_API_METHOD_UNAFFORDABLE, @@ -137,15 +137,23 @@ const PACKAGES_DIR = join(REPO_ROOT, 'packages'); * be imported here: a template's `@objectstack/spec` import resolves only inside * the generated project, which has its own install. * - * Declared as an exact path list, not a `templates/` pattern, and pinned as - * still-existing below. Every OTHER file is imported without a try/catch, so a - * file this sweep cannot load fails the run instead of being silently dropped — - * a silent skip is how a sweep keeps passing over the objects it stopped seeing. + * Declared as the scaffolder's template directory, not a list of its files: an + * object file anywhere under it is payload copied into a new project, so the + * next object a template gains is excluded with no edit here (a path list + * naming company and contact went on sweeping the template's later + * `article.object.ts` as a booted definition). The exclusion is held from both + * sides below: it must match at least one walked file, every match must sit in + * a template's own `src/objects/`, and it must remove nothing outside the + * directory. Every OTHER file is imported without a try/catch, so a file this + * sweep cannot load fails the run instead of being silently dropped — a silent + * skip is how a sweep keeps passing over the objects it stopped seeing. */ -const SCAFFOLDING_TEMPLATES: readonly string[] = [ - 'packages/create-objectstack/src/templates/blank/src/objects/company.object.ts', - 'packages/create-objectstack/src/templates/blank/src/objects/contact.object.ts', -]; +const SCAFFOLDING_TEMPLATES_DIR = 'packages/create-objectstack/src/templates/'; + +/** Whether a repo-relative path is a scaffolding template's file. */ +function isScaffoldingTemplate(repoRelative: string): boolean { + return repoRelative.split(sep).join('/').startsWith(SCAFFOLDING_TEMPLATES_DIR); +} /** Every `*.object.ts` under `packages/`, skipping build output, deps and tests. */ function walkObjectFiles(dir: string, out: string[] = []): string[] { @@ -173,7 +181,7 @@ function walkObjectFiles(dir: string, out: string[] = []): string[] { /** The files this sweep judges: every walked object file bar the templates. */ function sweptFiles(): string[] { return walkObjectFiles(PACKAGES_DIR).filter( - (f) => !SCAFFOLDING_TEMPLATES.includes(relative(REPO_ROOT, f)), + (f) => !isScaffoldingTemplate(relative(REPO_ROOT, f)), ); } @@ -311,11 +319,37 @@ describe('#7934 — code-shipped managed objects declare only apiMethods their o it('skips only scaffolding templates, and those still exist', () => { // A stale exemption is documentation of nothing; an exemption that quietly // grew is a hole. Both directions, on the SINGLE_RECORD_WRITE_ONLY pattern. - const walked = walkObjectFiles(PACKAGES_DIR).map((f) => relative(REPO_ROOT, f)); - for (const template of SCAFFOLDING_TEMPLATES) { - expect(walked, `${template} is no longer a real object file — drop the exemption`).toContain(template); + const walked = walkObjectFiles(PACKAGES_DIR).map((f) => relative(REPO_ROOT, f).split(sep).join('/')); + const templates = walked.filter(isScaffoldingTemplate); + // Not empty: the directory still holds template object files. + expect(templates.length, `${SCAFFOLDING_TEMPLATES_DIR} holds no object file any more — drop the exemption`) + .toBeGreaterThan(0); + // Not over-wide: each match is an object file in a template's own src/objects/. + for (const template of templates) { + expect(template, `${template} is excluded but is not a template's object file`).toMatch( + /^packages\/create-objectstack\/src\/templates\/[^/]+\/src\/objects\/[^/]+\.object\.ts$/, + ); } - expect(walked.length - sweptFiles().length).toBe(SCAFFOLDING_TEMPLATES.length); + // Exactly the templates' object files, read off each template's src/objects/ + // independently of the walk — today's blank template's article.object.ts among them. + const templatesRoot = join(REPO_ROOT, SCAFFOLDING_TEMPLATES_DIR); + const listed = readdirSync(templatesRoot).flatMap((t) => { + const objectsDir = join(templatesRoot, t, 'src', 'objects'); + let entries: string[]; + try { + entries = readdirSync(objectsDir); + } catch { + return []; + } + return entries + .filter((f) => f.endsWith('.object.ts')) + .map((f) => `${SCAFFOLDING_TEMPLATES_DIR}${t}/src/objects/${f}`); + }); + expect([...templates].sort()).toEqual([...listed].sort()); + // The template object a path list once missed, named so a regression to one is red here. + expect(templates).toContain('packages/create-objectstack/src/templates/blank/src/objects/article.object.ts'); + // And the filter removes nothing outside the directory. + expect(walked.length - sweptFiles().length).toBe(templates.length); }); // ── the verdict ─────────────────────────────────────────────────────────── diff --git a/packages/platform-objects/src/platform-admin-affordance-standing.test.ts b/packages/platform-objects/src/platform-admin-affordance-standing.test.ts index 6b6fceeb218..7b6ee99c3da 100644 --- a/packages/platform-objects/src/platform-admin-affordance-standing.test.ts +++ b/packages/platform-objects/src/platform-admin-affordance-standing.test.ts @@ -62,7 +62,7 @@ */ import { readdirSync, statSync } from 'node:fs'; -import { join, relative, resolve } from 'node:path'; +import { join, relative, resolve, sep } from 'node:path'; import { beforeAll, describe, expect, it } from 'vitest'; import { celEngine } from '@objectstack/formula'; import { ADMIN_FULL_ACCESS_CAPABILITIES } from '@objectstack/spec/identity'; @@ -77,11 +77,17 @@ const HERE = __dirname; const REPO_ROOT = resolve(HERE, '../../..'); const PACKAGES_DIR = join(REPO_ROOT, 'packages'); -/** Object files that are templates for a generated project, not definitions this repo boots. */ -const SCAFFOLDING_TEMPLATES: readonly string[] = [ - 'packages/create-objectstack/src/templates/blank/src/objects/company.object.ts', - 'packages/create-objectstack/src/templates/blank/src/objects/contact.object.ts', -]; +/** + * The scaffolder's template directory: an object file under it is payload for a + * generated project, not a definition this repo boots. The same exclusion, and + * its control, as `managed-api-method-affordance-sweep.test.ts`. + */ +const SCAFFOLDING_TEMPLATES_DIR = 'packages/create-objectstack/src/templates/'; + +/** Whether a repo-relative path is a scaffolding template's file. */ +function isScaffoldingTemplate(repoRelative: string): boolean { + return repoRelative.split(sep).join('/').startsWith(SCAFFOLDING_TEMPLATES_DIR); +} const ADMIN_NAMESPACE = '/api/v1/auth/admin/'; @@ -145,7 +151,7 @@ function sourceOf(raw: unknown): string | undefined { async function loadActions(): Promise<{ files: number; actions: FirstPartyAction[] }> { const files = walkObjectFiles(PACKAGES_DIR).filter( - (f) => !SCAFFOLDING_TEMPLATES.includes(relative(REPO_ROOT, f)), + (f) => !isScaffoldingTemplate(relative(REPO_ROOT, f)), ); const actions: FirstPartyAction[] = []; for (const file of files) {