amxxpack 0.1.2 → 1.0.0

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 (69) hide show
  1. package/README.md +26 -21
  2. package/lib/builder/amxxpc.d.ts +27 -27
  3. package/lib/builder/amxxpc.js +122 -122
  4. package/lib/builder/builder.d.ts +21 -22
  5. package/lib/builder/builder.js +379 -400
  6. package/lib/builder/constants.d.ts +3 -3
  7. package/lib/builder/constants.js +6 -6
  8. package/lib/builder/index.d.ts +1 -2
  9. package/lib/builder/index.js +9 -20
  10. package/lib/cli/controller.d.ts +20 -16
  11. package/lib/cli/controller.js +238 -181
  12. package/lib/cli/index.d.ts +3 -2
  13. package/lib/cli/index.js +13 -8
  14. package/lib/cli/program.d.ts +4 -4
  15. package/lib/cli/program.js +174 -118
  16. package/lib/cli/services/project-creator.d.ts +21 -0
  17. package/lib/cli/services/project-creator.js +274 -0
  18. package/lib/cli/services/template-builder.d.ts +11 -0
  19. package/lib/cli/services/template-builder.js +104 -0
  20. package/lib/cli/types.d.ts +12 -0
  21. package/lib/{compiler-downloader → cli}/types.js +2 -2
  22. package/lib/config/index.d.ts +8 -0
  23. package/lib/config/index.js +14 -0
  24. package/lib/downloaders/compiler/constants.d.ts +9 -0
  25. package/lib/{compiler-downloader → downloaders/compiler}/constants.js +14 -17
  26. package/lib/downloaders/compiler/downloader.d.ts +3 -0
  27. package/lib/{compiler-downloader → downloaders/compiler}/downloader.js +151 -174
  28. package/lib/{compiler-downloader → downloaders/compiler}/index.d.ts +1 -1
  29. package/lib/{compiler-downloader → downloaders/compiler}/index.js +9 -9
  30. package/lib/{compiler-downloader → downloaders/compiler}/resolvers.d.ts +6 -6
  31. package/lib/{compiler-downloader → downloaders/compiler}/resolvers.js +40 -39
  32. package/lib/{compiler-downloader → downloaders/compiler}/types.d.ts +16 -16
  33. package/lib/{builder → downloaders/compiler}/types.js +2 -2
  34. package/lib/downloaders/thirdparty/downloader.d.ts +3 -0
  35. package/lib/downloaders/thirdparty/downloader.js +69 -0
  36. package/lib/downloaders/thirdparty/index.d.ts +1 -0
  37. package/lib/downloaders/thirdparty/index.js +9 -0
  38. package/lib/downloaders/thirdparty/types.d.ts +5 -0
  39. package/lib/downloaders/thirdparty/types.js +2 -0
  40. package/lib/index.d.ts +2 -2
  41. package/lib/index.js +20 -20
  42. package/lib/logger/constants.d.ts +7 -0
  43. package/lib/logger/constants.js +12 -0
  44. package/lib/{services → logger}/logger.d.ts +16 -22
  45. package/lib/{services → logger}/logger.js +96 -104
  46. package/lib/logger/types.d.ts +3 -0
  47. package/lib/logger/types.js +2 -0
  48. package/lib/project-config/defaults.d.ts +3 -0
  49. package/lib/project-config/defaults.js +38 -0
  50. package/lib/project-config/index.d.ts +6 -0
  51. package/lib/project-config/index.js +8 -0
  52. package/lib/project-config/resolve.d.ts +3 -0
  53. package/lib/project-config/resolve.js +110 -0
  54. package/lib/types/index.d.ts +45 -0
  55. package/lib/types/index.js +2 -0
  56. package/lib/utils/accumulator.d.ts +2 -1
  57. package/lib/utils/accumulator.js +10 -10
  58. package/lib/utils/download.d.ts +6 -0
  59. package/lib/utils/download.js +63 -0
  60. package/package.json +7 -1
  61. package/resources/templates/include-directive.txt +1 -0
  62. package/resources/templates/include.txt +5 -0
  63. package/resources/templates/library-include.txt +6 -0
  64. package/resources/templates/library-script.txt +10 -0
  65. package/resources/templates/script.txt +5 -0
  66. package/lib/builder/types.d.ts +0 -20
  67. package/lib/compiler-downloader/constants.d.ts +0 -12
  68. package/lib/compiler-downloader/downloader.d.ts +0 -2
  69. package/resources/default-config.json +0 -22
