amxxpack 1.3.3 → 1.4.1
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.
- package/README.md +24 -0
- package/lib/builder/builder.js +25 -3
- package/lib/cli/services/project-creator.js +11 -2
- package/lib/downloaders/compiler/downloader.js +4 -0
- package/lib/logger/logger.js +2 -1
- package/lib/project-config/defaults.js +1 -0
- package/lib/project-config/resolve.js +10 -9
- package/lib/types/index.d.ts +24 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -140,3 +140,27 @@ You can also specify subdirectories for copying. With this configuration, the bu
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
```
|
|
143
|
+
|
|
144
|
+
### Compiler configuration
|
|
145
|
+
Using the `compiler` configuration you can specify the compiler version you want to use.
|
|
146
|
+
|
|
147
|
+
For example, if you want to use AmxModX 1.9 with `cstrike` addon in your project, then use this configuration:
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"compiler": {
|
|
151
|
+
"version": "1.9",
|
|
152
|
+
"addons": ["cstrike"]
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
In case you want to use a dev build from `amxxdrop` you should set `dev` flag to `true` and specify the build you want to use in the `version` field:
|
|
158
|
+
```json
|
|
159
|
+
{
|
|
160
|
+
"compiler": {
|
|
161
|
+
"version": "1.10.0-git5467",
|
|
162
|
+
"dev": true,
|
|
163
|
+
"addons": ["cstrike"]
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
package/lib/builder/builder.js
CHANGED
|
@@ -405,6 +405,9 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
405
405
|
return __generator(this, function (_a) {
|
|
406
406
|
switch (_a.label) {
|
|
407
407
|
case 0:
|
|
408
|
+
if (!this.projectConfig.output.assets) {
|
|
409
|
+
return [2 /*return*/];
|
|
410
|
+
}
|
|
408
411
|
srcFile = path_1.default.relative(assetInput.dir, filePath);
|
|
409
412
|
if (assetInput.filter && !this.execPathFilter(srcFile, assetInput.filter)) {
|
|
410
413
|
return [2 /*return*/];
|
|
@@ -428,6 +431,9 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
428
431
|
return __generator(this, function (_a) {
|
|
429
432
|
switch (_a.label) {
|
|
430
433
|
case 0:
|
|
434
|
+
if (!this.projectConfig.output.include) {
|
|
435
|
+
return [2 /*return*/];
|
|
436
|
+
}
|
|
431
437
|
destPath = path_1.default.join(this.projectConfig.output.include, path_1.default.parse(filePath).base);
|
|
432
438
|
return [4 /*yield*/, (0, mkdirp_1.default)(this.projectConfig.output.include)];
|
|
433
439
|
case 1:
|
|
@@ -463,6 +469,9 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
463
469
|
return __generator(this, function (_c) {
|
|
464
470
|
switch (_c.label) {
|
|
465
471
|
case 0:
|
|
472
|
+
if (!this.projectConfig.output.plugins) {
|
|
473
|
+
return [2 /*return*/];
|
|
474
|
+
}
|
|
466
475
|
srcPath = path_1.default.join(srcDir, srcFile);
|
|
467
476
|
_a = path_1.default.parse(srcFile), scriptName = _a.name, srcNestedDir = _a.dir;
|
|
468
477
|
destDir = path_1.default.join(this.projectConfig.output.plugins, this.projectConfig.rules.flatCompilation ? '.' : srcNestedDir);
|
|
@@ -510,10 +519,10 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
510
519
|
var startLine = message.startLine, type = message.type, code = message.code, text = message.text, filename = message.filename;
|
|
511
520
|
var relativeFilePath = filename ? path_1.default.relative(process.cwd(), filename) : relateiveSrcPath;
|
|
512
521
|
if (type === amxxpc_1.AMXPCMessageType.Error || type === amxxpc_1.AMXPCMessageType.FatalError) {
|
|
513
|
-
logger_1.default.error("".concat((0, normalize_path_1.default)(relativeFilePath), "
|
|
522
|
+
logger_1.default.error("".concat((0, normalize_path_1.default)(relativeFilePath), ":").concat(startLine), '-', type, code, ':', text);
|
|
514
523
|
}
|
|
515
524
|
else if (type === amxxpc_1.AMXPCMessageType.Warning) {
|
|
516
|
-
logger_1.default.warn("".concat((0, normalize_path_1.default)(relativeFilePath), "
|
|
525
|
+
logger_1.default.warn("".concat((0, normalize_path_1.default)(relativeFilePath), ":").concat(startLine), '-', type, code, ':', text);
|
|
517
526
|
}
|
|
518
527
|
else if (type === amxxpc_1.AMXPCMessageType.Echo) {
|
|
519
528
|
logger_1.default.debug(text);
|
|
@@ -554,10 +563,23 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
554
563
|
AmxxBuilder.prototype.watchDir = function (baseDir, pattern, cb) {
|
|
555
564
|
return __awaiter(this, void 0, void 0, function () {
|
|
556
565
|
var pathPattern, watcher, updateFn;
|
|
566
|
+
var _this = this;
|
|
557
567
|
return __generator(this, function (_a) {
|
|
558
568
|
pathPattern = (0, lodash_1.map)((0, lodash_1.castArray)(baseDir), function (dir) { return path_1.default.join(dir, pattern); });
|
|
559
569
|
watcher = (0, setup_watch_1.default)(pathPattern);
|
|
560
|
-
updateFn = function (filePath) { return
|
|
570
|
+
updateFn = function (filePath) { return __awaiter(_this, void 0, void 0, function () {
|
|
571
|
+
return __generator(this, function (_a) {
|
|
572
|
+
switch (_a.label) {
|
|
573
|
+
case 0:
|
|
574
|
+
logger_1.default.info('File change detected. Starting incremental compilation...');
|
|
575
|
+
return [4 /*yield*/, cb(path_1.default.normalize(filePath)).catch(function (err) { return logger_1.default.error(err.message); })];
|
|
576
|
+
case 1:
|
|
577
|
+
_a.sent();
|
|
578
|
+
logger_1.default.info('Compilation complete. Watching for file changes.');
|
|
579
|
+
return [2 /*return*/];
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
}); };
|
|
561
583
|
watcher.on('add', updateFn);
|
|
562
584
|
watcher.on('change', updateFn);
|
|
563
585
|
return [2 /*return*/];
|
|
@@ -183,7 +183,7 @@ var ProjectCreator = /** @class */ (function () {
|
|
|
183
183
|
};
|
|
184
184
|
ProjectCreator.prototype.createConfig = function () {
|
|
185
185
|
return __awaiter(this, void 0, void 0, function () {
|
|
186
|
-
var configPath;
|
|
186
|
+
var configPath, projectConfig;
|
|
187
187
|
return __generator(this, function (_a) {
|
|
188
188
|
switch (_a.label) {
|
|
189
189
|
case 0:
|
|
@@ -192,7 +192,16 @@ var ProjectCreator = /** @class */ (function () {
|
|
|
192
192
|
case 1:
|
|
193
193
|
_a.sent();
|
|
194
194
|
configPath = path_1.default.join(this.projectDir, config_1.default.projectConfig);
|
|
195
|
-
|
|
195
|
+
projectConfig = (0, lodash_1.merge)({}, project_config_1.default.defaults, {
|
|
196
|
+
output: {
|
|
197
|
+
base: './dist',
|
|
198
|
+
scripts: './addons/amxmodx/scripting',
|
|
199
|
+
plugins: './addons/amxmodx/plugins',
|
|
200
|
+
include: './addons/amxmodx/scripting/include',
|
|
201
|
+
assets: './'
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
return [4 /*yield*/, fs_1.default.promises.writeFile(configPath, JSON.stringify(projectConfig, null, 2))];
|
|
196
205
|
case 2:
|
|
197
206
|
_a.sent();
|
|
198
207
|
return [2 /*return*/];
|
|
@@ -107,6 +107,9 @@ function downloadDist(dist) {
|
|
|
107
107
|
case 0: return [4 /*yield*/, getDistFileName(dist)];
|
|
108
108
|
case 1:
|
|
109
109
|
fileName = _a.sent();
|
|
110
|
+
if (!fileName) {
|
|
111
|
+
throw new Error('Failed to fetch dist file meta!');
|
|
112
|
+
}
|
|
110
113
|
downloadOpts = (0, resolvers_1.resolveDownloadDistOpts)(fileName, dist);
|
|
111
114
|
return [4 /*yield*/, (0, download_1.default)(downloadOpts.url, downloadOpts.path)];
|
|
112
115
|
case 2:
|
|
@@ -166,6 +169,7 @@ function downloadCompiler(options) {
|
|
|
166
169
|
return [4 /*yield*/, Promise.all((0, lodash_1.map)(dists, downloadDist))];
|
|
167
170
|
case 1:
|
|
168
171
|
distArchives = _a.sent();
|
|
172
|
+
logger_1.default.info('Extracting compiler files...');
|
|
169
173
|
_i = 0, distArchives_1 = distArchives;
|
|
170
174
|
_a.label = 2;
|
|
171
175
|
case 2:
|
package/lib/logger/logger.js
CHANGED
|
@@ -68,8 +68,9 @@ var Logger = /** @class */ (function () {
|
|
|
68
68
|
.join(' ');
|
|
69
69
|
var label = this.getLevelLabel(level);
|
|
70
70
|
var coloredMessage = this.colorifyMessageByLevel(level, message);
|
|
71
|
+
var time = (new Date()).toLocaleTimeString();
|
|
71
72
|
// eslint-disable-next-line no-console
|
|
72
|
-
console.log(label, coloredMessage);
|
|
73
|
+
console.log("[".concat(time, "]"), label, coloredMessage);
|
|
73
74
|
};
|
|
74
75
|
Logger.prototype.colorifyMessageByLevel = function (level, message) {
|
|
75
76
|
switch (level) {
|
|
@@ -20,23 +20,24 @@ var defaults_1 = __importDefault(require("./defaults"));
|
|
|
20
20
|
function resolve(overrides, projectDir) {
|
|
21
21
|
if (overrides === void 0) { overrides = {}; }
|
|
22
22
|
if (projectDir === void 0) { projectDir = ''; }
|
|
23
|
-
var resolvePath = function (p) { return path_1.default.resolve(projectDir || '', p); };
|
|
24
23
|
var config = (0, lodash_1.merge)({}, defaults_1.default, overrides);
|
|
24
|
+
var resolvePath = function (p) { return path_1.default.resolve(projectDir, p); };
|
|
25
|
+
var resolveOutputPath = function (p) { return ((0, lodash_1.isNull)(p) ? null : path_1.default.resolve(projectDir, config.output.base || '', p)); };
|
|
25
26
|
// resolve paths
|
|
26
27
|
var resolvedConfig = (0, lodash_1.merge)(config, {
|
|
27
28
|
input: {
|
|
28
|
-
scripts: (0, lodash_1.map)((0, lodash_1.castArray)(config.input.scripts),
|
|
29
|
-
include: (0, lodash_1.map)((0, lodash_1.castArray)(config.input.include),
|
|
30
|
-
assets: (0, lodash_1.map)((0, lodash_1.castArray)(config.input.assets), function (input) { return (
|
|
29
|
+
scripts: (0, lodash_1.map)((0, lodash_1.castArray)(config.input.scripts), resolvePath),
|
|
30
|
+
include: (0, lodash_1.map)((0, lodash_1.castArray)(config.input.include), resolvePath),
|
|
31
|
+
assets: (0, lodash_1.map)((0, lodash_1.castArray)(config.input.assets), function (input) { return ((0, lodash_1.isObject)(input)
|
|
31
32
|
? __assign(__assign({}, input), { dir: resolvePath(input.dir) }) : { dir: resolvePath(input) }); })
|
|
32
33
|
},
|
|
33
34
|
output: {
|
|
34
|
-
scripts:
|
|
35
|
-
plugins:
|
|
36
|
-
include:
|
|
37
|
-
assets:
|
|
35
|
+
scripts: resolveOutputPath(config.output.scripts),
|
|
36
|
+
plugins: resolveOutputPath(config.output.plugins),
|
|
37
|
+
include: resolveOutputPath(config.output.include),
|
|
38
|
+
assets: resolveOutputPath(config.output.assets)
|
|
38
39
|
},
|
|
39
|
-
include: (0, lodash_1.map)(config.include,
|
|
40
|
+
include: (0, lodash_1.map)(config.include, resolvePath),
|
|
40
41
|
compiler: {
|
|
41
42
|
dir: resolvePath(config.compiler.dir),
|
|
42
43
|
},
|
package/lib/types/index.d.ts
CHANGED
|
@@ -5,31 +5,32 @@ export interface IAssetInput {
|
|
|
5
5
|
}
|
|
6
6
|
export interface IProjectConfig {
|
|
7
7
|
input: {
|
|
8
|
-
scripts: string | string[];
|
|
9
|
-
include: string | string[];
|
|
10
|
-
assets:
|
|
8
|
+
scripts: null | string | string[];
|
|
9
|
+
include: null | string | string[];
|
|
10
|
+
assets: null | string | IAssetInput | (string | IAssetInput)[];
|
|
11
11
|
};
|
|
12
12
|
output: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
base?: null | string;
|
|
14
|
+
scripts: null | string;
|
|
15
|
+
plugins: null | string;
|
|
16
|
+
include: null | string;
|
|
17
|
+
assets: null | string;
|
|
17
18
|
};
|
|
18
19
|
compiler: {
|
|
19
|
-
dir: string;
|
|
20
|
+
dir: null | string;
|
|
20
21
|
version: string;
|
|
21
22
|
addons: [];
|
|
22
23
|
dev: boolean;
|
|
23
24
|
executable: string;
|
|
24
25
|
};
|
|
25
26
|
thirdparty: {
|
|
26
|
-
dir: string;
|
|
27
|
+
dir: string | null;
|
|
27
28
|
dependencies: {
|
|
28
29
|
name: string;
|
|
29
30
|
url: string;
|
|
30
31
|
}[];
|
|
31
32
|
};
|
|
32
|
-
include: string[];
|
|
33
|
+
include: null | string[];
|
|
33
34
|
rules: {
|
|
34
35
|
flatCompilation: boolean;
|
|
35
36
|
};
|
|
@@ -54,4 +55,17 @@ export interface IResolvedProjectConfig extends IProjectConfig {
|
|
|
54
55
|
include: string[];
|
|
55
56
|
assets: IAssetInput[];
|
|
56
57
|
};
|
|
58
|
+
output: {
|
|
59
|
+
scripts: string;
|
|
60
|
+
plugins: string;
|
|
61
|
+
include: string;
|
|
62
|
+
assets: string;
|
|
63
|
+
};
|
|
64
|
+
include: string[];
|
|
65
|
+
compiler: IProjectConfig['compiler'] & {
|
|
66
|
+
dir: string;
|
|
67
|
+
};
|
|
68
|
+
thirdparty: IProjectConfig['thirdparty'] & {
|
|
69
|
+
dir: string;
|
|
70
|
+
};
|
|
57
71
|
}
|