2019-01-24 10:06:21 +08:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
2019-08-14 12:59:07 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
2019-01-24 10:06:21 +08:00
|
|
|
const chalk = require('chalk');
|
2019-08-14 08:58:03 +08:00
|
|
|
const {execSync} = require('child_process');
|
|
|
|
|
const {existsSync} = require('fs');
|
|
|
|
|
const {isAbsolute, join, relative} = require('path');
|
|
|
|
|
const {argv} = require('yargs');
|
2019-08-14 13:15:38 +08:00
|
|
|
const build = require('../build');
|
2019-01-24 10:06:21 +08:00
|
|
|
|
|
|
|
|
const main = async () => {
|
2019-08-14 08:58:03 +08:00
|
|
|
const {crx, keyPath} = argv;
|
2019-06-19 06:44:22 +08:00
|
|
|
|
|
|
|
|
if (crx) {
|
|
|
|
|
if (!keyPath || !existsSync(keyPath)) {
|
|
|
|
|
console.error('Must specify a key file (.pem) to build CRX');
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 23:52:21 +08:00
|
|
|
await build('chrome');
|
2019-04-13 04:46:05 +08:00
|
|
|
|
2019-06-19 06:44:22 +08:00
|
|
|
if (crx) {
|
|
|
|
|
const cwd = join(__dirname, 'build');
|
2019-06-19 09:40:05 +08:00
|
|
|
|
|
|
|
|
let safeKeyPath = keyPath;
|
|
|
|
|
if (!isAbsolute(keyPath)) {
|
|
|
|
|
safeKeyPath = join(relative(cwd, process.cwd()), keyPath);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 08:01:26 +08:00
|
|
|
const crxPath = join(
|
|
|
|
|
__dirname,
|
|
|
|
|
'..',
|
|
|
|
|
'..',
|
|
|
|
|
'..',
|
|
|
|
|
'node_modules',
|
|
|
|
|
'.bin',
|
|
|
|
|
'crx'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
execSync(
|
|
|
|
|
`${crxPath} pack ./unpacked -o ReactDevTools.crx -p ${safeKeyPath}`,
|
|
|
|
|
{
|
|
|
|
|
cwd,
|
|
|
|
|
}
|
|
|
|
|
);
|
2019-06-19 06:44:22 +08:00
|
|
|
}
|
|
|
|
|
|
2019-01-24 10:06:21 +08:00
|
|
|
console.log(chalk.green('\nThe Chrome extension has been built!'));
|
|
|
|
|
console.log(chalk.green('You can test this build by running:'));
|
|
|
|
|
console.log(chalk.gray('\n# From the react-devtools root directory:'));
|
|
|
|
|
console.log('yarn run test:chrome');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
main();
|