2017-08-26 01:29:57 +02:00
|
|
|
/* eslint-env node */
|
2018-12-29 01:27:37 +01:00
|
|
|
/* eslint-disable no-console */
|
2017-08-26 01:29:57 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
let fse = require('fs-extra');
|
|
|
|
let child_process = require('child_process');
|
|
|
|
let RSVP = require('rsvp');
|
|
|
|
|
|
|
|
let { copy, ensureDirSync, remove } = fse;
|
2018-12-29 01:27:37 +01:00
|
|
|
let { exec } = child_process;
|
2017-08-26 01:29:57 +02:00
|
|
|
let { Promise } = RSVP;
|
|
|
|
|
|
|
|
const apiPath = 'api/';
|
|
|
|
const targets = [
|
|
|
|
'composer.json',
|
|
|
|
'composer.lock',
|
|
|
|
'config.default.php',
|
|
|
|
'cron.php',
|
|
|
|
'index.php',
|
|
|
|
'classes/',
|
|
|
|
'utils/'
|
|
|
|
];
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'include-api-in-build',
|
|
|
|
|
|
|
|
isDevelopingAddon() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
postBuild(result) {
|
|
|
|
console.time('include-api');
|
|
|
|
return new RSVP.Promise(function(resolve, reject) {
|
|
|
|
let outputPath = result.directory + '/api';
|
|
|
|
ensureDirSync(outputPath);
|
|
|
|
|
|
|
|
let copyPromises = targets.map((target) => {
|
|
|
|
return copy(apiPath + '/' + target, outputPath + '/' + target);
|
|
|
|
});
|
|
|
|
|
|
|
|
Promise.all(copyPromises).then(() => {
|
|
|
|
exec('composer install --no-dev', {
|
|
|
|
cwd: outputPath
|
|
|
|
}, (err) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
}
|
|
|
|
Promise.all([
|
|
|
|
remove(outputPath + 'composer.json'),
|
|
|
|
remove(outputPath + 'composer.lock')
|
|
|
|
]).then(() => {
|
|
|
|
console.timeEnd('include-api');
|
|
|
|
resolve();
|
|
|
|
}).catch(reject);
|
|
|
|
});
|
|
|
|
}).catch(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|