-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathpublish-next.js
30 lines (24 loc) · 1.02 KB
/
publish-next.js
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
26
27
28
29
30
#!/usr/bin/env node
const { readFileSync, writeFileSync } = require("fs");
const { resolve } = require("path");
const getPackageJsonPath = projectDir => resolve(projectDir, "package.json");
const getPackageJson = projectDir => {
const packageJsonPath = getPackageJsonPath(projectDir);
return JSON.parse(readFileSync(packageJsonPath, "utf8"));
}
const writePackageJson = (content, projectDir) => {
const packageJsonPath = getPackageJsonPath(projectDir);
writeFileSync(packageJsonPath, JSON.stringify(content, null, 2));
}
const tag = "next";
const projectDir = __dirname;
const packageJson = getPackageJson(projectDir);
const [, , packageVersion = new Date().toISOString().split("T")[0] ] = process.argv;
packageJson.publishConfig = Object.assign(
packageJson.publishConfig || {},
{ tag }
);
const currentVersion = packageJson.version;
const nextVersion = `${currentVersion}-${packageVersion}`;
const newPackageJson = Object.assign(packageJson, { version: nextVersion });
writePackageJson(newPackageJson, projectDir);