2
0
mirror of https://github.com/iconify/iconify.git synced 2025-01-06 07:20:40 +00:00

Automatically build missing dependencies when building packages

This commit is contained in:
Vjacheslav Trushkin 2020-05-04 13:20:10 +03:00
parent 20ccec0f2e
commit 0230e952ca
6 changed files with 225 additions and 16 deletions

View File

@ -1,6 +1,9 @@
const fs = require('fs');
const path = require('path');
const child_process = require('child_process');
const packagesDir = path.dirname(__dirname);
// List of commands to run
const commands = [];
@ -11,7 +14,7 @@ const compile = {
lib: true,
dist: true,
};
process.argv.slice(2).forEach(cmd => {
process.argv.slice(2).forEach((cmd) => {
if (cmd.slice(0, 2) !== '--') {
return;
}
@ -35,7 +38,7 @@ process.argv.slice(2).forEach(cmd => {
case 'only':
// disable other modules
Object.keys(compile).forEach(key2 => {
Object.keys(compile).forEach((key2) => {
compile[key2] = key2 === key;
});
break;
@ -43,6 +46,32 @@ process.argv.slice(2).forEach(cmd => {
}
});
// Check if required modules in same monorepo are available
const fileExists = (file) => {
try {
fs.statSync(file);
} catch (e) {
return false;
}
return true;
};
if (compile.dist && !fileExists(packagesDir + '/browser-tests/lib/node.js')) {
compile.lib = true;
}
if (
compile.lib &&
(!fileExists(packagesDir + '/iconify/dist/iconify.js') ||
!fileExists(packagesDir + '/iconify/lib/iconify.js'))
) {
compile.iconify = true;
}
if (compile.iconify && !fileExists(packagesDir + '/core/lib/modules.js')) {
compile.core = true;
}
// Compile core before compiling this package
if (compile.core) {
commands.push({
@ -61,7 +90,7 @@ if (compile.iconify || compile.core) {
}
// Compile other packages
Object.keys(compile).forEach(key => {
Object.keys(compile).forEach((key) => {
if (key !== 'core' && key !== 'iconify' && compile[key]) {
commands.push({
cmd: 'npm',

View File

@ -1,6 +1,9 @@
const fs = require('fs');
const path = require('path');
const child_process = require('child_process');
const packagesDir = path.dirname(__dirname);
// List of commands to run
const commands = [];
@ -11,7 +14,7 @@ const compile = {
dist: true,
api: true,
};
process.argv.slice(2).forEach(cmd => {
process.argv.slice(2).forEach((cmd) => {
if (cmd.slice(0, 2) !== '--') {
return;
}
@ -35,7 +38,7 @@ process.argv.slice(2).forEach(cmd => {
case 'only':
// disable other modules
Object.keys(compile).forEach(key2 => {
Object.keys(compile).forEach((key2) => {
compile[key2] = key2 === key;
});
break;
@ -43,17 +46,39 @@ process.argv.slice(2).forEach(cmd => {
}
});
// Check if required modules in same monorepo are available
const fileExists = (file) => {
try {
fs.statSync(file);
} catch (e) {
return false;
}
return true;
};
if (compile.dist && !fileExists(packagesDir + '/iconify/lib/iconify.js')) {
compile.lib = true;
}
if (compile.api && !fileExists(packagesDir + '/iconify/lib/iconify.d.ts')) {
compile.lib = true;
}
if (compile.lib && !fileExists(packagesDir + '/core/lib/modules.js')) {
compile.core = true;
}
// Compile core before compiling this package
if (compile.core) {
commands.push({
cmd: 'npm',
args: ['run', 'build'],
cwd: path.dirname(__dirname) + '/core',
cwd: packagesDir + '/core',
});
}
// Compile other packages
Object.keys(compile).forEach(key => {
Object.keys(compile).forEach((key) => {
if (key !== 'core' && compile[key]) {
commands.push({
cmd: 'npm',

View File

@ -1,6 +1,9 @@
const fs = require('fs');
const path = require('path');
const child_process = require('child_process');
const packagesDir = path.dirname(__dirname);
// List of commands to run
const commands = [];
@ -11,7 +14,7 @@ const compile = {
dist: true,
api: true,
};
process.argv.slice(2).forEach(cmd => {
process.argv.slice(2).forEach((cmd) => {
if (cmd.slice(0, 2) !== '--') {
return;
}
@ -35,7 +38,7 @@ process.argv.slice(2).forEach(cmd => {
case 'only':
// disable other modules
Object.keys(compile).forEach(key2 => {
Object.keys(compile).forEach((key2) => {
compile[key2] = key2 === key;
});
break;
@ -43,17 +46,39 @@ process.argv.slice(2).forEach(cmd => {
}
});
// Check if required modules in same monorepo are available
const fileExists = (file) => {
try {
fs.statSync(file);
} catch (e) {
return false;
}
return true;
};
if (compile.dist && !fileExists(packagesDir + '/react/lib/icon.js')) {
compile.lib = true;
}
if (compile.api && !fileExists(packagesDir + '/react/lib/icon.d.ts')) {
compile.lib = true;
}
if (compile.lib && !fileExists(packagesDir + '/core/lib/modules.js')) {
compile.core = true;
}
// Compile core before compiling this package
if (compile.core) {
commands.push({
cmd: 'npm',
args: ['run', 'build'],
cwd: path.dirname(__dirname) + '/core',
cwd: packagesDir + '/core',
});
}
// Compile other packages
Object.keys(compile).forEach(key => {
Object.keys(compile).forEach((key) => {
if (key !== 'core' && compile[key]) {
commands.push({
cmd: 'npm',

104
packages/svelte/build.js Normal file
View File

@ -0,0 +1,104 @@
const fs = require('fs');
const path = require('path');
const child_process = require('child_process');
const packagesDir = path.dirname(__dirname);
// List of commands to run
const commands = [];
// Parse command line
const compile = {
core: false,
dist: true,
};
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;
};
if (compile.dist && !fileExists(packagesDir + '/core/lib/modules.js')) {
compile.core = true;
}
// Compile core before compiling this package
if (compile.core) {
commands.push({
cmd: 'npm',
args: ['run', 'build'],
cwd: packagesDir + '/core',
});
}
// 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();

View File

@ -15,7 +15,8 @@
"module": "dist/index.mjs",
"main": "dist/index.js",
"scripts": {
"build": "rollup -c"
"build": "node build",
"build:dist": "rollup -c rollup.config.js"
},
"dependencies": {
"@iconify/core": "^1.0.0-beta.0",

View File

@ -1,6 +1,9 @@
const fs = require('fs');
const path = require('path');
const child_process = require('child_process');
const packagesDir = path.dirname(__dirname);
// List of commands to run
const commands = [];
@ -11,7 +14,7 @@ const compile = {
dist: true,
api: true,
};
process.argv.slice(2).forEach(cmd => {
process.argv.slice(2).forEach((cmd) => {
if (cmd.slice(0, 2) !== '--') {
return;
}
@ -35,7 +38,7 @@ process.argv.slice(2).forEach(cmd => {
case 'only':
// disable other modules
Object.keys(compile).forEach(key2 => {
Object.keys(compile).forEach((key2) => {
compile[key2] = key2 === key;
});
break;
@ -43,17 +46,39 @@ process.argv.slice(2).forEach(cmd => {
}
});
// Check if required modules in same monorepo are available
const fileExists = (file) => {
try {
fs.statSync(file);
} catch (e) {
return false;
}
return true;
};
if (compile.dist && !fileExists(packagesDir + '/vue/lib/IconifyIcon.js')) {
compile.lib = true;
}
if (compile.api && !fileExists(packagesDir + '/vue/lib/IconifyIcon.d.ts')) {
compile.lib = true;
}
if (compile.lib && !fileExists(packagesDir + '/core/lib/modules.js')) {
compile.core = true;
}
// Compile core before compiling this package
if (compile.core) {
commands.push({
cmd: 'npm',
args: ['run', 'build'],
cwd: path.dirname(__dirname) + '/core',
cwd: packagesDir + '/core',
});
}
// Compile other packages
Object.keys(compile).forEach(key => {
Object.keys(compile).forEach((key) => {
if (key !== 'core' && compile[key]) {
commands.push({
cmd: 'npm',