add copy assets to cli
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import chalk from 'chalk';
|
||||
import fs from 'fs-extra';
|
||||
import recursive from 'recursive-readdir';
|
||||
import path from 'path';
|
||||
|
||||
const copyStaticAssets = async (source: string, destination: string) => {
|
||||
const assetFiles = await recursive(source, [
|
||||
'**/*.tsx',
|
||||
'**/*.ts',
|
||||
'**/*.js',
|
||||
]);
|
||||
assetFiles.forEach(file => {
|
||||
const fileToBeCopied = file.replace(source, destination);
|
||||
const dirForFileToBeCopied = fileToBeCopied.replace(
|
||||
path.basename(fileToBeCopied),
|
||||
'',
|
||||
);
|
||||
fs.ensureDirSync(dirForFileToBeCopied);
|
||||
fs.copyFileSync(file, file.replace(source, destination));
|
||||
});
|
||||
};
|
||||
|
||||
export default async () => {
|
||||
try {
|
||||
const pluginRoot = fs.realpathSync(process.cwd());
|
||||
const pluginSource = path.resolve(pluginRoot, 'src');
|
||||
const pluginDist = path.resolve(pluginRoot, 'dist', 'cjs');
|
||||
await copyStaticAssets(pluginSource, pluginDist);
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
process.stderr.write(`${chalk.red(error.message)}\n`);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
@@ -19,6 +19,7 @@ import chalk from 'chalk';
|
||||
import fs from 'fs';
|
||||
import createPluginCommand from './commands/createPlugin';
|
||||
import watch from './commands/watch-deps';
|
||||
import pluginCopyAssets from './commands/plugin/copyAssets';
|
||||
import pluginBuild from './commands/plugin/build';
|
||||
import pluginLint from './commands/plugin/lint';
|
||||
import pluginServe from './commands/plugin/serve';
|
||||
@@ -44,6 +45,12 @@ const main = (argv: string[]) => {
|
||||
.description('Build a plugin')
|
||||
.action(pluginBuild);
|
||||
|
||||
program
|
||||
.command('plugin:copyAssets')
|
||||
.option('--watch', 'Enable watch mode')
|
||||
.description('Copy assets for a plugin')
|
||||
.action(pluginCopyAssets);
|
||||
|
||||
program
|
||||
.command('plugin:lint')
|
||||
.option('--fix', 'Attempt to automatically fix violations')
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"license": "Apache-2.0",
|
||||
"private": false,
|
||||
"scripts": {
|
||||
"build": "backstage-cli plugin:build",
|
||||
"build": "backstage-cli plugin:build && backstage-cli plugin:copyAssets",
|
||||
"lint": "backstage-cli plugin:lint",
|
||||
"test": "backstage-cli plugin:test"
|
||||
},
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
"@material-ui/icons": "^4.9.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "backstage-cli plugin:build",
|
||||
"build": "backstage-cli plugin:copyAssets && backstage-cli plugin:build",
|
||||
"lint": "backstage-cli plugin:lint",
|
||||
"test": "backstage-cli plugin:test"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user