create-swdg-frontend 0.1.1 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-swdg-frontend",
3
- "version": "0.1.1",
3
+ "version": "0.1.4",
4
4
  "description": "Scaffold a new SWDG frontend project",
5
5
  "type": "module",
6
6
  "bin": {
@@ -14,6 +14,7 @@
14
14
  "prettier": "prettier --check .",
15
15
  "prettier:fix": "prettier --write .",
16
16
  "gen:api": "node ./scripts/gen-api.cjs",
17
+ "release": "node scripts/release.mjs",
17
18
  "test": "vitest",
18
19
  "test:run": "vitest run"
19
20
  },
@@ -43,13 +44,13 @@
43
44
  "vue-router": "^4.6.4"
44
45
  },
45
46
  "devDependencies": {
46
- "@openapitools/openapi-generator-cli": "^2.21.0",
47
47
  "@commitlint/cli": "^20.3.1",
48
48
  "@commitlint/config-conventional": "^20.3.1",
49
49
  "@commitlint/lint": "^20.3.1",
50
50
  "@commitlint/load": "^20.3.1",
51
51
  "@eslint/eslintrc": "^3.3.3",
52
52
  "@eslint/js": "^9.39.2",
53
+ "@openapitools/openapi-generator-cli": "^2.21.0",
53
54
  "@typescript-eslint/eslint-plugin": "^8.53.0",
54
55
  "@typescript-eslint/parser": "^8.53.0",
55
56
  "@vitejs/plugin-vue": "^6.0.3",
@@ -59,6 +60,7 @@
59
60
  "eslint-config-prettier": "^10.1.8",
60
61
  "eslint-plugin-prettier": "^5.5.5",
61
62
  "eslint-plugin-vue": "^10.7.0",
63
+ "fs-extra": "^11.3.3",
62
64
  "husky": "^9.1.7",
63
65
  "jsdom": "^27.4.0",
64
66
  "less": "^4.5.1",
@@ -0,0 +1,76 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import process from 'node:process';
4
+ import { execSync } from 'node:child_process';
5
+
6
+ const rootDir = process.cwd();
7
+ const createDir = path.join(rootDir, 'create-swdg');
8
+ const swdgDir = path.join(rootDir, 'swdg');
9
+
10
+ const createPkgPath = path.join(createDir, 'package.json');
11
+ const swdgPkgPath = path.join(swdgDir, 'package.json');
12
+
13
+ const args = process.argv.slice(2);
14
+ const isDryRun = args.includes('--dry-run') || args.includes('--dry');
15
+ const input = args.find((arg) => !arg.startsWith('-'));
16
+ if (!input) {
17
+ console.error(
18
+ 'Usage: node scripts/release.mjs <patch|minor|major|x.y.z> [--dry-run]',
19
+ );
20
+ process.exit(1);
21
+ }
22
+
23
+ const readJson = (filePath) => JSON.parse(fs.readFileSync(filePath, 'utf8'));
24
+ const writeJson = (filePath, data) =>
25
+ fs.writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n', 'utf8');
26
+
27
+ const isValidVersion = (value) => /^\d+\.\d+\.\d+$/.test(value);
28
+ const bumpVersion = (current, kind) => {
29
+ if (!isValidVersion(current)) {
30
+ throw new Error(`Invalid current version: ${current}`);
31
+ }
32
+ const [major, minor, patch] = current.split('.').map(Number);
33
+ if (kind === 'major') return `${major + 1}.0.0`;
34
+ if (kind === 'minor') return `${major}.${minor + 1}.0`;
35
+ if (kind === 'patch') return `${major}.${minor}.${patch + 1}`;
36
+ throw new Error(`Invalid bump type: ${kind}`);
37
+ };
38
+
39
+ const createPkg = readJson(createPkgPath);
40
+ const swdgPkg = readJson(swdgPkgPath);
41
+
42
+ const nextVersion = isValidVersion(input)
43
+ ? input
44
+ : bumpVersion(createPkg.version, input);
45
+
46
+ createPkg.version = nextVersion;
47
+ swdgPkg.version = nextVersion;
48
+ swdgPkg.dependencies = swdgPkg.dependencies || {};
49
+ swdgPkg.dependencies['create-swdg-frontend'] = `^${nextVersion}`;
50
+
51
+ writeJson(createPkgPath, createPkg);
52
+ writeJson(swdgPkgPath, swdgPkg);
53
+
54
+ if (isDryRun) {
55
+ execSync('pnpm -C create-swdg run prepublishOnly', { stdio: 'inherit' });
56
+ console.log('[dry-run] Skip npm registry switch and publish.');
57
+ } else {
58
+ try {
59
+ execSync('npm config set registry https://registry.npmjs.org/', {
60
+ stdio: 'inherit',
61
+ });
62
+ execSync('pnpm -C create-swdg run prepublishOnly', { stdio: 'inherit' });
63
+ execSync('npm publish --access public --registry https://registry.npmjs.org/', {
64
+ stdio: 'inherit',
65
+ cwd: createDir,
66
+ });
67
+ execSync('npm publish --access public --registry https://registry.npmjs.org/', {
68
+ stdio: 'inherit',
69
+ cwd: swdgDir,
70
+ });
71
+ } finally {
72
+ execSync('npm config set registry https://registry.npmmirror.com/', {
73
+ stdio: 'inherit',
74
+ });
75
+ }
76
+ }