2021-09-25 08:43:00 +00:00
|
|
|
/* eslint-disable */
|
2021-04-23 15:06:49 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const child_process = require('child_process');
|
|
|
|
|
2022-05-12 20:10:42 +00:00
|
|
|
const coreDir = path.dirname(require.resolve('@iconify/core/package.json'));
|
2021-04-23 15:06:49 +00:00
|
|
|
|
|
|
|
// List of commands to run
|
|
|
|
const commands = [];
|
|
|
|
|
2021-12-30 08:50:47 +00:00
|
|
|
// Build process
|
2021-04-23 15:06:49 +00:00
|
|
|
const compile = {
|
2021-12-30 08:50:47 +00:00
|
|
|
// Compile @iconify/core
|
2021-04-23 15:06:49 +00:00
|
|
|
core: false,
|
2021-12-30 08:50:47 +00:00
|
|
|
// Compile TypeScript src -> lib
|
2021-04-23 15:06:49 +00:00
|
|
|
lib: true,
|
2021-12-30 08:50:47 +00:00
|
|
|
// Fix types for icon components
|
|
|
|
cleanup: true,
|
|
|
|
// Generate bundle from compiled files lib -> dist
|
2021-04-23 15:06:49 +00:00
|
|
|
dist: true,
|
2021-12-30 08:50:47 +00:00
|
|
|
// Generate TypeScript definitions in dist
|
2021-04-23 15:06:49 +00:00
|
|
|
api: true,
|
|
|
|
};
|
2021-12-30 08:50:47 +00:00
|
|
|
|
2021-04-23 15:06:49 +00:00
|
|
|
process.argv.slice(2).forEach((cmd) => {
|
|
|
|
if (cmd.slice(0, 2) !== '--') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const parts = cmd.slice(2).split('-');
|
|
|
|
if (parts.length === 2) {
|
|
|
|
// Parse 2 part commands like --with-lib
|
|
|
|
const key = parts.pop();
|
|
|
|
if (compile[key] === void 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (parts.shift()) {
|
|
|
|
case 'with':
|
|
|
|
// enable module
|
|
|
|
compile[key] = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'without':
|
|
|
|
// disable module
|
|
|
|
compile[key] = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'only':
|
|
|
|
// disable other modules
|
|
|
|
Object.keys(compile).forEach((key2) => {
|
|
|
|
compile[key2] = key2 === key;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Check if required modules in same monorepo are available
|
|
|
|
const fileExists = (file) => {
|
|
|
|
try {
|
|
|
|
fs.statSync(file);
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2022-05-12 20:10:42 +00:00
|
|
|
if (compile.dist && !fileExists('./lib/icon.js')) {
|
2021-04-23 15:06:49 +00:00
|
|
|
compile.lib = true;
|
|
|
|
}
|
|
|
|
|
2022-05-12 20:10:42 +00:00
|
|
|
if (compile.api && !fileExists('./lib/icon.d.ts')) {
|
2021-04-23 15:06:49 +00:00
|
|
|
compile.lib = true;
|
|
|
|
}
|
|
|
|
|
2022-05-12 20:10:42 +00:00
|
|
|
if (compile.lib && !fileExists(coreDir + '/lib/cache.mjs')) {
|
2021-04-23 15:06:49 +00:00
|
|
|
compile.core = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compile core before compiling this package
|
|
|
|
if (compile.core) {
|
|
|
|
commands.push({
|
|
|
|
cmd: 'npm',
|
|
|
|
args: ['run', 'build'],
|
2022-05-12 20:10:42 +00:00
|
|
|
cwd: coreDir,
|
2021-04-23 15:06:49 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compile other packages
|
|
|
|
Object.keys(compile).forEach((key) => {
|
|
|
|
if (key !== 'core' && compile[key]) {
|
|
|
|
commands.push({
|
|
|
|
cmd: 'npm',
|
|
|
|
args: ['run', 'build:' + key],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run next command
|
|
|
|
*/
|
|
|
|
const next = () => {
|
|
|
|
const item = commands.shift();
|
|
|
|
if (item === void 0) {
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.cwd === void 0) {
|
|
|
|
item.cwd = __dirname;
|
|
|
|
}
|
|
|
|
|
|
|
|
const result = child_process.spawnSync(item.cmd, item.args, {
|
|
|
|
cwd: item.cwd,
|
|
|
|
stdio: 'inherit',
|
|
|
|
});
|
|
|
|
|
|
|
|
if (result.status === 0) {
|
|
|
|
process.nextTick(next);
|
|
|
|
} else {
|
|
|
|
process.exit(result.status);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
next();
|