move copy assets to build step

This commit is contained in:
Raghunandan
2020-03-13 09:39:15 +01:00
parent b65160dcf5
commit 78321d2718
5 changed files with 23 additions and 42 deletions
+21
View File
@@ -17,6 +17,9 @@
import chalk from 'chalk';
import { Command } from 'commander';
import { spawnSync } from 'child_process';
import fs from 'fs-extra';
import recursive from 'recursive-readdir';
import path from 'path';
export default async (cmd: Command) => {
const args = [
@@ -33,6 +36,7 @@ export default async (cmd: Command) => {
}
try {
await copyStaticAssets();
const result = spawnSync('tsc', args, { stdio: 'inherit' });
if (result.error) {
throw result.error;
@@ -43,3 +47,20 @@ export default async (cmd: Command) => {
process.exit(1);
}
};
const copyStaticAssets = async () => {
const pluginRoot = fs.realpathSync(process.cwd());
const source = path.resolve(pluginRoot, 'src');
const destination = path.resolve(pluginRoot, 'dist', 'cjs');
const assetFiles = await recursive(source, [
'**/*.tsx',
'**/*.ts',
'**/*.js',
]);
assetFiles.forEach(file => {
const fileToBeCopied = file.replace(source, destination);
const dirForFileToBeCopied = path.dirname(fileToBeCopied);
fs.ensureDirSync(dirForFileToBeCopied);
fs.copyFileSync(file, file.replace(source, destination).toString());
});
};
@@ -1,34 +0,0 @@
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);
}
};
-6
View File
@@ -19,7 +19,6 @@ 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';
@@ -45,11 +44,6 @@ const main = (argv: string[]) => {
.description('Build a plugin')
.action(pluginBuild);
program
.command('plugin:copyAssets')
.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:copyAssets && backstage-cli plugin:build",
"build": "backstage-cli plugin:build",
"lint": "backstage-cli plugin:lint",
"test": "backstage-cli plugin:test"
},
+1 -1
View File
@@ -19,7 +19,7 @@
"@material-ui/icons": "^4.9.1"
},
"scripts": {
"build": "backstage-cli plugin:copyAssets && backstage-cli plugin:build",
"build": "backstage-cli plugin:build",
"lint": "backstage-cli plugin:lint",
"test": "backstage-cli plugin:test"
},