react/packages/react-devtools-extensions/deploy.js
Sophie Alpert 767f52237c
Use .slice() for all substring-ing (#26677)
- substr is Annex B
- substring silently flips its arguments if they're in the "wrong order", which is confusing
- slice is better than sliced bread (no pun intended) and also it works the same way on Arrays so there's less to remember

---

> I'd be down to just lint and enforce a single form just for the potential compression savings by using a repeated string.

_Originally posted by @sebmarkbage in https://github.com/facebook/react/pull/26663#discussion_r1170455401_
2023-04-19 14:26:01 -07:00

56 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
'use strict';
const {exec, execSync} = require('child_process');
const {readFileSync, writeFileSync} = require('fs');
const {join} = require('path');
const main = async buildId => {
const root = join(__dirname, buildId);
const buildPath = join(root, 'build');
execSync(`node ${join(root, './build')}`, {
cwd: __dirname,
env: {
...process.env,
NODE_ENV: 'production',
},
stdio: 'inherit',
});
await exec(`cp ${join(root, 'now.json')} ${join(buildPath, 'now.json')}`, {
cwd: root,
});
const file = readFileSync(join(root, 'now.json'));
const json = JSON.parse(file);
const alias = json.alias[0];
const commit = execSync('git rev-parse HEAD').toString().trim().slice(0, 7);
let date = new Date();
date = `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`;
const installationInstructions =
buildId === 'chrome'
? readFileSync(join(__dirname, 'deploy.chrome.html'))
: readFileSync(join(__dirname, 'deploy.firefox.html'));
let html = readFileSync(join(__dirname, 'deploy.html')).toString();
html = html.replace(/%commit%/g, commit);
html = html.replace(/%date%/g, date);
html = html.replace(/%installation%/, installationInstructions);
writeFileSync(join(buildPath, 'index.html'), html);
await exec(`now deploy && now alias ${alias}`, {
cwd: buildPath,
stdio: 'inherit',
});
console.log(`Deployed to https://${alias}.now.sh`);
};
module.exports = main;