Skip to content

Commit

Permalink
fix(plugin): generate plugin tarball without removing ./build dir, ad…
Browse files Browse the repository at this point in the history
…d pack command

build command now build the plugin, copies build into temp dir, create tarball, removes the temp dir.
build dir remains
  • Loading branch information
dmitry-yudakov committed Oct 25, 2023
1 parent f42c132 commit 3ae0f06
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/sdk/bin/momentum-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const DEFAULT_PORT = 3001;

const args = process.argv.slice(2);
const scriptIndex = args.findIndex(
(x) => x === 'build' || x === 'start' || x === 'test' || x === 'start:plugin'
(x) => x === 'build' || x === 'pack' || x === 'start' || x === 'test' || x === 'start:plugin'
);
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];

Expand Down Expand Up @@ -41,6 +41,8 @@ switch (script) {
spawnProcess('craco', processArgs, env);
break;
}
case 'pack':
break;
default:
console.log(`Unknown script "${script}".`);
console.log('Perhaps you need to update @momentum-xyz/sdk?');
Expand All @@ -49,6 +51,7 @@ switch (script) {

switch (script) {
case 'build':
case 'pack':
generateAndStoreManifest();
break;
default:
Expand Down Expand Up @@ -109,9 +112,17 @@ function generateAndStoreManifest() {

const versionedDir = `./${name}-${version}`;

fs.renameSync(BUILD_DIR, versionedDir);
console.log('[momentum-plugin] Plugin build stored in', BUILD_DIR);
console.log('[momentum-plugin] Temp copy plugin build to', versionedDir);
fs.cpSync(BUILD_DIR, versionedDir, {
force: true,
preserveTimestamps: true,
recursive: true
});

console.log('[momentum-plugin] Compress plugin build to', `${versionedDir}.tar.gz`);
spawnProcess('tar', ['-czf', `${versionedDir}.tar.gz`, versionedDir], {});
console.log('[momentum-plugin] Plugin tarball generated: ', `${versionedDir}.tar.gz`);

console.log('[momentum-plugin] Removing temp dir', versionedDir);
fs.rmSync(versionedDir, {recursive: true});
}

0 comments on commit 3ae0f06

Please sign in to comment.