@@ -1,400 +1,379 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- var __generator = (this && this.__generator) || function (thisArg, body) {
31
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
32
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
33
- function verb(n) { return function (v) { return step([n, v]); }; }
34
- function step(op) {
35
- if (f) throw new TypeError("Generator is already executing.");
36
- while (_) try {
37
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
38
- if (y = 0, t) op = [op[0] & 2, t.value];
39
- switch (op[0]) {
40
- case 0: case 1: t = op; break;
41
- case 4: _.label++; return { value: op[1], done: false };
42
- case 5: _.label++; y = op[1]; op = [0]; continue;
43
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
44
- default:
45
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
46
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
47
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
48
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
49
- if (t[2]) _.ops.pop();
50
- _.trys.pop(); continue;
51
- }
52
- op = body.call(thisArg, _);
53
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
54
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
55
- }
56
- };
57
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
58
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
59
- if (ar || !(i in from)) {
60
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
61
- ar[i] = from[i];
62
- }
63
- }
64
- return to.concat(ar || Array.prototype.slice.call(from));
65
- };
66
- var __importDefault = (this && this.__importDefault) || function (mod) {
67
- return (mod && mod.__esModule) ? mod : { "default": mod };
68
- };
69
- Object.defineProperty(exports, "__esModule", { value: true });
70
- var path_1 = __importDefault(require("path"));
71
- var fs_1 = __importDefault(require("fs"));
72
- var mkdirp_1 = __importDefault(require("mkdirp"));
73
- var glob_promise_1 = __importDefault(require("glob-promise"));
74
- var chokidar_1 = __importDefault(require("chokidar"));
75
- var normalize_path_1 = __importDefault(require("normalize-path"));
76
- var lodash_1 = require("lodash");
77
- var amxxpc_1 = __importStar(require("./amxxpc"));
78
- var logger_1 = __importDefault(require("../services/logger"));
79
- var constants_1 = require("./constants");
80
- var AmxxBuilder = /** @class */ (function () {
81
- function AmxxBuilder(config) {
82
- var compiler = config.compiler, input = config.input, output = config.output, rules = config.rules;
83
- this.logger = new logger_1.default();
84
- this.config = {
85
- compiler: {
86
- executable: path_1.default.resolve(compiler.executable),
87
- include: compiler.include.map(function (include) { return path_1.default.resolve(include); })
88
- },
89
- input: {
90
- scripts: path_1.default.resolve(input.scripts),
91
- include: path_1.default.resolve(input.include),
92
- assets: path_1.default.resolve(input.assets),
93
- },
94
- output: {
95
- scripts: path_1.default.resolve(output.scripts),
96
- plugins: path_1.default.resolve(output.plugins),
97
- include: path_1.default.resolve(output.include),
98
- assets: path_1.default.resolve(output.assets)
99
- },
100
- rules: {
101
- flatCompilation: (0, lodash_1.get)(rules, 'flatCompilation', true)
102
- }
103
- };
104
- }
105
- AmxxBuilder.prototype.build = function () {
106
- return __awaiter(this, void 0, void 0, function () {
107
- return __generator(this, function (_a) {
108
- switch (_a.label) {
109
- case 0:
110
- this.logger.info('Building...');
111
- return [4 /*yield*/, this.buildAssets()];
112
- case 1:
113
- _a.sent();
114
- return [4 /*yield*/, this.buildInclude()];
115
- case 2:
116
- _a.sent();
117
- return [4 /*yield*/, this.buildSrc()];
118
- case 3:
119
- _a.sent();
120
- this.logger.success('Build finished!');
121
- return [2 /*return*/];
122
- }
123
- });
124
- });
125
- };
126
- AmxxBuilder.prototype.watch = function () {
127
- return __awaiter(this, void 0, void 0, function () {
128
- return __generator(this, function (_a) {
129
- switch (_a.label) {
130
- case 0: return [4 /*yield*/, this.watchAssets()];
131
- case 1:
132
- _a.sent();
133
- return [4 /*yield*/, this.watchInclude()];
134
- case 2:
135
- _a.sent();
136
- return [4 /*yield*/, this.watchSrc()];
137
- case 3:
138
- _a.sent();
139
- return [2 /*return*/];
140
- }
141
- });
142
- });
143
- };
144
- AmxxBuilder.prototype.buildSrc = function () {
145
- return __awaiter(this, void 0, void 0, function () {
146
- var _this = this;
147
- return __generator(this, function (_a) {
148
- switch (_a.label) {
149
- case 0: return [4 /*yield*/, this.buildDir(this.config.input.scripts, constants_1.SCRIPTS_PATH_PATTERN, function (filePath) { return _this.updatePlugin(filePath); })];
150
- case 1:
151
- _a.sent();
152
- return [2 /*return*/];
153
- }
154
- });
155
- });
156
- };
157
- AmxxBuilder.prototype.buildInclude = function () {
158
- return __awaiter(this, void 0, void 0, function () {
159
- var _this = this;
160
- return __generator(this, function (_a) {
161
- switch (_a.label) {
162
- case 0: return [4 /*yield*/, this.buildDir(this.config.input.include, constants_1.INCLUDE_PATH_PATTERN, function (filePath) { return _this.updateInclude(filePath); })];
163
- case 1:
164
- _a.sent();
165
- return [2 /*return*/];
166
- }
167
- });
168
- });
169
- };
170
- AmxxBuilder.prototype.buildAssets = function () {
171
- return __awaiter(this, void 0, void 0, function () {
172
- var _this = this;
173
- return __generator(this, function (_a) {
174
- switch (_a.label) {
175
- case 0: return [4 /*yield*/, this.buildDir(this.config.input.assets, constants_1.ASSETS_PATH_PATTERN, function (filePath) { return _this.updateAsset(filePath); })];
176
- case 1:
177
- _a.sent();
178
- return [2 /*return*/];
179
- }
180
- });
181
- });
182
- };
183
- AmxxBuilder.prototype.watchSrc = function () {
184
- return __awaiter(this, void 0, void 0, function () {
185
- var _this = this;
186
- return __generator(this, function (_a) {
187
- switch (_a.label) {
188
- case 0: return [4 /*yield*/, this.watchDir(this.config.input.scripts, constants_1.SCRIPTS_PATH_PATTERN, function (filePath) { return _this.updatePlugin(filePath); })];
189
- case 1:
190
- _a.sent();
191
- return [2 /*return*/];
192
- }
193
- });
194
- });
195
- };
196
- AmxxBuilder.prototype.watchInclude = function () {
197
- return __awaiter(this, void 0, void 0, function () {
198
- var _this = this;
199
- return __generator(this, function (_a) {
200
- switch (_a.label) {
201
- case 0: return [4 /*yield*/, this.watchDir(this.config.input.include, constants_1.INCLUDE_PATH_PATTERN, function (filePath) { return _this.updateInclude(filePath); })];
202
- case 1:
203
- _a.sent();
204
- return [2 /*return*/];
205
- }
206
- });
207
- });
208
- };
209
- AmxxBuilder.prototype.watchAssets = function () {
210
- return __awaiter(this, void 0, void 0, function () {
211
- var _this = this;
212
- return __generator(this, function (_a) {
213
- switch (_a.label) {
214
- case 0: return [4 /*yield*/, this.watchDir(this.config.input.assets, constants_1.ASSETS_PATH_PATTERN, function (filePath) { return _this.updateAsset(filePath); })];
215
- case 1:
216
- _a.sent();
217
- return [2 /*return*/];
218
- }
219
- });
220
- });
221
- };
222
- AmxxBuilder.prototype.updatePlugin = function (filePath) {
223
- return __awaiter(this, void 0, void 0, function () {
224
- return __generator(this, function (_a) {
225
- switch (_a.label) {
226
- case 0: return [4 /*yield*/, this.updateScript(filePath)];
227
- case 1:
228
- _a.sent();
229
- return [4 /*yield*/, this.compilePlugin(filePath)];
230
- case 2:
231
- _a.sent();
232
- return [2 /*return*/];
233
- }
234
- });
235
- });
236
- };
237
- AmxxBuilder.prototype.updateScript = function (filePath) {
238
- return __awaiter(this, void 0, void 0, function () {
239
- var srcPath, destPath;
240
- return __generator(this, function (_a) {
241
- switch (_a.label) {
242
- case 0:
243
- srcPath = path_1.default.resolve(filePath);
244
- destPath = path_1.default.join(this.config.output.scripts, path_1.default.parse(filePath).base);
245
- return [4 /*yield*/, (0, mkdirp_1.default)(this.config.output.scripts)];
246
- case 1:
247
- _a.sent();
248
- return [4 /*yield*/, fs_1.default.promises.copyFile(srcPath, destPath)];
249
- case 2:
250
- _a.sent();
251
- this.logger.info('Script updated:', (0, normalize_path_1.default)(destPath));
252
- return [2 /*return*/];
253
- }
254
- });
255
- });
256
- };
257
- AmxxBuilder.prototype.updateAsset = function (filePath) {
258
- return __awaiter(this, void 0, void 0, function () {
259
- var srcPath, relativePath, destPath;
260
- return __generator(this, function (_a) {
261
- switch (_a.label) {
262
- case 0:
263
- srcPath = path_1.default.resolve(filePath);
264
- relativePath = path_1.default.relative(this.config.input.assets, filePath);
265
- destPath = path_1.default.join(this.config.output.assets, relativePath);
266
- return [4 /*yield*/, (0, mkdirp_1.default)(path_1.default.parse(destPath).dir)];
267
- case 1:
268
- _a.sent();
269
- return [4 /*yield*/, fs_1.default.promises.copyFile(srcPath, destPath)];
270
- case 2:
271
- _a.sent();
272
- this.logger.info('Asset updated', (0, normalize_path_1.default)(destPath));
273
- return [2 /*return*/];
274
- }
275
- });
276
- });
277
- };
278
- AmxxBuilder.prototype.updateInclude = function (filePath) {
279
- return __awaiter(this, void 0, void 0, function () {
280
- var srcPath, destPath;
281
- return __generator(this, function (_a) {
282
- switch (_a.label) {
283
- case 0:
284
- srcPath = path_1.default.resolve(filePath);
285
- destPath = path_1.default.join(this.config.output.include, path_1.default.parse(filePath).base);
286
- return [4 /*yield*/, (0, mkdirp_1.default)(this.config.output.include)];
287
- case 1:
288
- _a.sent();
289
- return [4 /*yield*/, fs_1.default.promises.copyFile(srcPath, destPath)];
290
- case 2:
291
- _a.sent();
292
- this.logger.info('Include updated:', (0, normalize_path_1.default)(destPath));
293
- return [2 /*return*/];
294
- }
295
- });
296
- });
297
- };
298
- AmxxBuilder.prototype.findPlugins = function (pattern) {
299
- return __awaiter(this, void 0, void 0, function () {
300
- var pathPattern, matches;
301
- return __generator(this, function (_a) {
302
- switch (_a.label) {
303
- case 0:
304
- pathPattern = path_1.default.join(this.config.input.scripts, '**', pattern);
305
- return [4 /*yield*/, (0, glob_promise_1.default)(pathPattern)];
306
- case 1:
307
- matches = _a.sent();
308
- return [2 /*return*/, matches];
309
- }
310
- });
311
- });
312
- };
313
- AmxxBuilder.prototype.compilePlugin = function (filePath) {
314
- return __awaiter(this, void 0, void 0, function () {
315
- var srcPath, destDir, srcDir, relateiveSrcPath, result, destPath, relativeFilePath;
316
- var _this = this;
317
- return __generator(this, function (_a) {
318
- switch (_a.label) {
319
- case 0:
320
- srcPath = path_1.default.resolve(filePath);
321
- destDir = path_1.default.resolve(this.config.output.plugins);
322
- if (!this.config.rules.flatCompilation) {
323
- srcDir = path_1.default.parse(srcPath).dir;
324
- destDir = path_1.default.join(destDir, path_1.default.relative(this.config.input.scripts, srcDir));
325
- }
326
- relateiveSrcPath = path_1.default.relative(process.cwd(), srcPath);
327
- return [4 /*yield*/, (0, mkdirp_1.default)(destDir)];
328
- case 1:
329
- _a.sent();
330
- return [4 /*yield*/, (0, amxxpc_1.default)({
331
- path: srcPath,
332
- dest: destDir,
333
- compiler: this.config.compiler.executable,
334
- includeDir: __spreadArray(__spreadArray([], this.config.compiler.include, true), [
335
- this.config.input.include,
336
- ], false)
337
- })];
338
- case 2:
339
- result = _a.sent();
340
- result.output.messages.forEach(function (message) {
341
- var startLine = message.startLine, type = message.type, code = message.code, text = message.text;
342
- if (type === amxxpc_1.AMXPCMessageType.Error || type === amxxpc_1.AMXPCMessageType.FatalError) {
343
- _this.logger.error("".concat((0, normalize_path_1.default)(relateiveSrcPath), "(").concat(startLine, ")"), type, code, ':', text);
344
- }
345
- else if (type === amxxpc_1.AMXPCMessageType.Warning) {
346
- _this.logger.warn("".concat((0, normalize_path_1.default)(relateiveSrcPath), "(").concat(startLine, ")"), type, code, ':', text);
347
- }
348
- else if (type === amxxpc_1.AMXPCMessageType.Echo) {
349
- _this.logger.debug(text);
350
- }
351
- });
352
- if (result.success) {
353
- destPath = path_1.default.join(destDir, result.plugin);
354
- relativeFilePath = path_1.default.relative(process.cwd(), filePath);
355
- this.logger.success('Compilation success:', (0, normalize_path_1.default)(relativeFilePath));
356
- this.logger.info('Plugin updated:', (0, normalize_path_1.default)(destPath));
357
- }
358
- else {
359
- throw new Error("Failed to compile ".concat((0, normalize_path_1.default)(relateiveSrcPath), " : \"").concat(result.error, "\""));
360
- }
361
- return [2 /*return*/];
362
- }
363
- });
364
- });
365
- };
366
- AmxxBuilder.prototype.buildDir = function (baseDir, pattern, cb) {
367
- return __awaiter(this, void 0, void 0, function () {
368
- var pathPattern, matches;
369
- return __generator(this, function (_a) {
370
- switch (_a.label) {
371
- case 0:
372
- pathPattern = path_1.default.join(baseDir, pattern);
373
- return [4 /*yield*/, (0, glob_promise_1.default)(pathPattern, { nodir: true })];
374
- case 1:
375
- matches = _a.sent();
376
- return [4 /*yield*/, matches.reduce(function (acc, match) { return acc.then(function () { return cb(match); }); }, Promise.resolve())];
377
- case 2:
378
- _a.sent();
379
- return [2 /*return*/];
380
- }
381
- });
382
- });
383
- };
384
- AmxxBuilder.prototype.watchDir = function (baseDir, pattern, cb) {
385
- return __awaiter(this, void 0, void 0, function () {
386
- var pathPattern, watcher, updateFn;
387
- var _this = this;
388
- return __generator(this, function (_a) {
389
- pathPattern = path_1.default.join(baseDir, pattern);
390
- watcher = chokidar_1.default.watch(pathPattern, { ignoreInitial: true });
391
- updateFn = function (filePath) { return cb(filePath).catch(function (err) { return _this.logger.error(err.message); }); };
392
- watcher.on('add', updateFn);
393
- watcher.on('change', updateFn);
394
- return [2 /*return*/];
395
- });
396
- });
397
- };
398
- return AmxxBuilder;
399
- }());
400
- exports.default = AmxxBuilder;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __generator = (this && this.__generator) || function (thisArg, body) {
31
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
32
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
33
+ function verb(n) { return function (v) { return step([n, v]); }; }
34
+ function step(op) {
35
+ if (f) throw new TypeError("Generator is already executing.");
36
+ while (_) try {
37
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
38
+ if (y = 0, t) op = [op[0] & 2, t.value];
39
+ switch (op[0]) {
40
+ case 0: case 1: t = op; break;
41
+ case 4: _.label++; return { value: op[1], done: false };
42
+ case 5: _.label++; y = op[1]; op = [0]; continue;
43
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
44
+ default:
45
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
46
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
47
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
48
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
49
+ if (t[2]) _.ops.pop();
50
+ _.trys.pop(); continue;
51
+ }
52
+ op = body.call(thisArg, _);
53
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
54
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
55
+ }
56
+ };
57
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
58
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
59
+ if (ar || !(i in from)) {
60
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
61
+ ar[i] = from[i];
62
+ }
63
+ }
64
+ return to.concat(ar || Array.prototype.slice.call(from));
65
+ };
66
+ var __importDefault = (this && this.__importDefault) || function (mod) {
67
+ return (mod && mod.__esModule) ? mod : { "default": mod };
68
+ };
69
+ Object.defineProperty(exports, "__esModule", { value: true });
70
+ var path_1 = __importDefault(require("path"));
71
+ var fs_1 = __importDefault(require("fs"));
72
+ var mkdirp_1 = __importDefault(require("mkdirp"));
73
+ var glob_promise_1 = __importDefault(require("glob-promise"));
74
+ var chokidar_1 = __importDefault(require("chokidar"));
75
+ var normalize_path_1 = __importDefault(require("normalize-path"));
76
+ var amxxpc_1 = __importStar(require("./amxxpc"));
77
+ var constants_1 = require("./constants");
78
+ var logger_1 = __importDefault(require("../logger/logger"));
79
+ var AmxxBuilder = /** @class */ (function () {
80
+ function AmxxBuilder(config) {
81
+ this.config = config;
82
+ }
83
+ AmxxBuilder.prototype.build = function () {
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ return __generator(this, function (_a) {
86
+ switch (_a.label) {
87
+ case 0:
88
+ logger_1.default.info('Building...');
89
+ return [4 /*yield*/, this.buildAssets()];
90
+ case 1:
91
+ _a.sent();
92
+ return [4 /*yield*/, this.buildInclude()];
93
+ case 2:
94
+ _a.sent();
95
+ return [4 /*yield*/, this.buildSrc()];
96
+ case 3:
97
+ _a.sent();
98
+ logger_1.default.success('Build finished!');
99
+ return [2 /*return*/];
100
+ }
101
+ });
102
+ });
103
+ };
104
+ AmxxBuilder.prototype.watch = function () {
105
+ return __awaiter(this, void 0, void 0, function () {
106
+ return __generator(this, function (_a) {
107
+ switch (_a.label) {
108
+ case 0: return [4 /*yield*/, this.watchAssets()];
109
+ case 1:
110
+ _a.sent();
111
+ return [4 /*yield*/, this.watchInclude()];
112
+ case 2:
113
+ _a.sent();
114
+ return [4 /*yield*/, this.watchSrc()];
115
+ case 3:
116
+ _a.sent();
117
+ return [2 /*return*/];
118
+ }
119
+ });
120
+ });
121
+ };
122
+ AmxxBuilder.prototype.buildSrc = function () {
123
+ return __awaiter(this, void 0, void 0, function () {
124
+ var _this = this;
125
+ return __generator(this, function (_a) {
126
+ switch (_a.label) {
127
+ case 0: return [4 /*yield*/, this.buildDir(this.config.input.scripts, constants_1.SCRIPTS_PATH_PATTERN, function (filePath) { return _this.updatePlugin(filePath); })];
128
+ case 1:
129
+ _a.sent();
130
+ return [2 /*return*/];
131
+ }
132
+ });
133
+ });
134
+ };
135
+ AmxxBuilder.prototype.buildInclude = function () {
136
+ return __awaiter(this, void 0, void 0, function () {
137
+ var _this = this;
138
+ return __generator(this, function (_a) {
139
+ switch (_a.label) {
140
+ case 0: return [4 /*yield*/, this.buildDir(this.config.input.include, constants_1.INCLUDE_PATH_PATTERN, function (filePath) { return _this.updateInclude(filePath); })];
141
+ case 1:
142
+ _a.sent();
143
+ return [2 /*return*/];
144
+ }
145
+ });
146
+ });
147
+ };
148
+ AmxxBuilder.prototype.buildAssets = function () {
149
+ return __awaiter(this, void 0, void 0, function () {
150
+ var _this = this;
151
+ return __generator(this, function (_a) {
152
+ switch (_a.label) {
153
+ case 0: return [4 /*yield*/, this.buildDir(this.config.input.assets, constants_1.ASSETS_PATH_PATTERN, function (filePath) { return _this.updateAsset(filePath); })];
154
+ case 1:
155
+ _a.sent();
156
+ return [2 /*return*/];
157
+ }
158
+ });
159
+ });
160
+ };
161
+ AmxxBuilder.prototype.watchSrc = function () {
162
+ return __awaiter(this, void 0, void 0, function () {
163
+ var _this = this;
164
+ return __generator(this, function (_a) {
165
+ switch (_a.label) {
166
+ case 0: return [4 /*yield*/, this.watchDir(this.config.input.scripts, constants_1.SCRIPTS_PATH_PATTERN, function (filePath) { return _this.updatePlugin(filePath); })];
167
+ case 1:
168
+ _a.sent();
169
+ return [2 /*return*/];
170
+ }
171
+ });
172
+ });
173
+ };
174
+ AmxxBuilder.prototype.watchInclude = function () {
175
+ return __awaiter(this, void 0, void 0, function () {
176
+ var _this = this;
177
+ return __generator(this, function (_a) {
178
+ switch (_a.label) {
179
+ case 0: return [4 /*yield*/, this.watchDir(this.config.input.include, constants_1.INCLUDE_PATH_PATTERN, function (filePath) { return _this.updateInclude(filePath); })];
180
+ case 1:
181
+ _a.sent();
182
+ return [2 /*return*/];
183
+ }
184
+ });
185
+ });
186
+ };
187
+ AmxxBuilder.prototype.watchAssets = function () {
188
+ return __awaiter(this, void 0, void 0, function () {
189
+ var _this = this;
190
+ return __generator(this, function (_a) {
191
+ switch (_a.label) {
192
+ case 0: return [4 /*yield*/, this.watchDir(this.config.input.assets, constants_1.ASSETS_PATH_PATTERN, function (filePath) { return _this.updateAsset(filePath); })];
193
+ case 1:
194
+ _a.sent();
195
+ return [2 /*return*/];
196
+ }
197
+ });
198
+ });
199
+ };
200
+ AmxxBuilder.prototype.updatePlugin = function (filePath) {
201
+ return __awaiter(this, void 0, void 0, function () {
202
+ return __generator(this, function (_a) {
203
+ switch (_a.label) {
204
+ case 0: return [4 /*yield*/, this.updateScript(filePath)];
205
+ case 1:
206
+ _a.sent();
207
+ return [4 /*yield*/, this.compilePlugin(filePath)];
208
+ case 2:
209
+ _a.sent();
210
+ return [2 /*return*/];
211
+ }
212
+ });
213
+ });
214
+ };
215
+ AmxxBuilder.prototype.updateScript = function (filePath) {
216
+ return __awaiter(this, void 0, void 0, function () {
217
+ var srcPath, destPath;
218
+ return __generator(this, function (_a) {
219
+ switch (_a.label) {
220
+ case 0:
221
+ srcPath = path_1.default.resolve(filePath);
222
+ destPath = path_1.default.join(this.config.output.scripts, path_1.default.parse(filePath).base);
223
+ return [4 /*yield*/, (0, mkdirp_1.default)(this.config.output.scripts)];
224
+ case 1:
225
+ _a.sent();
226
+ return [4 /*yield*/, fs_1.default.promises.copyFile(srcPath, destPath)];
227
+ case 2:
228
+ _a.sent();
229
+ logger_1.default.info('Script updated:', (0, normalize_path_1.default)(destPath));
230
+ return [2 /*return*/];
231
+ }
232
+ });
233
+ });
234
+ };
235
+ AmxxBuilder.prototype.updateAsset = function (filePath) {
236
+ return __awaiter(this, void 0, void 0, function () {
237
+ var srcPath, relativePath, destPath;
238
+ return __generator(this, function (_a) {
239
+ switch (_a.label) {
240
+ case 0:
241
+ srcPath = path_1.default.resolve(filePath);
242
+ relativePath = path_1.default.relative(this.config.input.assets, filePath);
243
+ destPath = path_1.default.join(this.config.output.assets, relativePath);
244
+ return [4 /*yield*/, (0, mkdirp_1.default)(path_1.default.parse(destPath).dir)];
245
+ case 1:
246
+ _a.sent();
247
+ return [4 /*yield*/, fs_1.default.promises.copyFile(srcPath, destPath)];
248
+ case 2:
249
+ _a.sent();
250
+ logger_1.default.info('Asset updated', (0, normalize_path_1.default)(destPath));
251
+ return [2 /*return*/];
252
+ }
253
+ });
254
+ });
255
+ };
256
+ AmxxBuilder.prototype.updateInclude = function (filePath) {
257
+ return __awaiter(this, void 0, void 0, function () {
258
+ var srcPath, destPath;
259
+ return __generator(this, function (_a) {
260
+ switch (_a.label) {
261
+ case 0:
262
+ srcPath = path_1.default.resolve(filePath);
263
+ destPath = path_1.default.join(this.config.output.include, path_1.default.parse(filePath).base);
264
+ return [4 /*yield*/, (0, mkdirp_1.default)(this.config.output.include)];
265
+ case 1:
266
+ _a.sent();
267
+ return [4 /*yield*/, fs_1.default.promises.copyFile(srcPath, destPath)];
268
+ case 2:
269
+ _a.sent();
270
+ logger_1.default.info('Include updated:', (0, normalize_path_1.default)(destPath));
271
+ return [2 /*return*/];
272
+ }
273
+ });
274
+ });
275
+ };
276
+ AmxxBuilder.prototype.findPlugins = function (pattern) {
277
+ return __awaiter(this, void 0, void 0, function () {
278
+ var pathPattern, matches;
279
+ return __generator(this, function (_a) {
280
+ switch (_a.label) {
281
+ case 0:
282
+ pathPattern = path_1.default.join(this.config.input.scripts, '**', pattern);
283
+ return [4 /*yield*/, (0, glob_promise_1.default)(pathPattern)];
284
+ case 1:
285
+ matches = _a.sent();
286
+ return [2 /*return*/, matches];
287
+ }
288
+ });
289
+ });
290
+ };
291
+ AmxxBuilder.prototype.compilePlugin = function (filePath) {
292
+ return __awaiter(this, void 0, void 0, function () {
293
+ var srcPath, destDir, srcDir, relateiveSrcPath, executable, result, destPath, relativeFilePath;
294
+ return __generator(this, function (_a) {
295
+ switch (_a.label) {
296
+ case 0:
297
+ srcPath = path_1.default.resolve(filePath);
298
+ destDir = path_1.default.resolve(this.config.output.plugins);
299
+ if (!this.config.rules.flatCompilation) {
300
+ srcDir = path_1.default.parse(srcPath).dir;
301
+ destDir = path_1.default.join(destDir, path_1.default.relative(this.config.input.scripts, srcDir));
302
+ }
303
+ relateiveSrcPath = path_1.default.relative(process.cwd(), srcPath);
304
+ executable = path_1.default.join(this.config.compiler.dir, this.config.compiler.executable);
305
+ return [4 /*yield*/, (0, mkdirp_1.default)(destDir)];
306
+ case 1:
307
+ _a.sent();
308
+ return [4 /*yield*/, (0, amxxpc_1.default)({
309
+ path: srcPath,
310
+ dest: destDir,
311
+ compiler: executable,
312
+ includeDir: __spreadArray(__spreadArray([
313
+ path_1.default.join(this.config.compiler.dir, 'include')
314
+ ], this.config.include, true), [
315
+ this.config.input.include,
316
+ ], false)
317
+ })];
318
+ case 2:
319
+ result = _a.sent();
320
+ result.output.messages.forEach(function (message) {
321
+ var startLine = message.startLine, type = message.type, code = message.code, text = message.text;
322
+ if (type === amxxpc_1.AMXPCMessageType.Error || type === amxxpc_1.AMXPCMessageType.FatalError) {
323
+ logger_1.default.error("".concat((0, normalize_path_1.default)(relateiveSrcPath), "(").concat(startLine, ")"), type, code, ':', text);
324
+ }
325
+ else if (type === amxxpc_1.AMXPCMessageType.Warning) {
326
+ logger_1.default.warn("".concat((0, normalize_path_1.default)(relateiveSrcPath), "(").concat(startLine, ")"), type, code, ':', text);
327
+ }
328
+ else if (type === amxxpc_1.AMXPCMessageType.Echo) {
329
+ logger_1.default.debug(text);
330
+ }
331
+ });
332
+ if (result.success) {
333
+ destPath = path_1.default.join(destDir, result.plugin);
334
+ relativeFilePath = path_1.default.relative(process.cwd(), filePath);
335
+ logger_1.default.success('Compilation success:', (0, normalize_path_1.default)(relativeFilePath));
336
+ logger_1.default.info('Plugin updated:', (0, normalize_path_1.default)(destPath));
337
+ }
338
+ else {
339
+ throw new Error("Failed to compile ".concat((0, normalize_path_1.default)(relateiveSrcPath), " : \"").concat(result.error, "\""));
340
+ }
341
+ return [2 /*return*/];
342
+ }
343
+ });
344
+ });
345
+ };
346
+ AmxxBuilder.prototype.buildDir = function (baseDir, pattern, cb) {
347
+ return __awaiter(this, void 0, void 0, function () {
348
+ var pathPattern, matches;
349
+ return __generator(this, function (_a) {
350
+ switch (_a.label) {
351
+ case 0:
352
+ pathPattern = path_1.default.join(baseDir, pattern);
353
+ return [4 /*yield*/, (0, glob_promise_1.default)(pathPattern, { nodir: true })];
354
+ case 1:
355
+ matches = _a.sent();
356
+ return [4 /*yield*/, matches.reduce(function (acc, match) { return acc.then(function () { return cb(match); }); }, Promise.resolve())];
357
+ case 2:
358
+ _a.sent();
359
+ return [2 /*return*/];
360
+ }
361
+ });
362
+ });
363
+ };
364
+ AmxxBuilder.prototype.watchDir = function (baseDir, pattern, cb) {
365
+ return __awaiter(this, void 0, void 0, function () {
366
+ var pathPattern, watcher, updateFn;
367
+ return __generator(this, function (_a) {
368
+ pathPattern = path_1.default.join(baseDir, pattern);
369
+ watcher = chokidar_1.default.watch(pathPattern, { ignoreInitial: true });
370
+ updateFn = function (filePath) { return cb(filePath).catch(function (err) { return logger_1.default.error(err.message); }); };
371
+ watcher.on('add', updateFn);
372
+ watcher.on('change', updateFn);
373
+ return [2 /*return*/];
374
+ });
375
+ });
376
+ };
377
+ return AmxxBuilder;
378
+ }());
379
+ exports.default = AmxxBuilder;