mirror of
https://github.com/citizenfx/cfx-server-data.git
synced 2025-01-08 22:22:57 +08:00
Compare commits
3 Commits
bbc77613f0
...
60da977c02
Author | SHA1 | Date | |
---|---|---|---|
|
60da977c02 | ||
|
3bac230553 | ||
|
85419a6145 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "webpack-builder",
|
"name": "webpack-builder",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -9,8 +9,8 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^2.6.1",
|
"async": "^3.1.0",
|
||||||
"webpack": "^4.12.0",
|
"webpack": "^4.41.2",
|
||||||
"worker-farm": "^1.6.0"
|
"worker-farm": "^1.7.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,9 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const workerFarm = require('worker-farm');
|
const workerFarm = require('worker-farm');
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
|
let buildingInProgress = false;
|
||||||
|
let currentBuildingModule = '';
|
||||||
|
let currentBuildingScript = '';
|
||||||
const webpackBuildTask = {
|
const webpackBuildTask = {
|
||||||
shouldBuild(resourceName) {
|
shouldBuild(resourceName) {
|
||||||
const numMetaData = GetNumResourceMetadata(resourceName, 'webpack_config');
|
const numMetaData = GetNumResourceMetadata(resourceName, 'webpack_config');
|
||||||
@ -23,7 +25,7 @@ const webpackBuildTask = {
|
|||||||
const cachePath = `cache/${resourceName}/${config.replace(/\//g, '_')}.json`;
|
const cachePath = `cache/${resourceName}/${config.replace(/\//g, '_')}.json`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return JSON.parse(fs.readFileSync(cachePath, { encoding: 'utf8' }));
|
return JSON.parse(fs.readFileSync(cachePath, {encoding: 'utf8'}));
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -66,21 +68,23 @@ const webpackBuildTask = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
build(resourceName, cb) {
|
build(resourceName, cb) {
|
||||||
|
let buildWebpack = async () => {
|
||||||
|
let error = null;
|
||||||
const configs = [];
|
const configs = [];
|
||||||
const numMetaData = GetNumResourceMetadata(resourceName, 'webpack_config');
|
const numMetaData = GetNumResourceMetadata(resourceName, 'webpack_config');
|
||||||
|
|
||||||
for (let i = 0; i < numMetaData; i++) {
|
for (let i = 0; i < numMetaData; i++) {
|
||||||
configs.push(GetResourceMetadata(resourceName, 'webpack_config', i));
|
configs.push(GetResourceMetadata(resourceName, 'webpack_config', i));
|
||||||
}
|
}
|
||||||
|
for (const configName of configs) {
|
||||||
async.forEachOf(configs, (configName, i, acb) => {
|
|
||||||
const configPath = GetResourcePath(resourceName) + '/' + configName;
|
const configPath = GetResourcePath(resourceName) + '/' + configName;
|
||||||
|
|
||||||
const cachePath = `cache/${resourceName}/${configName.replace(/\//g, '_')}.json`;
|
const cachePath = `cache/${resourceName}/${configName.replace(/\//g, '_')}.json`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.mkdirSync(path.dirname(cachePath));
|
fs.mkdirSync(path.dirname(cachePath));
|
||||||
} catch {}
|
} catch {
|
||||||
|
}
|
||||||
|
|
||||||
const config = require(configPath);
|
const config = require(configPath);
|
||||||
|
|
||||||
@ -89,6 +93,13 @@ const webpackBuildTask = {
|
|||||||
if (config) {
|
if (config) {
|
||||||
const resourcePath = path.resolve(GetResourcePath(resourceName));
|
const resourcePath = path.resolve(GetResourcePath(resourceName));
|
||||||
|
|
||||||
|
while (buildingInProgress) {
|
||||||
|
console.log(`webpack is busy by another process: we are waiting to compile ${resourceName} (${configName})`);
|
||||||
|
await sleep(3000);
|
||||||
|
}
|
||||||
|
buildingInProgress = true;
|
||||||
|
currentBuildingModule = resourceName;
|
||||||
|
currentBuildingScript = configName;
|
||||||
workers({
|
workers({
|
||||||
configPath,
|
configPath,
|
||||||
resourcePath,
|
resourcePath,
|
||||||
@ -102,7 +113,11 @@ const webpackBuildTask = {
|
|||||||
console.error(err.details);
|
console.error(err.details);
|
||||||
}
|
}
|
||||||
|
|
||||||
acb("worker farm webpack errored out");
|
buildingInProgress = false;
|
||||||
|
currentBuildingModule = '';
|
||||||
|
currentBuildingScript = '';
|
||||||
|
error = "worker farm webpack errored out";
|
||||||
|
console.error("worker farm webpack errored out");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,30 +125,32 @@ const webpackBuildTask = {
|
|||||||
for (const error of outp.errors) {
|
for (const error of outp.errors) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
acb("webpack got an error");
|
buildingInProgress = false;
|
||||||
|
currentBuildingModule = '';
|
||||||
|
currentBuildingScript = '';
|
||||||
|
error = "webpack got an error";
|
||||||
|
console.error("webpack got an error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`${resourceName}: built ${configName}`);
|
console.log(`${resourceName}: built ${configName}`);
|
||||||
|
|
||||||
acb();
|
buildingInProgress = false;
|
||||||
});
|
currentBuildingModule = '';
|
||||||
|
currentBuildingScript = '';
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
acb("no configuration");
|
|
||||||
}, (err) => {
|
|
||||||
setImmediate(() => {
|
|
||||||
if (err) {
|
|
||||||
cb(false, err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cb(true);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (error) {
|
||||||
|
cb(false, error);
|
||||||
|
} else cb(true);
|
||||||
|
};
|
||||||
|
buildWebpack().then();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function sleep(ms) {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisterResourceBuildTaskFactory('z_webpack', () => webpackBuildTask);
|
RegisterResourceBuildTaskFactory('z_webpack', () => webpackBuildTask);
|
@ -1,6 +1,8 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const child_process = require('child_process');
|
const child_process = require('child_process');
|
||||||
|
let buildingInProgress = false;
|
||||||
|
let currentBuildingModule = '';
|
||||||
|
|
||||||
const yarnBuildTask = {
|
const yarnBuildTask = {
|
||||||
shouldBuild(resourceName) {
|
shouldBuild(resourceName) {
|
||||||
@ -30,6 +32,13 @@ const yarnBuildTask = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
build(resourceName, cb) {
|
build(resourceName, cb) {
|
||||||
|
let buildYarn = async () => {
|
||||||
|
while (buildingInProgress) {
|
||||||
|
console.log(`yarn is busy by another process: we are waiting to compile ${resourceName}`);
|
||||||
|
await sleep(3000);
|
||||||
|
}
|
||||||
|
buildingInProgress = true;
|
||||||
|
currentBuildingModule = resourceName;
|
||||||
const process = child_process.fork(
|
const process = child_process.fork(
|
||||||
require.resolve('./yarn_cli.js'),
|
require.resolve('./yarn_cli.js'),
|
||||||
['install'],
|
['install'],
|
||||||
@ -40,6 +49,8 @@ const yarnBuildTask = {
|
|||||||
process.on('exit', (code, signal) => {
|
process.on('exit', (code, signal) => {
|
||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
if (code != 0 || signal) {
|
if (code != 0 || signal) {
|
||||||
|
buildingInProgress = false;
|
||||||
|
currentBuildingModule = '';
|
||||||
cb(false, 'yarn failed!');
|
cb(false, 'yarn failed!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -53,10 +64,17 @@ const yarnBuildTask = {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildingInProgress = false;
|
||||||
|
currentBuildingModule = '';
|
||||||
cb(true);
|
cb(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
buildYarn().then();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
function sleep(ms) {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
RegisterResourceBuildTaskFactory('yarn', () => yarnBuildTask);
|
RegisterResourceBuildTaskFactory('yarn', () => yarnBuildTask);
|
Loading…
Reference in New Issue
Block a user