@percepta/create 3.1.4 → 3.1.5

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/package.json CHANGED
@@ -1,8 +1,17 @@
1
1
  {
2
2
  "name": "@percepta/create",
3
- "version": "3.1.4",
3
+ "version": "3.1.5",
4
4
  "description": "Scaffold a new Mosaic package",
5
- "type": "module",
5
+ "keywords": [
6
+ "cli",
7
+ "create",
8
+ "mosaic",
9
+ "nextjs",
10
+ "percepta",
11
+ "scaffold",
12
+ "template"
13
+ ],
14
+ "license": "MIT",
6
15
  "bin": {
7
16
  "create": "./dist/index.js"
8
17
  },
@@ -11,6 +20,10 @@
11
20
  "templates",
12
21
  "template-versions.json"
13
22
  ],
23
+ "type": "module",
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
14
27
  "dependencies": {
15
28
  "chalk": "^5.4.1",
16
29
  "commander": "^13.1.0",
@@ -24,36 +37,22 @@
24
37
  "@types/fs-extra": "^11.0.4",
25
38
  "@types/node": "^24.1.0",
26
39
  "@types/validate-npm-package-name": "^4.0.2",
27
- "tsup": "^8.4.0",
28
- "typescript": "^5.7.3",
29
40
  "vitest": "^4.0.0",
30
- "@percepta/build": "0.4.1"
41
+ "@percepta/build": "0.5.0"
31
42
  },
32
43
  "engines": {
33
44
  "node": ">=18.0.0"
34
45
  },
35
- "publishConfig": {
36
- "access": "public"
37
- },
38
- "keywords": [
39
- "create",
40
- "template",
41
- "nextjs",
42
- "mosaic",
43
- "percepta",
44
- "scaffold",
45
- "cli"
46
- ],
47
- "license": "MIT",
48
46
  "scripts": {
49
- "build": "tsup src/index.ts --format esm --dts --clean",
50
- "create:local": "pnpm build && node dist/index.js",
51
- "dev": "tsup src/index.ts --format esm --watch",
47
+ "build": "tsdown",
48
+ "dev": "tsdown --watch",
49
+ "clean": "rimraf dist",
52
50
  "typecheck": "tsc --noEmit",
53
- "sync-template": "tsx scripts/sync-template.ts",
54
- "template:tag": "tsx scripts/template-tag.ts",
55
51
  "test": "vitest run",
56
52
  "test:watch": "vitest",
57
- "test:template": "bash scripts/test-template.sh"
53
+ "test:template": "bash scripts/test-template.sh",
54
+ "create:local": "pnpm build && node dist/index.js",
55
+ "sync-template": "tsx scripts/sync-template.ts",
56
+ "template:tag": "tsx scripts/template-tag.ts"
58
57
  }
59
58
  }
