From b5d8f6c63d09f70019f9cbf4fa8140c06c12217b Mon Sep 17 00:00:00 2001 From: Anton Nikolaev Date: Thu, 13 May 2021 05:31:13 -0700 Subject: [PATCH] Output unpacked plugin dir in addition to tar from "build-plugin" command Summary: "plugin-build" command will produce dir with unpacked plugin sources in addition to tar package. This is required because for publishing to Marketplace we need to retrieve few files from the output package, like "readme.md" and "package.json" and it's better to have it already unpacked rather than pack and then unpack to get these files. Reviewed By: passy Differential Revision: D28409930 fbshipit-source-id: 51c8eeb848a72850a2f126eb91a563d52851ed41 --- desktop/scripts/build-plugin.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/desktop/scripts/build-plugin.ts b/desktop/scripts/build-plugin.ts index c2aa8aac3..e2e77a1f6 100644 --- a/desktop/scripts/build-plugin.ts +++ b/desktop/scripts/build-plugin.ts @@ -48,6 +48,11 @@ const argv = yargs type: 'string', alias: 'o', }, + 'output-unpacked': { + description: 'Where to save the unpacked plugin package', + type: 'string', + alias: 'ou', + }, }) .help() .strict() @@ -58,6 +63,7 @@ async function buildPlugin() { const previousChecksum = argv.checksum; const pluginDir = await resolvePluginDir(pluginName); const outputFileArg = argv.output; + const outputUnpackedArg = argv['output-unpacked']; const minFlipperVersion = argv['min-flipper-version']; const packageJsonPath = path.join(pluginDir, 'package.json'); await runBuild(pluginDir, false); @@ -71,6 +77,9 @@ async function buildPlugin() { 'plugins', path.relative(pluginsDir, pluginDir) + '.tgz', ); + const outputUnpackedDir = outputUnpackedArg + ? path.resolve(outputUnpackedArg) + : path.join(distDir, 'plugins', path.relative(pluginsDir, pluginDir)); await fs.ensureDir(path.dirname(outputFile)); await fs.remove(outputFile); const {name: tmpDir} = tmp.dirSync(); @@ -84,12 +93,13 @@ async function buildPlugin() { } packageJson.engines.flipper = minFlipperVersion; } - if (argv.version) { - packageJson.version = argv.version; - } + packageJson.version = argv.version; await fs.writeJson(packageJsonPath, packageJson, {spaces: 2}); const packCmd = `yarn pack --cwd "${pluginDir}" --filename ${outputFile}`; execSync(packCmd, {cwd: rootDir, stdio: 'inherit'}); + await fs.remove(outputUnpackedDir); + await fs.copy(pluginDir, outputUnpackedDir, {overwrite: true}); + console.log(`Unpacked package saved to ${outputUnpackedDir}`); } finally { await fs.move(packageJsonBackupPath, packageJsonPath, {overwrite: true}); await fs.remove(tmpDir);