|
| 1 | +// const path = require("path"); |
| 2 | +// const jsonfile = require("jsonfile"); |
| 3 | +// const semver = require("semver"); |
| 4 | +// const execSync = require("child_process").execSync; |
| 5 | +// const rootDir = path.resolve(__dirname, ".."); |
| 6 | + |
| 7 | +// const args = process.argv.slice(2); |
| 8 | + |
| 9 | +// /** |
| 10 | +// * @param {*} cond |
| 11 | +// * @param {string} message |
| 12 | +// * @returns {asserts cond} |
| 13 | +// */ |
| 14 | +// function invariant(cond, message) { |
| 15 | +// if (!cond) throw new Error(message); |
| 16 | +// } |
| 17 | + |
| 18 | +// /** |
| 19 | +// * @returns {string} |
| 20 | +// */ |
| 21 | +// function getTaggedVersion() { |
| 22 | +// let output = execSync("git tag --list --points-at HEAD").toString(); |
| 23 | +// return output.replace(/^v|\n+$/g, ""); |
| 24 | +// } |
| 25 | + |
| 26 | +// /** |
| 27 | +// * |
| 28 | +// * @param {SemverRelease} [semverRelease] |
| 29 | +// */ |
| 30 | +// function bumpVersion(semverRelease = "patch") { |
| 31 | +// // lerna version --no-push --exact |
| 32 | +// execSync(`yarn lerna version ${semverRelease} --no-push --exact --yes`); |
| 33 | +// } |
| 34 | + |
| 35 | +// /** |
| 36 | +// * @param {string} packageName |
| 37 | +// * @param {string|number} version |
| 38 | +// */ |
| 39 | +// async function ensureBuildVersion(packageName, version) { |
| 40 | +// let file = path.join(rootDir, "packages", packageName, "package.json"); |
| 41 | +// let json = await jsonfile.readFile(file); |
| 42 | +// invariant( |
| 43 | +// json.version === version, |
| 44 | +// `Package ${packageName} is on version ${json.version}, but should be on ${version}` |
| 45 | +// ); |
| 46 | +// } |
| 47 | + |
| 48 | +// /** |
| 49 | +// * @param {string} packageName |
| 50 | +// * @param {string} tag |
| 51 | +// */ |
| 52 | +// function publishBuild(packageName, tag) { |
| 53 | +// let buildDir = path.join(rootDir, "packages", packageName); |
| 54 | +// console.log(); |
| 55 | +// console.log(` npm publish ${buildDir} --tag ${tag}`); |
| 56 | +// console.log(); |
| 57 | +// execSync(`npm publish ${buildDir} --tag ${tag}`, { stdio: "inherit" }); |
| 58 | +// } |
| 59 | + |
| 60 | +// /** |
| 61 | +// * @param {SemverRelease|null} [semverRelease] |
| 62 | +// * @returns {Promise<1 | 0>} |
| 63 | +// */ |
| 64 | +// async function run(semverRelease) { |
| 65 | +// try { |
| 66 | +// // 0. Ensure we are in CI. We don't do this manually |
| 67 | +// invariant( |
| 68 | +// process.env.CI, |
| 69 | +// `You should always run the publish script from the CI environment!` |
| 70 | +// ); |
| 71 | + |
| 72 | +// // 1. Update the release version with a git tag + commit |
| 73 | +// bumpVersion(semverRelease); |
| 74 | + |
| 75 | +// // 2. Get the current tag, which has the release version number |
| 76 | +// let version = getTaggedVersion(); |
| 77 | +// invariant( |
| 78 | +// version !== "", |
| 79 | +// "Missing release version. Run the version script first." |
| 80 | +// ); |
| 81 | + |
| 82 | +// // 3. Determine the appropriate npm tag to use |
| 83 | +// let tag = semver.prerelease(version) == null ? "latest" : null; |
| 84 | + |
| 85 | +// console.log(); |
| 86 | +// console.log( |
| 87 | +// ` Publishing version ${version} to npm` + tag ? ` with tag "${tag}"` : "" |
| 88 | +// ); |
| 89 | + |
| 90 | +// // 3. Ensure build versions match the release version |
| 91 | +// await ensureBuildVersion("react-router", version); |
| 92 | +// await ensureBuildVersion("react-router-dom", version); |
| 93 | +// await ensureBuildVersion("react-router-native", version); |
| 94 | + |
| 95 | +// // 4. Publish to npm |
| 96 | +// publishBuild("react-router", tag); |
| 97 | +// publishBuild("react-router-dom", tag); |
| 98 | +// publishBuild("react-router-native", tag); |
| 99 | +// } catch (error) { |
| 100 | +// console.log(); |
| 101 | +// console.error(` ${error.message}`); |
| 102 | +// console.log(); |
| 103 | +// return 1; |
| 104 | +// } |
| 105 | + |
| 106 | +// return 0; |
| 107 | +// } |
| 108 | + |
| 109 | +// run().then(code => { |
| 110 | +// process.exit(code); |
| 111 | +// }); |
| 112 | + |
| 113 | +// /** |
| 114 | +// * @typedef {'major'|'minor'|'patch'|'premajor'|'preminor'|'prepatch'|'prerelease'} SemverRelease |
| 115 | +// */ |
0 commit comments