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';
|
|
|
|
|
2019-03-08 01:19:17 +01:00
|
|
|
const { copy, ensureDir, unlink } = require('fs-extra');
|
|
|
|
const { exec } = require('child_process');
|
2017-08-26 01:29:57 +02:00
|
|
|
|
|
|
|
const apiPath = 'api/';
|
|
|
|
const targets = [
|
|
|
|
'composer.json',
|
|
|
|
'composer.lock',
|
|
|
|
'config.default.php',
|
|
|
|
'cron.php',
|
|
|
|
'index.php',
|
|
|
|
'classes/',
|
2019-03-08 01:19:17 +01:00
|
|
|
'utils/',
|
2017-08-26 01:29:57 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'include-api-in-build',
|
|
|
|
|
|
|
|
postBuild(result) {
|
2019-03-08 01:19:17 +01:00
|
|
|
let outputPath = result.directory + '/api';
|
|
|
|
|
|
|
|
return Promise.resolve()
|
|
|
|
.then(() => {
|
|
|
|
return ensureDir(outputPath);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
return Promise.all(
|
|
|
|
targets.map((target) => {
|
|
|
|
return copy(`${apiPath}/${target}`, `${outputPath}/${target}`);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
exec('composer install --no-dev', {
|
|
|
|
cwd: outputPath
|
|
|
|
}, (err) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
}
|
2017-08-26 01:29:57 +02:00
|
|
|
|
|
|
|
resolve();
|
2019-03-08 01:19:17 +01:00
|
|
|
});
|
2017-08-26 01:29:57 +02:00
|
|
|
});
|
2019-03-08 01:19:17 +01:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
return Promise.all([
|
|
|
|
unlink(`${outputPath}/composer.json`),
|
|
|
|
unlink(`${outputPath}/composer.lock`),
|
|
|
|
]);
|
|
|
|
});
|
2017-08-26 01:29:57 +02:00
|
|
|
}
|
|
|
|
};
|