@aj-shadow/z-build-project 0.0.0-aj-beta.221

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/.gitattributes +26 -0
  2. package/LICENSE.txt +96 -0
  3. package/README.md +5 -0
  4. package/npm-shrinkwrap.json +13 -0
  5. package/package.json +10 -0
  6. package/package_release.json +26 -0
  7. package/project/server/_build/z-build-project.prj +3 -0
  8. package/project/server/bottleneck-queue.js +35 -0
  9. package/project/server/build-all.js +122 -0
  10. package/project/server/build-client-bundle.js +84 -0
  11. package/project/server/build-client-js.js +58 -0
  12. package/project/server/build-client-jsx.js +59 -0
  13. package/project/server/build-client-rc-bundle.js +72 -0
  14. package/project/server/build-server-js.js +62 -0
  15. package/project/server/build-server-rc.js +68 -0
  16. package/project/server/build.js +294 -0
  17. package/project/server/child-build-data.js +87 -0
  18. package/project/server/child-client-bundle.js +376 -0
  19. package/project/server/child-client-js.js +279 -0
  20. package/project/server/child-client-jsx.js +175 -0
  21. package/project/server/child-client-rc-bundle.js +115 -0
  22. package/project/server/child-server-js.js +165 -0
  23. package/project/server/child-server-rc.js +118 -0
  24. package/project/server/git-global.js +75 -0
  25. package/project/server/git-tasks.js +768 -0
  26. package/project/server/log.js +53 -0
  27. package/project/server/npm-install-all.js +129 -0
  28. package/project/server/pendings.js +21 -0
  29. package/project/server/process.js +218 -0
  30. package/project/server/project.js +102 -0
  31. package/project/server/repo-manager.js +106 -0
  32. package/project/server/service/commands.js +332 -0
  33. package/project/server/task-clean.js +45 -0
  34. package/project/server/task-list.js +27 -0
  35. package/project/server/task-runner-glob.js +83 -0
  36. package/project/server/task-runner.js +292 -0
  37. package/project/server/task-simple.js +56 -0
  38. package/project/server/task.js +59 -0
  39. package/project/server/workspace.js +317 -0
  40. package/project/z-build-project.tree +37 -0
