1
0
mirror of https://github.com/citizenfx/cfx-server-data.git synced 2025-02-10 07:32:56 +08:00

system: add yarn builder resource

This commit is contained in:
moscovium 2018-04-24 21:40:18 +02:00
parent 7bb81573f1
commit 79d01af08a
3 changed files with 147742 additions and 0 deletions

View File

@ -0,0 +1,2 @@
server_only 'yes'
server_script 'yarn_builder.js'

View File

@ -0,0 +1,53 @@
const path = require('path');
const fs = require('fs');
const child_process = require('child_process');
const yarnBuildTask = {
shouldBuild(resourceName) {
try {
const resourcePath = GetResourcePath(resourceName);
const packageJson = path.resolve(resourcePath, 'package.json');
const yarnLock = path.resolve(resourcePath, 'yarn.lock');
const packageStat = fs.statSync(packageJson);
try {
const yarnStat = fs.statSync(yarnLock);
if (packageStat.mtimeMs > yarnStat.mtimeMs) {
return true;
}
} catch (e) {
// no yarn.lock, but package.json - install time!
return true;
}
} catch (e) {
}
return false;
},
build(resourceName, cb) {
const process = child_process.fork(
require.resolve('./yarn_cli.js'),
['install'],
{
cwd: path.resolve(GetResourcePath(resourceName))
});
process.on('exit', (code, signal) => {
setImmediate(() => {
if (code != 0 || signal) {
cb(false, 'yarn failed!');
return;
}
cb(true);
});
});
}
}
RegisterResourceBuildTaskFactory('yarn', () => yarnBuildTask);

File diff suppressed because one or more lines are too long