Performance improvements for "build-plugin" task
Summary: Few improvements for "build-plugin" task which together with Sandcastle command changes (D26872427) helps to build all plugins in CI ~30% faster if most of them has not changed (which is usually the case): 1) compute package checksum in the same script to not call additional yarn scripts for each plugin 2) avoid packaging plugin if it's checksum has not changed since last release Reviewed By: mweststrate Differential Revision: D26872253 fbshipit-source-id: 968102d32a1550ea7503f1169f0ef2863296383f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5df0fd6e52
commit
baeb8ba5be
@@ -12,27 +12,68 @@ import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import {execSync} from 'child_process';
|
||||
import {resolvePluginDir} from './workspaces';
|
||||
import {runBuild, computePackageChecksum} from 'flipper-pkg-lib';
|
||||
import yargs from 'yargs';
|
||||
|
||||
async function buildPlugin(argv: string[]) {
|
||||
const pluginName = argv[2];
|
||||
const argv = yargs
|
||||
.usage('yarn build-plugin [args]')
|
||||
.version(false)
|
||||
.options({
|
||||
plugin: {
|
||||
description:
|
||||
'Plugin ID or path relative to "plugins" dir (e.g. "layout")',
|
||||
type: 'string',
|
||||
demandOption: true,
|
||||
alias: 'p',
|
||||
},
|
||||
version: {
|
||||
description: 'New version to set',
|
||||
type: 'string',
|
||||
alias: 'v',
|
||||
},
|
||||
checksum: {
|
||||
description:
|
||||
'Checksum of the previous plugin package which is used to determine whether the plugin is changed or not. If it is not changed, it will not be packaged.',
|
||||
type: 'string',
|
||||
alias: 'c',
|
||||
},
|
||||
output: {
|
||||
description: 'Where to save the plugin package',
|
||||
type: 'string',
|
||||
alias: 'o',
|
||||
},
|
||||
})
|
||||
.help()
|
||||
.strict()
|
||||
.parse(process.argv.slice(1));
|
||||
|
||||
async function buildPlugin() {
|
||||
const pluginName = argv.plugin;
|
||||
const previousChecksum = argv.checksum;
|
||||
const pluginDir = await resolvePluginDir(pluginName);
|
||||
const outputFileArg = argv.length > 3 ? argv[3] : null;
|
||||
const outputFile = outputFileArg
|
||||
? path.resolve(outputFileArg)
|
||||
: path.join(
|
||||
distDir,
|
||||
'plugins',
|
||||
path.relative(pluginsDir, pluginDir) + '.tgz',
|
||||
);
|
||||
await fs.ensureDir(path.dirname(outputFile));
|
||||
await fs.remove(outputFile);
|
||||
const bundleCmd = `yarn flipper-pkg bundle "${pluginDir}" --production`;
|
||||
const packCmd = `yarn pack --cwd "${pluginDir}" --filename ${outputFile}`;
|
||||
execSync(bundleCmd, {cwd: rootDir, stdio: 'inherit'});
|
||||
execSync(packCmd, {cwd: rootDir, stdio: 'inherit'});
|
||||
const outputFileArg = argv.output;
|
||||
await runBuild(pluginDir, false);
|
||||
const checksum = await computePackageChecksum(pluginDir);
|
||||
if (previousChecksum !== checksum && argv.version) {
|
||||
console.log(`Plugin changed. Packaging new version ${argv.version}...`);
|
||||
const outputFile = outputFileArg
|
||||
? path.resolve(outputFileArg)
|
||||
: path.join(
|
||||
distDir,
|
||||
'plugins',
|
||||
path.relative(pluginsDir, pluginDir) + '.tgz',
|
||||
);
|
||||
await fs.ensureDir(path.dirname(outputFile));
|
||||
await fs.remove(outputFile);
|
||||
const versionCmd = `yarn version --cwd "${pluginDir}" --new-version ${argv.version}`;
|
||||
execSync(versionCmd, {cwd: rootDir, stdio: 'inherit'});
|
||||
const packCmd = `yarn pack --cwd "${pluginDir}" --filename ${outputFile}`;
|
||||
execSync(packCmd, {cwd: rootDir, stdio: 'inherit'});
|
||||
await fs.writeFile(outputFile + '.hash', checksum);
|
||||
}
|
||||
}
|
||||
|
||||
buildPlugin(process.argv)
|
||||
buildPlugin()
|
||||
.then(() => {
|
||||
process.exit(0);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user