@@ -0,0 +1,376 @@
1
+
2
+ 'use strict';
3
+
4
+ const ChildBuildData = require('./child-build-data');
5
+ const Log = require('./log');
6
+ const Babelify = require('babelify');
7
+ const envify = require('envify');
8
+ const { minify } = require('terser');
9
+ const Browserify = require('browserify');
10
+ const Clc = require('cli-color');
11
+ const FastGlob = require('fast-glob');
12
+ const Babel = require("@babel/core");
13
+ const Fs = require('fs');
14
+ const Path = require('path');
15
+ const Zlib = require('zlib');
16
+
17
+
18
+ class ChildClientBundle {
19
+ static START = './build/'.length;
20
+ static STOP = '.js'.length;
21
+ static BABEL_PART_PATH = `${Path.sep}node_modules${Path.sep}@babel`;
22
+ static BROWSERIFY_PART_EMPTY_PATH = `${Path.sep}node_modules${Path.sep}browserify${Path.sep}lib${Path.sep}_empty.js`;
23
+
24
+ constructor(appName, name, silent, bundleName, source, dest, ignores, externals, externalGlobs, exports, exportSource, shim, nodeEnv, buildEnv) {
25
+ this.appName = appName;
26
+ this.name = name;
27
+ this.silent = silent;
28
+ this.bundleName = bundleName;
29
+ this.source = source;
30
+ this.dest = dest;
31
+ this.ignores = ignores;
32
+ this.externals = externals;
33
+ this.externalGlobs = externalGlobs;
34
+ this.exports = exports;
35
+ this.exportSource = exportSource;
36
+ this.shim = shim;
37
+ process.env.NODE_ENV = nodeEnv;
38
+ this.production = 1 === buildEnv;
39
+ this.nestedDependencies = [];
40
+ }
41
+
42
+ task(cb) {
43
+ const buildDataPath = Path.resolve(`..${Path.sep}Generated${Path.sep}Build${Path.sep}${this.appName}-${this.name.replaceAll(':', '-').replaceAll('/', '-')}`);
44
+ ChildBuildData.getBuildData(buildDataPath, (buildData) => {
45
+ let pendings = 3;
46
+ let changed = false;
47
+ let sources = null;
48
+ let externals = null;
49
+ const dstFile = `${this.dest.replaceAll('/', Path.sep)}${Path.sep}${this.bundleName}`;
50
+ Fs.lstat(dstFile, (err, stat) => {
51
+ if(!!err) {
52
+ changed = 'ENOENT' === err.code;
53
+ }
54
+ if(0 === --pendings) {
55
+ if(changed) {
56
+ this._build(sources, externals, buildDataPath, buildData, cb);
57
+ }
58
+ else {
59
+ cb();
60
+ }
61
+ }
62
+ });
63
+ this._sourceChanged(buildData, (_changed, _sources) => {
64
+ changed = changed || _changed;
65
+ sources = _sources;
66
+ if(0 === --pendings) {
67
+ if(changed) {
68
+ this._build(sources, externals, buildDataPath, buildData, cb);
69
+ }
70
+ else {
71
+ cb();
72
+ }
73
+ }
74
+ });
75
+ this._externalChanged(buildData, (_changed, _externals) => {
76
+ changed = changed || _changed;
77
+ externals = _externals;
78
+ if(0 === --pendings) {
79
+ if(changed) {
80
+ this._build(sources, externals, buildDataPath, buildData, cb);
81
+ }
82
+ else {
83
+ cb();
84
+ }
85
+ }
86
+ });
87
+ });
88
+ }
89
+
90
+ _printNestedDependencies() {
91
+ this.nestedDependencies.forEach((nestedDependency) => {
92
+ if(nestedDependency.isExternal) {
93
+ if(!nestedDependency.file.includes(ChildClientBundle.BABEL_PART_PATH)) {
94
+ if(!nestedDependency.file.includes(ChildClientBundle.BROWSERIFY_PART_EMPTY_PATH)) {
95
+ const bundleDate = new Date();
96
+ Log.bundle(this.name, bundleDate, nestedDependency.id, nestedDependency.file);
97
+ }
98
+ else {
99
+ const ignoreDate = new Date();
100
+ Log.ignore(this.name, ignoreDate, nestedDependency.id, nestedDependency.file);
101
+ }
102
+ }
103
+ }
104
+ });
105
+ }
106
+
107
+ _build(sources, externals, buildDataPath, buildData, cb) {
108
+ const browserify = Browserify({
109
+ entries: sources,
110
+ debug: false,
111
+ ignoreMissing: true,
112
+ transform: [[envify, { global: true }, { NODE_ENV: this.production ? 'production' : 'development'}]]
113
+ }, this.shim);
114
+ browserify.pipeline.on('file', (file, id, parent) => {
115
+ this.nestedDependencies.push({
116
+ file,
117
+ id,
118
+ isExternal: file.includes('node_modules') && !file.includes('@actorjs')
119
+ });
120
+ });
121
+ if(this.ignores) {
122
+ this.ignores.forEach((ignore) => {
123
+ if(!Array.isArray(ignore)) {
124
+ browserify.exclude(ignore);
125
+ const ignoreDate = new Date();
126
+ Log.ignore(this.name, ignoreDate, ignore, '');
127
+ }
128
+ else {
129
+ if(this.production) {
130
+ browserify.exclude(ignore[0]);
131
+ const ignoreDate = new Date();
132
+ Log.ignore(this.name, ignoreDate, ignore[0], '');
133
+ }
134
+ else {
135
+ browserify.exclude(ignore[1]);
136
+ const ignoreDate = new Date();
137
+ Log.ignore(this.name, ignoreDate, ignore[1], '');
138
+ }
139
+ }
140
+ });
141
+ }
142
+
143
+ if(this.externals) {
144
+ this.externals.forEach((external) => {
145
+ browserify.external(external);
146
+ });
147
+ }
148
+
149
+ if(this.exports) {
150
+ this.exports.forEach((export_) => {
151
+ if(!Array.isArray(export_)) {
152
+ browserify.require(export_);
153
+ }
154
+ else {
155
+ if(this.production) {
156
+ browserify.require(export_[0][0], {expose: export_[0][1]});
157
+ }
158
+ else {
159
+ if(export_[1]) {
160
+ browserify.require(export_[1][0], {expose: export_[1][1]});
161
+ }
162
+ else {
163
+ browserify.require(export_[0][0], {expose: export_[0][1]});
164
+ }
165
+ }
166
+ }
167
+ });
168
+ }
169
+
170
+ sources.forEach((source) => {
171
+ browserify.require(source, {expose: source.substring(ChildClientBundle.START, source.length - ChildClientBundle.STOP)});
172
+ });
173
+
174
+ externals.forEach((external) => {
175
+ browserify.external(external.substring(ChildClientBundle.START, external.length - ChildClientBundle.STOP));
176
+ });
177
+
178
+ this._bundleClientBundle(browserify, buildDataPath, buildData, cb);
179
+ }
180
+
181
+ async _sourceChanged(buildData, cb) {
182
+ if(this.source && 0 !== this.source.length) {
183
+ let pendings = this.source.length;
184
+ const entries = [];
185
+ let changed = false;
186
+ for(let i = 0; i < this.source.length; ++i) {
187
+ const files = await FastGlob([this.source[i]], { caseSensitiveMatch: true, braceExpansion: false });
188
+ entries.push(files);
189
+ files.forEach((file) => {
190
+ ++pendings;
191
+ Fs.lstat(file, (err, stat) => {
192
+ const mTimeMs = buildData.map.get(file);
193
+ if(mTimeMs !== stat.mtimeMs) {
194
+ changed = true;
195
+ ChildBuildData.set(buildData, file, stat.mtimeMs);
196
+ }
197
+ if(0 === --pendings) {
198
+ cb(changed, entries.flat());
199
+ }
200
+ });
201
+ });
202
+ if(0 === --pendings) {
203
+ cb(changed, entries.flat());
204
+ }
205
+ }
206
+ }
207
+ else {
208
+ process.nextTick(cb, false, []);
209
+ }
210
+ }
211
+
212
+ async _externalChanged(buildData, cb) {
213
+ if(this.externalGlobs && 0 !== this.externalGlobs.length) {
214
+ let pendings = this.externalGlobs.length;
215
+ const entries = [];
216
+ let changed = false;
217
+ for(let i = 0; i < this.externalGlobs.length; ++i) {
218
+ const files = await FastGlob([this.externalGlobs[i]], { caseSensitiveMatch: true, braceExpansion: false });
219
+ entries.push(files);
220
+ files.forEach((file) => {
221
+ ++pendings;
222
+ Fs.lstat(file, (err, stat) => {
223
+ const mTimeMs = buildData.map.get(file);
224
+ if(mTimeMs !== stat.mtimeMs) {
225
+ changed = true;
226
+ ChildBuildData.set(buildData, file, stat.mtimeMs);
227
+ }
228
+ if(0 === --pendings) {
229
+ cb(changed, entries.flat());
230
+ return;
231
+ }
232
+ });
233
+ });
234
+ if(0 === --pendings) {
235
+ cb(changed, entries.flat());
236
+ return;
237
+ }
238
+ }
239
+ if(0 === pendings) {
240
+ cb(changed, entries.flat());
241
+ }
242
+ }
243
+ else {
244
+ process.nextTick(cb.bind(this, false, []));
245
+ }
246
+ }
247
+
248
+ async _formatCodeDevelopment(buf, cb) {
249
+ const result = await minify(buf.toString('utf8'), {
250
+ compress: {
251
+ dead_code: true,
252
+ drop_debugger: false,
253
+ global_defs: {
254
+ 'process.env.NODE_ENV': '"development"'
255
+ }
256
+ },
257
+ mangle: false,
258
+ format: {
259
+ beautify: true
260
+ }
261
+ });
262
+ cb(result);
263
+ }
264
+
265
+ async _formatCodeProduction(buf, cb) {
266
+ const result = await minify(buf.toString('utf8'), {
267
+ compress: {
268
+ dead_code: true,
269
+ drop_debugger: false,
270
+ passes: 2,
271
+ global_defs: {
272
+ 'process.env.NODE_ENV': '"production"'
273
+ }
274
+ },
275
+ mangle: false,
276
+ format: {
277
+ comments: false
278
+ }
279
+ });
280
+ cb(result);
281
+ }
282
+
283
+ _bundleClientBundle(browserify, buildDataPath, buildData, cb) {
284
+ browserify
285
+ .on('error', console.error.bind(console))
286
+ .transform(Babelify, {
287
+ plugins: [
288
+ "@babel/plugin-transform-runtime",
289
+ ["transform-inline-environment-variables", {"include": ["NODE_ENV"]}]
290
+ ],
291
+ presets: ["@babel/env"],
292
+ compact: this.production,
293
+ minified: this.production,
294
+ comments: !this.production
295
+ })
296
+ .bundle((err, buf) => {
297
+ if(err) {
298
+ Log.log(this.appName + '.' + this.name + '-----------------------------------------------------------------------------', buf);
299
+ Log.log(this.appName + '.' + this.name + `Bundle ${this.name} error:`, err);
300
+ cb();
301
+ }
302
+ else if(this.production) {
303
+ this._formatCodeProduction(buf, (result) => {
304
+ const dstFile = `${this.dest}${Path.sep}${this.bundleName}`;
305
+ let pendings = 2;
306
+ Zlib.gzip(result.code, (err, data) => {
307
+ if(err) {
308
+ Log.log(this.appName + '.' + this.name + `Bundle Zip ${this.name} error:`, err);
309
+ if(0 === --pendings) {
310
+ cb();
311
+ }
312
+ return;
313
+ }
314
+ Fs.writeFile(dstFile + '.gzip', data, (err) => {
315
+ if(err) {
316
+ Log.log(this.appName + '.' + this.name + Clc.red(`Could not write: '`) + dstFile + Clc.red(`'.`), err);
317
+ }
318
+ if(0 === --pendings) {
319
+ ChildBuildData.setBuildData(buildDataPath, buildData, cb);
320
+ this._printNestedDependencies();
321
+ }
322
+ });
323
+ });
324
+ Fs.writeFile(dstFile, result.code, (err) => {
325
+ if(err) {
326
+ Log.log(this.appName + '.' + this.name + Clc.red(`Could not write: '`) + dstFile + Clc.red(`'.`), err);
327
+ }
328
+ if(0 === --pendings) {
329
+ ChildBuildData.setBuildData(buildDataPath, buildData, cb);
330
+ this._printNestedDependencies();
331
+ }
332
+ });
333
+ });
334
+ }
335
+ else {
336
+ this._formatCodeDevelopment(buf, (result) => {
337
+ const dstFile = `${this.dest}${Path.sep}${this.bundleName}`;
338
+ Fs.writeFile(dstFile, result.code, (err) => {
339
+ if(err) {
340
+ Log.log(this.appName + '.' + this.name + Clc.red(`Could not write: '`) + dstFile + Clc.red(`'.`), err);
341
+ }
342
+ ChildBuildData.setBuildData(buildDataPath, buildData, cb);
343
+ this._printNestedDependencies();
344
+ });
345
+ });
346
+ }
347
+ });
348
+ }
349
+ }
350
+
351
+
352
+ process.nextTick(() => {
353
+ const parameters = JSON.parse(process.argv[2]);
354
+ let isDone = false;
355
+ const childClientBundle = new ChildClientBundle(...parameters);
356
+ process.on('exit', (code) => {
357
+ if(!isDone) {
358
+ console.log(' EXIT BUNDLE JS - WITHOUT DONE', childClientBundle.name);
359
+ }
360
+ });
361
+ //if('Bundle:AppLayer/client' === childClientBundle.name) {
362
+ // console.log('START BUNDLE JS', childClientBundle.name);
363
+ //}
364
+ childClientBundle.task(() => {
365
+ if(!isDone) {
366
+ //if('Bundle:AppLayer/client' === childClientBundle.name) {
367
+ // console.log(' DONE BUNDLE JS', childClientBundle.name);
368
+ //}
369
+ isDone = true;
370
+ process.send(0);
371
+ }
372
+ else {
373
+ console.log(' DONE BUNDLE JS - AGAIN', childClientBundle.name);
374
+ }
375
+ });
376
+ });
@@ -0,0 +1,279 @@
1
+
2
+ 'use strict';
3
+
4
+ const ChildBuildData = require('./child-build-data');
5
+ const Log = require('./log');
6
+ const Pendings = require('./pendings');
7
+ const TaskRunnerGlob = require('./task-runner-glob');
8
+ const Clc = require('cli-color');
9
+ const Fs = require('fs');
10
+ const Os = require('os');
11
+ const Path = require('path');
12
+
13
+
14
+ class ChildClientJs {
15
+ static SEARCH_requireAsBundle = Buffer.from('requireAsBundle');
16
+ static SEARCH_start = 'requireAsBundle'.length + 2;
17
+ static SEARCH_stop = Buffer.from('\')');
18
+ static SEARCH_empty_string = Buffer.from('\'\'');
19
+ static SEARCH_template_litteral = Buffer.from('`');
20
+
21
+ static BUILD_RELEASE_START = '#BUILD_RELEASE_START';
22
+ static BUILD_RELEASE_START_COMMENT_LINE = '// #BUILD_RELEASE_START';
23
+ static BUILD_RELEASE_START_COMMENT_ALL = '/* #BUILD_RELEASE_START';
24
+ static BUILD_RELEASE_STOP = '#BUILD_RELEASE_STOP';
25
+ static BUILD_RELEASE_STOP_COMMENT_LINE = '// #BUILD_RELEASE_STOP';
26
+ static BUILD_RELEASE_STOP_COMMENT_ALL = '#BUILD_RELEASE_STOP */';
27
+ static BUILD_DEBUG_START = '#BUILD_DEBUG_START';
28
+ static BUILD_DEBUG_START_COMMENT_LINE = '// #BUILD_DEBUG_START';
29
+ static BUILD_DEBUG_START_COMMENT_ALL = '/* #BUILD_DEBUG_START';
30
+ static BUILD_DEBUG_STOP = '#BUILD_DEBUG_STOP';
31
+ static BUILD_DEBUG_STOP_COMMENT_LINE = '// #BUILD_DEBUG_STOP';
32
+ static BUILD_DEBUG_STOP_COMMENT_ALL = '#BUILD_DEBUG_STOP */';
33
+
34
+ constructor(appName, name, silent, repo, source, dest, nodeEnv) {
35
+ this.appName = appName;
36
+ this.name = name;
37
+ this.silent = silent;
38
+ this.repo = repo;
39
+ this.source = source;
40
+ this.dest = dest;
41
+ this.isDebug = 'development' === nodeEnv;
42
+ process.env.NODE_ENV = nodeEnv;
43
+ }
44
+
45
+ task(cb) {
46
+ const resolvedPath = Path.resolve(this.repo ? Path.resolve(this.repo) : '.');
47
+ const buildDataPath = Path.resolve(`..${Path.sep}Generated${Path.sep}Build${Path.sep}${this.appName}-${this.name.replaceAll(':', '-').replaceAll('/', '-')}`);
48
+ ChildBuildData.getBuildData(buildDataPath, (buildData) => {
49
+ TaskRunnerGlob.glob(this.source, this.dest, resolvedPath, null, cb, (srcFile, dstFile, done) => {
50
+ let shallBuild = true;
51
+ const pendings = new Pendings(1, null);
52
+ Fs.lstat(dstFile, (err, stat) => {
53
+ if(shallBuild) {
54
+ if(!!err && 'ENOENT' === err.code) {
55
+ shallBuild = false;
56
+ this._build(pendings, srcFile, dstFile, resolvedPath, buildDataPath, buildData, done);
57
+ }
58
+ else {
59
+ this._setBuildData(pendings, buildDataPath, buildData, done);
60
+ }
61
+ }
62
+ else {
63
+ this._setBuildData(pendings, buildDataPath, buildData, done);
64
+ }
65
+ });
66
+ pendings.inc();
67
+ Fs.lstat(srcFile, (err, stat) => {
68
+ if(shallBuild) {
69
+ const mTimeMs = buildData.map.get(srcFile);
70
+ if(mTimeMs === stat.mtimeMs) {
71
+ this._setBuildData(pendings, buildDataPath, buildData, done);
72
+ }
73
+ else {
74
+ shallBuild = false;
75
+ this._build(pendings, srcFile, dstFile, resolvedPath, buildDataPath, buildData, done);
76
+ }
77
+ }
78
+ else {
79
+ this._setBuildData(pendings, buildDataPath, buildData, done);
80
+ }
81
+ });
82
+ });
83
+ });
84
+ }
85
+
86
+ _setBuildData(pendings, buildDataPath, buildData, done) {
87
+ if(pendings.dec()) {
88
+ ChildBuildData.setBuildData(buildDataPath, buildData, done);
89
+ }
90
+ }
91
+
92
+ _build(pendings, srcFile, dstFile, resolvedPath, buildDataPath, buildData, cb) {
93
+ Fs.readFile(srcFile, (err, data) => {
94
+ if(err) {
95
+ Log.log(Clc.red(`Could not read: '`) + srcFile + Clc.red(`'.`), err);
96
+ if(pendings.dec()) {
97
+ cb();
98
+ }
99
+ }
100
+ else {
101
+ TaskRunnerGlob.verifyPath(dstFile, (err) => {
102
+ if(err) {
103
+ if(pendings.dec()) {
104
+ cb();
105
+ }
106
+ }
107
+ else {
108
+ const bundleIndex = data.indexOf(ChildClientJs.SEARCH_requireAsBundle);
109
+ if(-1 !== bundleIndex) {
110
+ data = this._macro(data);
111
+ ChildBuildData.write(srcFile, dstFile, data.subarray(0, bundleIndex), buildData, (err) => {
112
+ if(!err) {
113
+ const buffers = [];
114
+ this._bundle(buffers, data, bundleIndex, srcFile, dstFile, resolvedPath, () => {
115
+ this._appendFile(dstFile, buffers, (err) => {
116
+ if(err) {
117
+ Log.log(Clc.red(`Could not write: '`) + dstFile + Clc.red(`'.`), err);
118
+ if(pendings.dec()) {
119
+ cb();
120
+ }
121
+ return;
122
+ }
123
+ if(pendings.dec()) {
124
+ ChildBuildData.setBuildData(buildDataPath, buildData, cb);
125
+ }
126
+ });
127
+ });
128
+ }
129
+ else {
130
+ if(pendings.dec()) {
131
+ ChildBuildData.setBuildData(buildDataPath, buildData, cb);
132
+ }
133
+ }
134
+ });
135
+ }
136
+ else {
137
+ data = this._macro(data);
138
+ ChildBuildData.write(srcFile, dstFile, data, buildData, () => {
139
+ if(pendings.dec()) {
140
+ ChildBuildData.setBuildData(buildDataPath, buildData, cb);
141
+ }
142
+ });
143
+ }
144
+ }
145
+ });
146
+ }
147
+ });
148
+ }
149
+
150
+ _appendFile(dstFile, buffers, cb) {
151
+ const buffer = buffers.shift();
152
+ if(!buffer) {
153
+ return cb();
154
+ }
155
+ Fs.appendFile(dstFile, buffer, (err) => {
156
+ if(err) {
157
+ Log.log(Clc.red(`Could not append: '`) + dstFile + Clc.red(`'.`), err);
158
+ cb(err);
159
+ }
160
+ else {
161
+ this._appendFile(dstFile, buffers, cb);
162
+ }
163
+ });
164
+ }
165
+
166
+ _bundle(buffers, data, bundleIndex, srcFile, dstFile, resolvedPath, cb) {
167
+ const stopIndex = data.indexOf(ChildClientJs.SEARCH_stop, bundleIndex);
168
+ const bundleInculde = data.subarray(bundleIndex + ChildClientJs.SEARCH_start, stopIndex).toString().replaceAll('/', Path.sep);
169
+ let file = null;
170
+ let srcBase = null;
171
+ if(bundleInculde.startsWith('.')) {
172
+ const lastIndex = srcFile.lastIndexOf(Path.sep);
173
+ srcBase = srcFile.substring(0, lastIndex);
174
+ file = Path.normalize(srcBase + Path.sep + bundleInculde) + '.js';
175
+ }
176
+ else {
177
+ const lastIndex = resolvedPath.lastIndexOf(Path.sep);
178
+ srcBase = resolvedPath.substring(0, lastIndex);
179
+ const firstIndex = bundleInculde.indexOf(Path.sep);
180
+ file = Path.normalize(srcBase + Path.sep + bundleInculde.substring(0, firstIndex) + Path.sep + 'project' + Path.sep + bundleInculde.substring(firstIndex)) + '.js';
181
+ }
182
+ Fs.readFile(file, (err, src) => {
183
+ if(!err) {
184
+ buffers.push(ChildClientJs.SEARCH_template_litteral);
185
+ let replacedSrc = src.toString().replace('`', '\`');
186
+ this._removeLine(buffers, replacedSrc, ['\'use strict\';', 'module.exports', '= require(\''], 0);
187
+ buffers.push(ChildClientJs.SEARCH_template_litteral);
188
+ }
189
+ else {
190
+ Log.log(err);
191
+ buffers.push(ChildClientJs.SEARCH_empty_string);
192
+ }
193
+ const nextBundleIndex = data.indexOf(ChildClientJs.SEARCH_requireAsBundle, stopIndex + 2);
194
+ if(-1 === nextBundleIndex) {
195
+ buffers.push(data.subarray(stopIndex + 2));
196
+ process.nextTick(cb);
197
+ }
198
+ else {
199
+ buffers.push(data.subarray(stopIndex + 2, nextBundleIndex));
200
+ this._bundle(buffers, data, nextBundleIndex, srcFile, dstFile, resolvedPath, cb);
201
+ }
202
+ });
203
+ }
204
+
205
+ _removeLine(buffers, src, texts, index) {
206
+ let foundIndex = -1;
207
+ for(let i = 0; i < texts.length; ++i) {
208
+ const fIndex = src.indexOf(texts[i], index);
209
+ if(-1 !== fIndex) {
210
+ if(-1 === foundIndex) {
211
+ foundIndex = fIndex;
212
+ }
213
+ else if(fIndex < foundIndex) {
214
+ foundIndex = fIndex;
215
+ }
216
+ }
217
+ }
218
+ if(-1 === foundIndex) {
219
+ if(0 === index) {
220
+ buffers.push(Buffer.from(src));
221
+ }
222
+ else {
223
+ buffers.push(Buffer.from(src.substring(index)));
224
+ }
225
+ return;
226
+ }
227
+ else {
228
+ const startIndex = src.lastIndexOf(Os.EOL, foundIndex);
229
+ const endIndex = src.indexOf(Os.EOL, foundIndex);
230
+ if(-1 !== endIndex) {
231
+ buffers.push(Buffer.from(src.substring(index, startIndex)));
232
+ this._removeLine(buffers, src, texts, endIndex);
233
+ }
234
+ }
235
+ }
236
+
237
+ _macro(data) {
238
+ const mightHaveMacro = data.indexOf('#');
239
+ if(-1 !== mightHaveMacro) {
240
+ if('string' !== typeof data) {
241
+ data = data.toString();
242
+ }
243
+ if(this.isDebug) {
244
+ data = data.replaceAll(ChildClientJs.BUILD_DEBUG_START, ChildClientJs.BUILD_DEBUG_START_COMMENT_LINE);
245
+ data = data.replaceAll(ChildClientJs.BUILD_DEBUG_STOP, ChildClientJs.BUILD_DEBUG_STOP_COMMENT_LINE);
246
+ data = data.replaceAll(ChildClientJs.BUILD_RELEASE_START, ChildClientJs.BUILD_RELEASE_START_COMMENT_ALL);
247
+ data = data.replaceAll(ChildClientJs.BUILD_RELEASE_STOP, ChildClientJs.BUILD_RELEASE_STOP_COMMENT_ALL);
248
+ }
249
+ else {
250
+ data = data.replaceAll(ChildClientJs.BUILD_RELEASE_START, ChildClientJs.BUILD_RELEASE_START_COMMENT_LINE);
251
+ data = data.replaceAll(ChildClientJs.BUILD_RELEASE_STOP, ChildClientJs.BUILD_RELEASE_STOP_COMMENT_LINE);
252
+ data = data.replaceAll(ChildClientJs.BUILD_DEBUG_START, ChildClientJs.BUILD_DEBUG_START_COMMENT_ALL);
253
+ data = data.replaceAll(ChildClientJs.BUILD_DEBUG_STOP, ChildClientJs.BUILD_DEBUG_STOP_COMMENT_ALL);
254
+ }
255
+ }
256
+ return data;
257
+ }
258
+ }
259
+
260
+
261
+ process.nextTick(() => {
262
+ const parameters = JSON.parse(process.argv[2]);
263
+ let isDone = false;
264
+ const childClientJs = new ChildClientJs(...parameters);
265
+ process.on('exit', (code) => {
266
+ if(!isDone) {
267
+ console.log(' EXIT CLIENT JS - WITHOUT DONE', childClientJs.name, childClientJs.pendings.value);
268
+ }
269
+ });
270
+ childClientJs.task(() => {
271
+ if(!isDone) {
272
+ isDone = true;
273
+ process.send(0);
274
+ }
275
+ else {
276
+ console.log(' DONE CLIENT JS - AGAIN', childClientJs.name);
277
+ }
278
+ });
279
+ });