@vizualmodel/vmblu-cli 0.3.2 → 0.3.4

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
@@ -1,7 +1,6 @@
1
1
  # CLI for vmblu
2
2
  This folder contains the CLI commands that are available for vmblu.
3
3
 
4
-
5
4
  ## Folder layout
6
5
 
7
6
  ```txt
@@ -12,7 +11,7 @@ vmblu/
12
11
  profile/
13
12
  migrate/
14
13
  templates/
15
- 0.8.2/
14
+ x.y.z/ # a directory per version x.y.z
16
15
  vmblu.schema.json
17
16
  vmblu.annex.md
18
17
  seed.md
@@ -25,7 +24,7 @@ vmblu/
25
24
 
26
25
  ## Add more commands
27
26
 
28
- Create commands/migrate/index.js with the same export shape { command, describe, builder, handler }. The router auto-discovers it, so users can run vmblu migrate ….
27
+ Create commands/migrate/index.js with the same export shape { command, describe, builder, handler }. The router auto-discovers it.
29
28
 
30
29
  ## Dev/test workflow
31
30
 
@@ -1,15 +1,20 @@
1
1
  // vmblu init [targetDir] --name <project> --schema <ver> --force --dry-run
2
- import path from 'path';
3
- import { fileURLToPath } from 'url';
4
- import { initProject } from './init-project.js';
5
-
6
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import { initProject } from './init-project.js';
5
+ import { createRequire } from 'module';
6
+
7
+ const require = createRequire(import.meta.url);
8
+ const pckg = require('../../package.json');
9
+
10
+
11
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
12
 
8
13
  export const command = 'init <folder name>';
9
14
  export const describe = 'Scaffold an empty vmblu project';
10
15
  export const builder = [
11
16
  { flag: '--name <project>', desc: 'Project name (default: folder name)' },
12
- { flag: '--schema <ver>', desc: 'Schema version (default: 0.8.2)' },
17
+ { flag: '--schema <ver>', desc: 'Schema version (default: latest version)' },
13
18
  { flag: '--force', desc: 'Overwrite existing files' },
14
19
  { flag: '--dry-run', desc: 'Show actions without writing' }
15
20
  ];
@@ -28,7 +33,7 @@ export const handler = async (argv) => {
28
33
 
29
34
  const targetDir = path.resolve(args._[0] || '.');
30
35
  const projectName = args.name || path.basename(targetDir);
31
- const schemaVersion = args.schema || '0.8.2';
36
+ const schemaVersion = args.schema || pckg.schemaVersion;
32
37
 
33
38
  await initProject({
34
39
  targetDir,
@@ -1,10 +1,17 @@
1
1
  // core/initProject.js
2
2
  // Node 18+ (fs/promises, crypto). No external deps.
3
- import * as fs from 'fs/promises';
4
- import * as fssync from 'fs';
5
- import path from 'path';
6
- //import crypto from 'crypto';
7
- import { makePackageJson } from './make-package-json.js';
3
+ import * as fs from 'fs/promises';
4
+ import * as fssync from 'fs';
5
+ import path from 'path';
6
+ //import crypto from 'crypto';
7
+ import { makePackageJson } from './make-package-json.js';
8
+ import { createRequire } from 'module';
9
+
10
+ // Get the versions
11
+ const require = createRequire(import.meta.url);
12
+ const pckg = require('../../package.json');
13
+ const SCHEMA_VERSION = pckg.schemaVersion
14
+ const CLI_VERSION = pckg.version
8
15
 
9
16
  function rel(from, to) {
10
17
  return path.posix.join(...path.relative(from, to).split(path.sep));
@@ -50,12 +57,12 @@ function defaultModel(projectName) {
50
57
  const now = new Date().toISOString();
51
58
  return JSON.stringify({
52
59
  header: {
53
- version: "0.8.2",
60
+ version: SCHEMA_VERSION,
54
61
  created: now,
55
62
  saved: now,
56
63
  utc: now,
57
64
  style: "#2c7be5",
58
- runtime: "@vizualmodel/vmblu/runtime",
65
+ runtime: "@vizualmodel/vmblu-runtime",
59
66
  description: `${projectName} — vmblu model (scaffolded)`
60
67
  },
61
68
  models: [],
@@ -73,7 +80,7 @@ function defaultModel(projectName) {
73
80
  function defaultDoc(projectName) {
74
81
  const now = new Date().toISOString();
75
82
  return JSON.stringify({
76
- version: "0.0.0",
83
+ version: CLI_VERSION,
77
84
  generatedAt: now,
78
85
  entries: {}
79
86
  }, null, 2);
@@ -145,7 +152,7 @@ async function initProject(opts) {
145
152
  const {
146
153
  targetDir,
147
154
  projectName = path.basename(opts.targetDir),
148
- schemaVersion = "0.8.2",
155
+ schemaVersion = SCHEMA_VERSION,
149
156
  force = false,
150
157
  dryRun = false,
151
158
  templatesDir = path.join(__dirname, '..', 'templates'),
@@ -246,7 +253,7 @@ async function initProject(opts) {
246
253
  }
247
254
 
248
255
  // 5) Make the package file
249
- makePackageJson({ absTarget, projectName, force, dryRun, addCliDep: true, cliVersion: "^0.1.0" }, ui);
256
+ makePackageJson({ absTarget, projectName, force, dryRun, addCliDep: true, cliVersion: "^" + CLI_VERSION }, ui);
250
257
 
251
258
  // 6) Final tree hint
252
259
  ui.info(`\nScaffold complete${dryRun ? ' (dry run)' : ''}:\n` +
@@ -1,58 +1,72 @@
1
1
  import * as fs from 'fs/promises';
2
2
  import path from 'path';
3
+ import { createRequire } from 'module';
3
4
 
4
- async function readJsonIfExists(file) {
5
+ const require = createRequire(import.meta.url);
6
+ const pckg = require('../../package.json');
7
+
8
+ async function readJsonIfExists(file) {
5
9
  try { return JSON.parse(await fs.readFile(file, 'utf8')); } catch { return null; }
6
- }
10
+ };
7
11
 
8
12
  function sortKeys(obj) {
9
13
  return Object.fromEntries(Object.entries(obj).sort(([a],[b]) => a.localeCompare(b)));
10
- }
14
+ };
11
15
 
12
- export async function makePackageJson({
13
- absTarget, projectName, force, dryRun,
14
- addCliDep = true, cliVersion = "^0.1.0"
15
- }, ui) {
16
+ export async function makePackageJson({
17
+ absTarget,
18
+ projectName,
19
+ force,
20
+ dryRun,
21
+ addCliDep = true,
22
+ cliVersion = "^"+pckg.version
23
+ }, ui)
24
+ {
25
+
26
+ // check if a pckage file exists
16
27
  const pkgPath = path.join(absTarget, 'package.json');
17
28
  const existing = await readJsonIfExists(pkgPath);
18
29
 
19
- // Base skeleton (created if missing)
20
- const basePkg = existing || {
30
+ // don't overwrite
31
+ if (existing && !force) return pkgPath;
32
+
33
+ // The base package with vite and typescript
34
+ const basePackage = {
21
35
  name: projectName,
22
36
  private: true,
23
37
  version: "0.0.0",
38
+ type: "module",
39
+ dependencies: {
40
+ "@vizualmodel/vmblu-runtime": "^0.1.0"
41
+ },
42
+ devDependencies : {
43
+ "@vizualmodel/vmblu-cli": "^0.3.3",
44
+ "typescript": "^5.9.3",
45
+ "vite": "^7.1.12",
46
+ // "ts-morph": "^26.0.0",
47
+ // "svelte": "^5.0.0",
48
+ // "@sveltejs/vite-plugin-svelte": "^6.2.1",
49
+ // "@tsconfig/svelte": "^5.0.2"
50
+ },
51
+ scripts : {
52
+ "vm:init": "vmblu init .",
53
+ "vm:profile": "vmblu profile",
54
+ "dev": "vite",
55
+ "build": "vite build",
56
+ "preview": "vite preview"
57
+ }
24
58
  };
25
59
 
26
- // Add/merge scripts (idempotent)
27
- basePkg.scripts = Object.assign({}, basePkg.scripts, {
28
- "vm:init": "vmblu init ."
29
- });
30
-
31
- // Optionally add the CLI as a devDependency
32
- if (addCliDep) {
33
- basePkg.devDependencies = Object.assign({}, basePkg.devDependencies, {
34
- "@vizualmodel/vmblu-cli": basePkg.devDependencies?.["@vizualmodel/vmblu-cli"] || cliVersion
35
- });
36
- }
37
-
38
- // Nice-to-have: keep deterministic key order
39
- const ordered = {
40
- ...sortKeys(basePkg),
41
- scripts: sortKeys(basePkg.scripts || {}),
42
- devDependencies: basePkg.devDependencies ? sortKeys(basePkg.devDependencies) : undefined
43
- };
44
60
 
45
- if (existing && !force) {
46
- ui.info(`update package.json (merge scripts${addCliDep ? " + devDependency" : ""})`);
47
- } else if (!existing) {
61
+ if (!existing) {
48
62
  ui.info(`create ${pkgPath}`);
49
63
  } else {
50
64
  ui.info(`overwrite ${pkgPath} (force)`);
51
- }
65
+ };
52
66
 
53
67
  if (!dryRun) {
54
- await fs.writeFile(pkgPath, JSON.stringify(ordered, null, 2) + '\n', 'utf8');
55
- }
68
+ await fs.writeFile(pkgPath, JSON.stringify(basePackage, null, 2) + '\n', 'utf8');
69
+ };
56
70
 
57
- return pkgPath;
58
- }
71
+ return pkgPath;
72
+ }