123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #!/usr/bin/env node
- const babel = require('@babel/cli/lib/babel/dir').default;
- const execSync = require('@polkadot/dev/scripts/execSync');
- const cpx = require('cpx');
- const fs = require('fs');
- const mkdirp = require('mkdirp');
- const path = require('path');
- const IS_LIVE = !(process.env.IS_LIVE === false || process.env.IS_LIVE === 'false');
- const CPX = ['css', 'gif', 'hbs', 'jpg', 'js', 'png', 'svg', 'd.ts']
- .map((ext) => `src/**/*.${ext}`)
- .concat('package.json');
- console.log('$ polkadot-dev-build-ts', process.argv.slice(2).join(' '));
- function buildWebpack () {
- execSync('yarn polkadot-exec-webpack --config webpack.config.js --mode production');
- }
- async function buildBabel (dir) {
- await babel({
- babelOptions: {
- configFile: path.join(process.cwd(), '../../babel.config.js')
- },
- cliOptions: {
- extensions: ['.ts', '.tsx'],
- filenames: ['src'],
- ignore: '**/*.d.ts',
- outDir: path.join(process.cwd(), 'build')
- }
- });
- [...CPX]
- .concat(`../../build/${dir}/src/**/*.d.ts`, `../../build/packages/${dir}/src/**/*.d.ts`)
- .forEach((src) => cpx.copySync(src, 'build'));
- }
- async function buildJs (dir) {
- if (!fs.existsSync(path.join(process.cwd(), '.skip-build'))) {
- const { name, version } = require(path.join(process.cwd(), './package.json'));
- if (!name.startsWith('@polkadot/')) {
- return;
- }
- console.log(`*** ${name} ${version}`);
- mkdirp.sync('build');
- if (fs.existsSync(path.join(process.cwd(), 'public'))) {
- buildWebpack(dir);
-
- } else if (IS_LIVE) {
- await buildBabel(dir);
- }
- console.log();
- }
- }
- async function main () {
- execSync('yarn polkadot-dev-clean-build');
- console.log('IS_LIVE:', process.env.IS_LIVE);
-
- process.chdir('packages');
-
-
-
-
-
- if (IS_LIVE) {
- execSync('yarn tsc --emitDeclarationOnly --outdir ./build');
- }
- const dirs = fs
- .readdirSync('.')
- .filter((dir) => fs.statSync(dir).isDirectory() && fs.existsSync(path.join(process.cwd(), dir, 'src')));
- for (const dir of dirs) {
- process.chdir(dir);
- await buildJs(dir);
- process.chdir('..');
- }
- process.chdir('..');
- }
- main().catch((error) => {
- console.error(error);
- process.exit(-1);
- });
|