Skip to content

Commit 22137d3

Browse files
BrooooooklynCopilot
andcommitted
Update packages/tools/src/index.ts
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: LongYinan <lynweklm@gmail.com>
1 parent bebb0fb commit 22137d3

5 files changed

Lines changed: 19 additions & 25 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
- uses: oxc-project/setup-node@fdbf0dfd334c4e6d56ceeb77d91c76339c2a0885 # v1.0.4
4949

5050
- name: Set binding version
51-
run: pnpm exec replace-file-content packages/cli/binding/Cargo.toml 'version = "0.0.0"' 'version = "0.0.0-${{ github.sha }}"'
51+
run: pnpm exec tool replace-file-content packages/cli/binding/Cargo.toml 'version = "0.0.0"' 'version = "0.0.0-${{ github.sha }}"'
5252

5353
- name: Build
5454
if: ${{ matrix.settings.target == 'x86_64-unknown-linux-gnu' }}

packages/tools/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"private": true,
44
"type": "module",
55
"bin": {
6-
"tool": "./src/bin.js"
6+
"tool": "./src/bin.js",
7+
"json-edit": "./src/json-edit.ts"
78
},
89
"devDependencies": {
910
"minimatch": "catalog:"

packages/tools/snap-tests/replace-file-content/snap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ napi-derive = { workspace = true }
1717
> replace-file-content foo/example.toml 'version = "0.0.0"' 'version = "1.0.0"' && cat foo/example.toml # should edit toml file
1818
[package]
1919
name = "foo"
20-
version = "0.0.0"
20+
version = "1.0.0"
2121
edition = "2024"
2222

2323
[[bin]]

packages/tools/src/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import { jsonEdit } from './json-edit';
21
import { replaceFileContent } from './replace-file-content';
32
import { snapTest } from './snap-test';
43

54
const subcommand = process.argv[2];
65

76
switch (subcommand) {
8-
case 'json-edit':
9-
jsonEdit();
10-
break;
117
case 'snap-test':
128
await snapTest();
139
break;
@@ -16,6 +12,6 @@ switch (subcommand) {
1612
break;
1713
default:
1814
console.error(`Unknown subcommand: ${subcommand}`);
19-
console.error('Available subcommands: json-edit, snap-test, replace-file-content, sync-remote');
15+
console.error('Available subcommands: snap-test, replace-file-content');
2016
process.exit(1);
2117
}

packages/tools/src/json-edit.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
import { readFileSync, writeFileSync } from 'node:fs';
22
import { parseArgs } from 'node:util';
33

4-
export function jsonEdit() {
5-
const { positionals } = parseArgs({
6-
allowPositionals: true,
7-
args: process.argv.slice(3),
8-
});
4+
const { positionals } = parseArgs({
5+
allowPositionals: true,
6+
});
97

10-
const filename = positionals[0];
11-
const script = positionals[1];
8+
const filename = positionals[0];
9+
const script = positionals[1];
1210

13-
if (!filename || !script) {
14-
console.error('Usage: tool json-edit <filename> <script>');
15-
console.error('Example: tool json-edit package.json \'_.version = "1.2.3"\'');
16-
process.exit(1);
17-
}
11+
if (!filename || !script) {
12+
console.error('Usage: json-edit <filename> <script>');
13+
console.error('Example: json-edit package.json \'_.version = "1.2.3"\'');
14+
process.exit(1);
15+
}
1816

19-
const json = JSON.parse(readFileSync(filename, 'utf-8'));
20-
const func = new Function('_', script + '; return _;');
21-
const result = func(json);
17+
const json = JSON.parse(readFileSync(filename, 'utf-8'));
18+
const func = new Function('_', script + '; return _;');
19+
const result = func(json);
2220

23-
writeFileSync(filename, JSON.stringify(result, null, 2) + '\n', 'utf-8');
24-
}
21+
writeFileSync(filename, JSON.stringify(result, null, 2) + '\n', 'utf-8');

0 commit comments

Comments
 (0)