-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathsetup.js
More file actions
25 lines (24 loc) · 1.04 KB
/
setup.js
File metadata and controls
25 lines (24 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// @ts-check
const fs = require("fs");
const path = require("path");
const args = process.argv.slice(2);
const wasmPath = path.join(__dirname, "../../target/wasm32-unknown-unknown/release/dprint_plugin_typescript.wasm");
fs.copyFileSync(wasmPath, path.join(__dirname, "plugin.wasm"));
if (args.length > 0) {
// update the version based on the first argument
const packageJsonPath = path.join(__dirname, "package.json");
const packageJsonText = fs.readFileSync(packageJsonPath, "utf8");
const packageJson = JSON.parse(packageJsonText);
if (args[0] === "sync-version") {
const cargoTomlPath = path.join(__dirname, "../../Cargo.toml");
const cargoTomlText = fs.readFileSync(cargoTomlPath, "utf8");
const versionMatch = cargoTomlText.match(/^version\s*=\s*"([^"]+)"/m);
if (!versionMatch) {
throw new Error("Could not find version in Cargo.toml");
}
packageJson.version = versionMatch[1];
} else {
packageJson.version = args[0];
}
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, undefined, 2) + "\n");
}