@uns-kit/cli 2.0.26 → 2.0.27

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.
Files changed (2) hide show
  1. package/dist/index.js +37 -0
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -374,6 +374,21 @@ async function initGitRepository(targetDir) {
374
374
  return false;
375
375
  }
376
376
  }
377
+ function setPackageScript(scripts, name, command) {
378
+ if (scripts[name] === command) {
379
+ return false;
380
+ }
381
+ scripts[name] = command;
382
+ return true;
383
+ }
384
+ function ensureUnsReferenceScripts(scripts) {
385
+ let changed = false;
386
+ changed = setPackageScript(scripts, "generate-uns-dictionary", "node ./node_modules/@uns-kit/core/dist/tools/generate-uns-dictionary.js --input uns-dictionary.json --output src/uns/uns-dictionary.generated.ts") || changed;
387
+ changed = setPackageScript(scripts, "generate-uns-measurements", "node ./node_modules/@uns-kit/core/dist/tools/generate-uns-measurements.js --input uns-measurements.json --output src/uns/uns-measurements.generated.ts") || changed;
388
+ changed = setPackageScript(scripts, "generate-uns-reference", "node ./node_modules/@uns-kit/core/dist/tools/generate-uns-reference.js --dictionary uns-dictionary.json --dictionary-output src/uns/uns-dictionary.generated.ts --measurements uns-measurements.json --measurements-output src/uns/uns-measurements.generated.ts") || changed;
389
+ changed = setPackageScript(scripts, "sync-uns-schema", "node ./node_modules/@uns-kit/core/dist/tools/sync-uns-schema.js") || changed;
390
+ return changed;
391
+ }
377
392
  async function configureDevops(targetPath, options) {
378
393
  const targetDir = path.resolve(process.cwd(), targetPath ?? ".");
379
394
  await ensureGitRepository(targetDir);
@@ -762,6 +777,7 @@ async function configurePython(targetPath, options = {}) {
762
777
  });
763
778
  }
764
779
  async function configureUnsReference(targetPath, options = {}) {
780
+ const targetDir = path.resolve(process.cwd(), targetPath ?? ".");
765
781
  await configurePlugin({
766
782
  targetPath,
767
783
  templateName: "uns-dictionary",
@@ -774,6 +790,27 @@ async function configureUnsReference(targetPath, options = {}) {
774
790
  label: "UNS measurements (units)",
775
791
  overwrite: options.overwrite,
776
792
  });
793
+ const packagePath = path.join(targetDir, "package.json");
794
+ let pkgRaw;
795
+ try {
796
+ pkgRaw = await readFile(packagePath, "utf8");
797
+ }
798
+ catch (error) {
799
+ if (error.code === "ENOENT") {
800
+ throw new Error(`Could not find package.json in ${targetDir}`);
801
+ }
802
+ throw error;
803
+ }
804
+ const pkg = JSON.parse(pkgRaw);
805
+ const scripts = (pkg.scripts ??= {});
806
+ const pkgChanged = ensureUnsReferenceScripts(scripts);
807
+ if (pkgChanged) {
808
+ await writeFile(packagePath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
809
+ console.log(" Updated package.json schema scripts.");
810
+ }
811
+ else {
812
+ console.log(" Existing package.json already contained schema scripts.");
813
+ }
777
814
  }
778
815
  const configureFeatureHandlers = {
779
816
  devops: configureDevops,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uns-kit/cli",
3
- "version": "2.0.26",
3
+ "version": "2.0.27",
4
4
  "description": "Command line scaffolding tool for UNS applications",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -26,13 +26,13 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "azure-devops-node-api": "^15.1.1",
29
- "@uns-kit/core": "2.0.26"
29
+ "@uns-kit/core": "2.0.27"
30
30
  },
31
31
  "unsKitPackages": {
32
- "@uns-kit/core": "2.0.26",
33
- "@uns-kit/api": "2.0.26",
34
- "@uns-kit/cron": "2.0.26",
35
- "@uns-kit/temporal": "2.0.26"
32
+ "@uns-kit/core": "2.0.27",
33
+ "@uns-kit/api": "2.0.27",
34
+ "@uns-kit/cron": "2.0.27",
35
+ "@uns-kit/temporal": "2.0.27"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "tsc -p tsconfig.build.json",