Skip to content

Commit

Permalink
chore(scripts/version): bump remix versions for examples (remix-run#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcansh authored Nov 19, 2021
1 parent 940c1bd commit 3ed38d6
Showing 1 changed file with 55 additions and 9 deletions.
64 changes: 55 additions & 9 deletions scripts/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@ const Confirm = require("prompt-confirm");
const jsonfile = require("jsonfile");
const semver = require("semver");

const packagesDir = path.resolve(__dirname, "../packages");

function packageJson(packageName) {
return path.join(packagesDir, packageName, "package.json");
let rootDir = path.resolve(__dirname, "..");
let examplesDir = path.resolve(rootDir, "examples");

let adapters = ["architect", "express", "netlify", "vercel"];
let runtimes = ["cloudflare-workers", "node"];
let core = ["dev", "server-runtime", "react"];
let allPackages = [...adapters, ...runtimes, ...core];

/**
* @param {string} packageName
* @param {string} [directory]
* @returns {string}
*/
function packageJson(packageName, directory) {
return path.join(rootDir, directory, packageName, "package.json");
}

function ensureCleanWorkingDirectory() {
Expand Down Expand Up @@ -52,13 +63,13 @@ async function prompt(question) {
}

async function getPackageVersion(packageName) {
let file = packageJson(packageName);
let file = packageJson(packageName, "packages");
let json = await jsonfile.readFile(file);
return json.version;
}

async function updatePackageConfig(packageName, transform) {
let file = packageJson(packageName);
let file = packageJson(packageName, "packages");
let json = await jsonfile.readFile(file);
transform(json);
await jsonfile.writeFile(file, json, { spaces: 2 });
Expand All @@ -78,6 +89,17 @@ async function updateChangesVersion(version, date) {
await fsp.writeFile(file, updated);
}

/**
* @param {string} example
* @param {(json: string) => any} transform
*/
async function updateExamplesPackageConfig(example, transform) {
let file = packageJson(example, "examples");
let json = await jsonfile.readFile(file);
transform(json);
await jsonfile.writeFile(file, json, { spaces: 2 });
}

async function run(args) {
let givenVersion = args[0];
let prereleaseId = args[1];
Expand All @@ -104,7 +126,7 @@ async function run(args) {
console.log(chalk.green(` Updated remix to version ${nextVersion}`));

// Update remix-dev, remix-server-runtime, and remix-react versions
for (let name of ["dev", "server-runtime", "react"]) {
for (let name of core) {
await updatePackageConfig(`remix-${name}`, config => {
config.version = nextVersion;
});
Expand All @@ -114,7 +136,7 @@ async function run(args) {
}

// Update remix-cloudflare-workers and remix-node versions + server-runtime dep
for (let name of ["cloudflare-workers", "node"]) {
for (let name of runtimes) {
await updatePackageConfig(`remix-${name}`, config => {
config.version = nextVersion;
config.dependencies["@remix-run/server-runtime"] = nextVersion;
Expand All @@ -125,7 +147,7 @@ async function run(args) {
}

// Update remix-* node server versions + remix-node dep
for (let name of ["architect", "express", "vercel", "netlify"]) {
for (let name of adapters) {
await updatePackageConfig(`remix-${name}`, config => {
config.version = nextVersion;
config.dependencies["@remix-run/node"] = nextVersion;
Expand Down Expand Up @@ -158,6 +180,30 @@ async function run(args) {
);
}

// Update remix versions in the examples
let examples = await fsp.readdir(examplesDir);
for (let example of examples) {
let stat = await fsp.stat(path.join(examplesDir, example));
if (!stat.isDirectory()) continue;

await updateExamplesPackageConfig(example, config => {
if (config.dependencies["remix"]) {
config.dependencies["remix"] = nextVersion;
}

for (let package of allPackages) {
if (config.dependencies[`@remix-run/${package}`]) {
config.dependencies[`@remix-run/${package}`] = nextVersion;
}
if (config.devDependencies[`@remix-run/${package}`]) {
config.devDependencies[`@remix-run/${package}`] = nextVersion;
}
}
});

console.log(chalk.green(` Updated remix versions in ${example} example`));
}

// Commit and tag
execSync(`git commit --all --message="Version ${nextVersion}"`);
execSync(`git tag -a -m "Version ${nextVersion}" v${nextVersion}`);
Expand Down

0 comments on commit 3ed38d6

Please sign in to comment.