75 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-04-25 16:34:20 +02:00
const fs = require('fs');
2017-12-19 21:23:20 +01:00
const shell = require('shelljs');
const path = require('path');
const _ = require('lodash');
2017-12-19 21:23:20 +01:00
const pwd = shell.pwd();
2017-12-19 21:23:20 +01:00
2018-01-16 16:33:05 +01:00
const silent = process.env.npm_config_debug !== 'true';
const isDevelopmentMode = path.resolve(pwd.stdout).indexOf('strapi-admin') !== -1;
const appPath = isDevelopmentMode ? path.resolve(process.env.PWD, '..') : path.resolve(pwd.stdout, '..');
shell.echo('🏗 Building the admin...');
2017-12-20 18:34:33 +01:00
const build = shell.exec(`cd "${path.resolve(appPath, 'admin')}" && APP_PATH="${appPath}" npm run build`, {
silent
2017-12-20 18:34:33 +01:00
});
if (build.stderr && build.code !== 0) {
2017-12-20 18:34:33 +01:00
console.error(build.stderr);
process.exit(1);
2017-12-20 18:34:33 +01:00
}
shell.echo('✅ Success');
shell.echo('');
if (process.env.npm_config_plugins === 'true') {
const plugins = path.resolve(appPath, 'plugins');
2018-04-25 17:27:09 +02:00
// TODO: build plugins in async
2018-04-25 16:34:20 +02:00
shell.ls('* -d', plugins)
.filter(x => {
let hasAdminFolder;
try {
fs.accessSync(path.resolve(appPath, 'plugins', x, 'admin', 'src', 'containers', 'App'));
hasAdminFolder = true;
} catch(err) {
hasAdminFolder = false;
}
return hasAdminFolder;
})
.forEach(function (plugin) {
2018-04-25 17:27:09 +02:00
shell.echo(`🔸 Plugin - ${_.upperFirst(plugin)}`);
shell.echo('📦 Installing packages...');
shell.exec(`cd "${path.resolve(plugins, plugin)}" && npm install`, {
silent
});
2018-04-25 17:27:09 +02:00
if (isDevelopmentMode) {
shell.exec(`cd "${path.resolve(plugins, plugin)}" && npm link strapi-helper-plugin`, {
silent
});
} else {
shell.exec(`cd "${path.resolve(plugins, plugin, 'node_modules', 'strapi-helper-plugin')}" && npm install`, {
silent
});
}
shell.echo('🏗 Building...');
const build = shell.exec(`cd "${path.resolve(plugins, plugin)}" && APP_PATH="${appPath}" npm run build`, {
silent
});
2018-04-25 17:27:09 +02:00
if (build.stderr && build.code !== 0) {
console.error(build.stderr);
process.exit(1);
}
2018-04-25 17:27:09 +02:00
shell.echo('✅ Success');
shell.echo('');
});
}