|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import { Command } from 'commander'; |
18 | | -import fs from 'fs-extra'; |
19 | | -import path from 'path'; |
20 | | -import recursive from 'recursive-readdir'; |
21 | | -import { run } from '../../helpers/run'; |
| 17 | +const rollup = require('rollup'); // "import" is not working for some reason... |
| 18 | +import rollupConfig from './rollup.config'; |
22 | 19 |
|
23 | | -const copyStaticAssets = async () => { |
24 | | - const pluginRoot = fs.realpathSync(process.cwd()); |
25 | | - const source = path.resolve(pluginRoot, 'src'); |
26 | | - const destination = path.resolve(pluginRoot, 'dist', 'cjs'); |
27 | | - const assetFiles = await recursive(source, [ |
28 | | - '**/*.tsx', |
29 | | - '**/*.ts', |
30 | | - '**/*.js', |
31 | | - ]); |
32 | | - assetFiles.forEach(file => { |
33 | | - const fileToBeCopied = file.replace(source, destination); |
34 | | - const dirForFileToBeCopied = path.dirname(fileToBeCopied); |
35 | | - fs.ensureDirSync(dirForFileToBeCopied); |
36 | | - fs.copyFileSync(file, file.replace(source, destination).toString()); |
37 | | - }); |
38 | | -}; |
39 | | - |
40 | | -export default async (cmd: Command) => { |
41 | | - const args = [ |
42 | | - '--outDir', |
43 | | - 'dist/cjs', |
44 | | - '--noEmit', |
45 | | - 'false', |
46 | | - '--module', |
47 | | - 'CommonJS', |
48 | | - ]; |
49 | | - |
50 | | - if (cmd.watch) { |
51 | | - args.push('--watch'); |
52 | | - } |
| 20 | +export default async () => { |
| 21 | + const inputOptions = { |
| 22 | + input: rollupConfig.input, |
| 23 | + plugins: rollupConfig.plugins, |
| 24 | + }; |
| 25 | + const outputOptions = rollupConfig.output; |
53 | 26 |
|
54 | | - await copyStaticAssets(); |
55 | | - await run('tsc', args); |
| 27 | + const bundle = await rollup.rollup(inputOptions); |
| 28 | + await bundle.generate(outputOptions); |
| 29 | + await bundle.write(outputOptions); |
56 | 30 | }; |
0 commit comments