@pixpilot/scaffoldfy-configs 0.25.1 → 0.26.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @pixpilot/scaffoldfy-configs
2
2
 
3
+ ## 0.26.0
4
+
5
+ ### Minor Changes
6
+
7
+ - add sorting task for root package.json
8
+
3
9
  ## 0.25.1
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pixpilot/scaffoldfy-configs",
3
3
  "type": "module",
4
- "version": "0.25.1",
4
+ "version": "0.26.0",
5
5
  "author": "PixPilot <m.doaie@hotmail.com>",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -0,0 +1,68 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import fs from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { afterEach, describe, expect, it } from 'vitest';
6
+
7
+ const scriptPath = path.join(
8
+ __dirname,
9
+ '..',
10
+ 'update-root-package-json',
11
+ 'scripts',
12
+ 'sort-package-json.cjs',
13
+ );
14
+ const temporaryDirectories: string[] = [];
15
+
16
+ afterEach(() => {
17
+ for (const directory of temporaryDirectories.splice(0)) {
18
+ fs.rmSync(directory, { force: true, recursive: true });
19
+ }
20
+ });
21
+
22
+ describe('sort-package-json', () => {
23
+ it('should place root package.json fields in the configured order', () => {
24
+ const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'scaffoldfy-configs-'));
25
+ temporaryDirectories.push(directory);
26
+ const packageJsonPath = path.join(directory, 'package.json');
27
+
28
+ fs.writeFileSync(
29
+ packageJsonPath,
30
+ JSON.stringify({
31
+ scripts: {},
32
+ engines: { node: '>=24.15.0', pnpm: '>=9.6.0' },
33
+ custom: true,
34
+ private: true,
35
+ name: 'pnpm-turbo-monorepo-template',
36
+ devDependencies: {},
37
+ repository: {
38
+ type: 'git',
39
+ url: 'https://github.com/pixpilot/pnpm-turbo-monorepo-template.git',
40
+ },
41
+ packageManager: 'pnpm@10.33.4',
42
+ prettier: '@internal/prettier-config',
43
+ author: 'Mo Doaie <m.doaie@hotmail.com>',
44
+ license: 'NONE',
45
+ homepage: 'https://github.com/pixpilot/pnpm-turbo-monorepo-template',
46
+ bugs: { url: 'https://github.com/pixpilot/pnpm-turbo-monorepo-template/issues' },
47
+ }),
48
+ );
49
+
50
+ execFileSync(process.execPath, [scriptPath, `--file=${packageJsonPath}`]);
51
+
52
+ expect(Object.keys(JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')))).toEqual([
53
+ 'name',
54
+ 'private',
55
+ 'packageManager',
56
+ 'prettier',
57
+ 'author',
58
+ 'license',
59
+ 'homepage',
60
+ 'repository',
61
+ 'bugs',
62
+ 'engines',
63
+ 'scripts',
64
+ 'devDependencies',
65
+ 'custom',
66
+ ]);
67
+ });
68
+ });
@@ -25,6 +25,18 @@
25
25
  "license": "{{licenseType}}"
26
26
  }
27
27
  }
28
+ },
29
+ {
30
+ "id": "sort-root-package",
31
+ "name": "Sort root package.json",
32
+ "description": "Sort root package.json fields into the standard project order",
33
+ "type": "exec-file",
34
+ "dependencies": ["update-root-package"],
35
+ "config": {
36
+ "file": "./scripts/sort-package-json.cjs",
37
+ "runtime": "node",
38
+ "args": ["--file=package.json"]
39
+ }
28
40
  }
29
41
  ]
30
42
  }
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const fs = require('node:fs');
5
+ const process = require('node:process');
6
+
7
+ const INDENT_SPACES = 2;
8
+ const ROOT_PACKAGE_JSON_KEY_ORDER = [
9
+ 'name',
10
+ 'private',
11
+ 'packageManager',
12
+ 'prettier',
13
+ 'author',
14
+ 'license',
15
+ 'homepage',
16
+ 'repository',
17
+ 'bugs',
18
+ 'engines',
19
+ 'scripts',
20
+ 'devDependencies',
21
+ ];
22
+
23
+ /** @param {string} prefix */
24
+ function getArg(prefix) {
25
+ const arg = process.argv.find((value) => value.startsWith(prefix));
26
+ return arg?.slice(prefix.length);
27
+ }
28
+
29
+ const file = getArg('--file=');
30
+
31
+ if (!file) {
32
+ console.error('Missing --file argument');
33
+ process.exit(1);
34
+ }
35
+
36
+ let packageJson;
37
+
38
+ try {
39
+ packageJson = JSON.parse(fs.readFileSync(file, 'utf8'));
40
+ } catch (error) {
41
+ console.error(`Failed to read package.json: ${error.message}`);
42
+ process.exit(1);
43
+ }
44
+
45
+ const orderedPackageJson = {};
46
+
47
+ for (const key of ROOT_PACKAGE_JSON_KEY_ORDER) {
48
+ if (key in packageJson) {
49
+ orderedPackageJson[key] = packageJson[key];
50
+ }
51
+ }
52
+
53
+ for (const [key, value] of Object.entries(packageJson)) {
54
+ if (!(key in orderedPackageJson)) {
55
+ orderedPackageJson[key] = value;
56
+ }
57
+ }
58
+
59
+ fs.writeFileSync(file, `${JSON.stringify(orderedPackageJson, null, INDENT_SPACES)}\n`);