@tetcoin/dev
Version:
A collection of shared CI scripts and development environment used by @tetcoin projects
89 lines (67 loc) • 2.23 kB
JavaScript
// Copyright 2017-2020 @polkadot/dev authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
const babel = require('@babel/cli/lib/babel/dir').default;
const execSync = require('./execSync');
const cpx = require('cpx');
const fs = require('fs');
const mkdirp = require('mkdirp');
const path = require('path');
const CPX = ['css', 'gif', 'hbs', 'jpg', 'js', 'png', 'svg', 'd.ts']
.map((ext) => `src/**/*.${ext}`)
.concat('package.json');
console.log('$ tetcoin-dev-build-ts', process.argv.slice(2).join(' '));
function buildWebpack () {
execSync('yarn tetcoin-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('@tetcoin/')) {
return;
}
console.log(`*** ${name} ${version}`);
mkdirp.sync('build');
if (fs.existsSync(path.join(process.cwd(), 'public'))) {
buildWebpack(dir);
} else {
await buildBabel(dir);
}
console.log();
}
}
async function main () {
execSync('yarn tetcoin-dev-clean-build');
process.chdir('packages');
execSync('yarn tetcoin-exec-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);
});