@@ -1,139 +0,0 @@
1
- // src/utils/prompts.ts
2
- import path from "path";
3
- import inquirer from "inquirer";
4
-
5
- // src/utils/validate.ts
6
- import validateNpmPackageName from "validate-npm-package-name";
7
- function validateProjectName(name) {
8
- const result = validateNpmPackageName(name);
9
- if (!result.validForNewPackages) {
10
- const errors = [...result.errors || [], ...result.warnings || []];
11
- return {
12
- valid: false,
13
- error: errors[0] || "Invalid package name"
14
- };
15
- }
16
- return { valid: true };
17
- }
18
-
19
- // src/utils/case-converters.ts
20
- function toKebabCase(str) {
21
- return str.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
22
- }
23
- function toTitleCase(str) {
24
- return str.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
25
- }
26
- function toSnakeCase(str) {
27
- return str.replace(/-/g, "_");
28
- }
29
-
30
- // src/utils/prompts.ts
31
- var VALID_PROJECT_TYPES = ["monorepo", "webapp", "library"];
32
- function isValidProjectType(value) {
33
- return typeof value === "string" && VALID_PROJECT_TYPES.includes(value);
34
- }
35
- async function promptName(message) {
36
- const { name } = await inquirer.prompt([
37
- {
38
- type: "input",
39
- name: "name",
40
- message,
41
- filter: toKebabCase,
42
- validate: (input) => {
43
- const result = validateProjectName(toKebabCase(input));
44
- return result.valid || result.error || "Invalid project name";
45
- }
46
- }
47
- ]);
48
- return name;
49
- }
50
- async function promptOutsideMonorepoType() {
51
- const { webapp } = await inquirer.prompt([
52
- {
53
- type: "confirm",
54
- name: "webapp",
55
- message: "Initialize with a webapp?",
56
- default: true
57
- }
58
- ]);
59
- return webapp ? "webapp" : "monorepo";
60
- }
61
- async function promptInsideMonorepoType() {
62
- const { projectType } = await inquirer.prompt([
63
- {
64
- type: "rawlist",
65
- name: "projectType",
66
- message: "What kind of package?",
67
- // inquirer v12 / @inquirer/rawlist v5 matches `default` against the
68
- // choice's `value`, not its index. `default: 0` would be a no-op.
69
- default: "webapp",
70
- choices: [
71
- { name: "Webapp \u2014 A Next.js webapp", value: "webapp" },
72
- { name: "Library \u2014 A TypeScript library", value: "library" }
73
- ]
74
- }
75
- ]);
76
- return projectType;
77
- }
78
- async function promptProjectDetails(defaults) {
79
- const inMonorepo = defaults.monorepoContext?.found ?? false;
80
- const cwd = defaults.cwd ?? process.cwd();
81
- let projectType;
82
- let finalName;
83
- if (inMonorepo) {
84
- projectType = defaults.projectType ?? await promptInsideMonorepoType();
85
- await defaults.beforeNamePrompt?.(projectType);
86
- finalName = defaults.name || await promptName("Package name?");
87
- } else {
88
- const repoName = defaults.repoName || (defaults.projectType === "monorepo" ? defaults.name : void 0) || await promptName("Repo name?");
89
- const repoTitle = toTitleCase(repoName);
90
- projectType = defaults.projectType ?? await promptOutsideMonorepoType();
91
- await defaults.beforeNamePrompt?.(projectType);
92
- if (projectType === "monorepo") {
93
- finalName = repoName;
94
- const finalTitle3 = repoTitle;
95
- const finalDirectory3 = path.resolve(cwd, repoName);
96
- return {
97
- projectType,
98
- directory: finalDirectory3,
99
- name: finalName,
100
- title: finalTitle3,
101
- installDeps: !defaults.skipInstall,
102
- monorepoName: repoName,
103
- monorepoTitle: repoTitle
104
- };
105
- }
106
- const packageNamePrompt = projectType === "webapp" ? "Webapp name?" : "Library name?";
107
- finalName = defaults.name || await promptName(packageNamePrompt);
108
- const finalTitle2 = toTitleCase(finalName);
109
- const finalDirectory2 = path.resolve(cwd, repoName);
110
- return {
111
- projectType,
112
- directory: finalDirectory2,
113
- name: finalName,
114
- title: finalTitle2,
115
- installDeps: !defaults.skipInstall,
116
- monorepoName: repoName,
117
- monorepoTitle: repoTitle
118
- };
119
- }
120
- const finalTitle = finalName ? toTitleCase(finalName) : "";
121
- const finalDirectory = !inMonorepo && finalName ? path.resolve(cwd, finalName) : "";
122
- return {
123
- projectType,
124
- directory: finalDirectory,
125
- name: finalName,
126
- title: finalTitle,
127
- installDeps: !defaults.skipInstall
128
- };
129
- }
130
-
131
- export {
132
- validateProjectName,
133
- toKebabCase,
134
- toTitleCase,
135
- toSnakeCase,
136
- VALID_PROJECT_TYPES,
137
- isValidProjectType,
138
- promptProjectDetails
139
- };
@@ -1,49 +0,0 @@
1
- // src/utils/git-ops.ts
2
- import { execFileSync } from "child_process";
3
- function toGitPath(p) {
4
- return p.replace(/\\/g, "/");
5
- }
6
- function getLatestTemplateTag(type, repoPath) {
7
- try {
8
- const tags = execFileSync(
9
- "git",
10
- ["tag", "-l", `template/${type}/*`, "--sort=-v:refname"],
11
- { cwd: repoPath, encoding: "utf-8" }
12
- ).trim();
13
- if (!tags) return null;
14
- return tags.split("\n")[0] ?? null;
15
- } catch {
16
- return null;
17
- }
18
- }
19
- function getTemplateVersionFromTag(tag) {
20
- const parts = tag.split("/");
21
- return parts[parts.length - 1] ?? "";
22
- }
23
- function getTemplateDiff(repoPath, templatePath, fromTag, toTag) {
24
- return execFileSync(
25
- "git",
26
- ["diff", `${fromTag}..${toTag}`, "--", toGitPath(templatePath)],
27
- {
28
- cwd: repoPath,
29
- encoding: "utf-8"
30
- }
31
- );
32
- }
33
- function getFileAtTag(repoPath, tag, filePath) {
34
- try {
35
- return execFileSync("git", ["show", `${tag}:${toGitPath(filePath)}`], {
36
- cwd: repoPath,
37
- encoding: "utf-8"
38
- });
39
- } catch {
40
- return null;
41
- }
42
- }
43
-
44
- export {
45
- getLatestTemplateTag,
46
- getTemplateVersionFromTag,
47
- getTemplateDiff,
48
- getFileAtTag
49
- };
@@ -1,60 +0,0 @@
1
- // src/utils/manifest.ts
2
- import path from "path";
3
- import fs from "fs-extra";
4
- var MANIFEST_FILENAME = ".mosaic-template.json";
5
- function getManifestPath(dir) {
6
- return path.join(dir, MANIFEST_FILENAME);
7
- }
8
- async function readManifest(dir) {
9
- const manifestPath = getManifestPath(dir);
10
- if (!await fs.pathExists(manifestPath)) {
11
- throw new Error(
12
- `No ${MANIFEST_FILENAME} found in ${dir}. Run 'create init' to create one.`
13
- );
14
- }
15
- const content = await fs.readFile(manifestPath, "utf-8");
16
- try {
17
- return JSON.parse(content);
18
- } catch (error) {
19
- throw new Error(
20
- `Invalid JSON in ${MANIFEST_FILENAME}: ${error.message}`
21
- );
22
- }
23
- }
24
- async function writeManifest(dir, manifest) {
25
- const manifestPath = getManifestPath(dir);
26
- await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2) + "\n");
27
- }
28
- async function manifestExists(dir) {
29
- return fs.pathExists(getManifestPath(dir));
30
- }
31
- function derivePlaceholders(appName, appTitle, repoName = appName) {
32
- const nameSnake = appName.replace(/-/g, "_");
33
- const repoNameSnake = repoName.replace(/-/g, "_");
34
- return {
35
- __APP_NAME__: appName,
36
- __APP_TITLE__: appTitle,
37
- __DB_NAME__: nameSnake + "_db",
38
- __APP_NAME_UPPER__: appName.toUpperCase(),
39
- __APP_NAME_SNAKE__: nameSnake,
40
- __REPO_NAME__: repoName,
41
- __REPO_NAME_SNAKE__: repoNameSnake
42
- };
43
- }
44
- function resolveMosaicTemplatePath(options) {
45
- if (options.mosaicTemplatePath)
46
- return path.resolve(options.mosaicTemplatePath);
47
- if (process.env.MOSAIC_TEMPLATE_PATH)
48
- return path.resolve(process.env.MOSAIC_TEMPLATE_PATH);
49
- throw new Error(
50
- "Mosaic repo path required. Use --mosaic-template-path or set MOSAIC_TEMPLATE_PATH."
51
- );
52
- }
53
-
54
- export {
55
- readManifest,
56
- writeManifest,
57
- manifestExists,
58
- derivePlaceholders,
59
- resolveMosaicTemplatePath
60
- };
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- #!/usr/bin/env node
@@ -1,96 +0,0 @@
1
- import {
2
- VALID_PROJECT_TYPES,
3
- isValidProjectType
4
- } from "./chunk-CO3YWUD6.js";
5
- import {
6
- derivePlaceholders,
7
- manifestExists,
8
- writeManifest
9
- } from "./chunk-V5EJIUBJ.js";
10
-
11
- // src/commands/init.ts
12
- import path from "path";
13
- import fs from "fs-extra";
14
- import chalk from "chalk";
15
- import inquirer from "inquirer";
16
- async function initCommand(options) {
17
- const cwd = process.cwd();
18
- if (await manifestExists(cwd)) {
19
- console.error(
20
- chalk.red(".mosaic-template.json already exists in this directory.")
21
- );
22
- process.exit(1);
23
- }
24
- const pkgPath = path.join(cwd, "package.json");
25
- let appName = path.basename(cwd);
26
- if (await fs.pathExists(pkgPath)) {
27
- const pkg = JSON.parse(await fs.readFile(pkgPath, "utf-8"));
28
- appName = pkg.name?.replace(/^@[^/]+\//, "") || appName;
29
- }
30
- let templateType = options.type;
31
- if (templateType && !isValidProjectType(templateType)) {
32
- console.error(
33
- chalk.red(
34
- `Invalid template type "${templateType}". Valid types: ${VALID_PROJECT_TYPES.join(", ")}`
35
- )
36
- );
37
- process.exit(1);
38
- }
39
- if (!templateType) {
40
- const answer = await inquirer.prompt([
41
- {
42
- type: "list",
43
- name: "type",
44
- message: "Template type:",
45
- choices: ["webapp", "library"]
46
- }
47
- ]);
48
- templateType = answer.type;
49
- }
50
- const templateVersion = options.templateVersion || "1.0.0";
51
- const appTitle = appName.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
52
- const manifest = {
53
- templateType,
54
- templateVersion,
55
- templateCommit: "unknown",
56
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
57
- placeholders: derivePlaceholders(appName, appTitle),
58
- source: {
59
- templatePath: `packages/create-mosaic-module/templates/${templateType}`
60
- }
61
- };
62
- await writeManifest(cwd, manifest);
63
- const notesPath = path.join(cwd, "mosaic-template-notes.md");
64
- if (!await fs.pathExists(notesPath)) {
65
- await fs.writeFile(
66
- notesPath,
67
- `# Mosaic Divergence Notes
68
-
69
- Document intentional differences from the ${templateType} template here.
70
- Claude reads this file during sync to preserve your customizations.
71
-
72
- ## Intentional Divergences
73
-
74
- `
75
- );
76
- }
77
- console.log();
78
- console.log(
79
- chalk.green("\u2714"),
80
- chalk.bold("Initialized .mosaic-template.json")
81
- );
82
- console.log();
83
- console.log(chalk.dim(" Template:"), templateType);
84
- console.log(chalk.dim(" Version:"), templateVersion);
85
- console.log(chalk.dim(" App name:"), appName);
86
- console.log();
87
- console.log(
88
- chalk.dim(
89
- "Review .mosaic-template.json and mosaic-template-notes.md, then commit them."
90
- )
91
- );
92
- console.log();
93
- }
94
- export {
95
- initCommand
96
- };
@@ -1,76 +0,0 @@
1
- import {
2
- getLatestTemplateTag,
3
- getTemplateVersionFromTag
4
- } from "./chunk-DCM7JOSC.js";
5
- import {
6
- readManifest
7
- } from "./chunk-V5EJIUBJ.js";
8
-
9
- // src/commands/status.ts
10
- import path from "path";
11
- import chalk from "chalk";
12
- async function statusCommand(options) {
13
- const cwd = process.cwd();
14
- try {
15
- const manifest = await readManifest(cwd);
16
- console.log();
17
- console.log(chalk.bold("Mosaic Template Status"));
18
- console.log();
19
- console.log(chalk.dim(" Template type:"), manifest.templateType);
20
- console.log(chalk.dim(" Current version:"), manifest.templateVersion);
21
- console.log(chalk.dim(" Template commit:"), manifest.templateCommit);
22
- console.log(chalk.dim(" Created:"), manifest.createdAt);
23
- if (manifest.lastSyncedAt) {
24
- console.log(chalk.dim(" Last synced:"), manifest.lastSyncedAt);
25
- }
26
- const rawPath = options.mosaicTemplatePath || process.env.MOSAIC_TEMPLATE_PATH;
27
- const mosaicTemplatePath = rawPath ? path.resolve(rawPath) : void 0;
28
- if (mosaicTemplatePath) {
29
- const latestTag = getLatestTemplateTag(
30
- manifest.templateType,
31
- mosaicTemplatePath
32
- );
33
- if (latestTag) {
34
- const latestVersion = getTemplateVersionFromTag(latestTag);
35
- console.log(chalk.dim(" Latest version:"), latestVersion);
36
- console.log();
37
- if (latestVersion !== manifest.templateVersion) {
38
- console.log(
39
- chalk.yellow(
40
- ` Update available: ${manifest.templateVersion} \u2192 ${latestVersion}`
41
- )
42
- );
43
- console.log(
44
- chalk.dim(" Run:"),
45
- `create sync --mosaic-template-path ${mosaicTemplatePath}`
46
- );
47
- } else {
48
- console.log(chalk.green(" Up to date"));
49
- }
50
- } else {
51
- console.log();
52
- console.log(
53
- chalk.yellow(" No template tags found in mosaic repo.")
54
- );
55
- console.log(
56
- chalk.dim(" Run:"),
57
- `cd ${mosaicTemplatePath} && pnpm template:tag`
58
- );
59
- }
60
- } else {
61
- console.log();
62
- console.log(
63
- chalk.dim(
64
- " Use --mosaic-template-path or set MOSAIC_TEMPLATE_PATH to check for updates"
65
- )
66
- );
67
- }
68
- console.log();
69
- } catch (error) {
70
- console.error(chalk.red(error.message));
71
- process.exit(1);
72
- }
73
- }
74
- export {
75
- statusCommand
76
- };
@@ -1,136 +0,0 @@
1
- import {
2
- getLatestTemplateTag,
3
- getTemplateDiff,
4
- getTemplateVersionFromTag
5
- } from "./chunk-DCM7JOSC.js";
6
- import {
7
- readManifest,
8
- resolveMosaicTemplatePath
9
- } from "./chunk-V5EJIUBJ.js";
10
-
11
- // src/commands/sync.ts
12
- import path from "path";
13
- import fs from "fs-extra";
14
- import chalk from "chalk";
15
- function generateSyncContext(manifest, toVersion, diff, notes) {
16
- let content = `# Mosaic Sync Context
17
-
18
- ## App Info
19
- - **Template:** ${manifest.templateType}
20
- - **Current version:** ${manifest.templateVersion}
21
- - **Target version:** ${toVersion}
22
-
23
- ## Placeholder Mappings
24
-
25
- When applying template changes, replace these placeholder tokens with the actual values:
26
-
27
- | Placeholder | Value |
28
- |------------|-------|
29
- ${Object.entries(manifest.placeholders).map(([k, v]) => `| \`${k}\` | \`${v}\` |`).join("\n")}
30
-
31
- ## Template Changes (${manifest.templateVersion} \u2192 ${toVersion})
32
-
33
- \`\`\`diff
34
- ${diff}
35
- \`\`\`
36
- `;
37
- if (notes.trim()) {
38
- content += `
39
- ## Divergence Notes (from mosaic-template-notes.md)
40
-
41
- ${notes}
42
- `;
43
- }
44
- content += `
45
- ## Instructions
46
-
47
- 1. Apply the template changes above to this app
48
- 2. When you see placeholder tokens (e.g. \`__APP_NAME__\`), replace them with the actual values from the mapping table
49
- 3. Check the divergence notes \u2014 preserve intentional divergences
50
- 4. For files not modified locally: apply changes directly
51
- 5. For files modified locally: merge intelligently, preserving local customizations
52
- 6. After applying all changes, run: \`pnpm install && pnpm build && pnpm lint\`
53
- 7. Update \`.mosaic-template.json\`: set \`templateVersion\` to \`"${toVersion}"\` and update \`templateCommit\`
54
- 8. If you made decisions about merge conflicts, add notes to \`mosaic-template-notes.md\`
55
- 9. Delete this file (\`.mosaic-sync-context.md\`) when done
56
- `;
57
- return content;
58
- }
59
- async function syncCommand(options) {
60
- const cwd = process.cwd();
61
- try {
62
- const manifest = await readManifest(cwd);
63
- const mosaicTemplatePath = resolveMosaicTemplatePath(options);
64
- const fromTag = `template/${manifest.templateType}/${manifest.templateVersion}`;
65
- let toTag;
66
- if (options.to) {
67
- toTag = `template/${manifest.templateType}/${options.to}`;
68
- } else {
69
- const latest = getLatestTemplateTag(
70
- manifest.templateType,
71
- mosaicTemplatePath
72
- );
73
- if (!latest) {
74
- console.error(
75
- chalk.red(
76
- "No template tags found. Run 'pnpm template:tag' in the mosaic repo first."
77
- )
78
- );
79
- process.exit(1);
80
- }
81
- toTag = latest;
82
- }
83
- const toVersion = getTemplateVersionFromTag(toTag);
84
- if (toVersion === manifest.templateVersion) {
85
- console.log(chalk.green("Already up to date."));
86
- return;
87
- }
88
- const diff = getTemplateDiff(
89
- mosaicTemplatePath,
90
- manifest.source.templatePath,
91
- fromTag,
92
- toTag
93
- );
94
- if (!diff.trim()) {
95
- console.log(
96
- chalk.green("No template file changes between versions.")
97
- );
98
- return;
99
- }
100
- const notesPath = path.join(cwd, "mosaic-template-notes.md");
101
- let notes = "";
102
- if (await fs.pathExists(notesPath)) {
103
- notes = await fs.readFile(notesPath, "utf-8");
104
- }
105
- const context = generateSyncContext(manifest, toVersion, diff, notes);
106
- const contextPath = path.join(cwd, ".mosaic-sync-context.md");
107
- await fs.writeFile(contextPath, context);
108
- console.log();
109
- console.log(chalk.bold("Sync Context Generated"));
110
- console.log();
111
- console.log(chalk.dim(" From:"), manifest.templateVersion);
112
- console.log(chalk.dim(" To:"), toVersion);
113
- console.log(chalk.dim(" Context file:"), ".mosaic-sync-context.md");
114
- console.log();
115
- console.log("Next steps:");
116
- console.log(
117
- chalk.dim(" 1."),
118
- "Open Claude Code in this directory"
119
- );
120
- console.log(
121
- chalk.dim(" 2."),
122
- 'Tell Claude: "Read .mosaic-sync-context.md and apply the template changes"'
123
- );
124
- console.log(
125
- chalk.dim(" 3."),
126
- "Review Claude's changes, then delete .mosaic-sync-context.md"
127
- );
128
- console.log();
129
- } catch (error) {
130
- console.error(chalk.red(error.message));
131
- process.exit(1);
132
- }
133
- }
134
- export {
135
- syncCommand
136
- };