amxxpack 1.3.3 → 1.4.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.
- package/README.md +24 -0
- package/lib/builder/builder.js +19 -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 +12 -10
- 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
|
@@ -428,6 +428,9 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
428
428
|
return __generator(this, function (_a) {
|
|
429
429
|
switch (_a.label) {
|
|
430
430
|
case 0:
|
|
431
|
+
if (!this.projectConfig.output.include) {
|
|
432
|
+
return [2 /*return*/];
|
|
433
|
+
}
|
|
431
434
|
destPath = path_1.default.join(this.projectConfig.output.include, path_1.default.parse(filePath).base);
|
|
432
435
|
return [4 /*yield*/, (0, mkdirp_1.default)(this.projectConfig.output.include)];
|
|
433
436
|
case 1:
|
|
@@ -510,10 +513,10 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
510
513
|
var startLine = message.startLine, type = message.type, code = message.code, text = message.text, filename = message.filename;
|
|
511
514
|
var relativeFilePath = filename ? path_1.default.relative(process.cwd(), filename) : relateiveSrcPath;
|
|
512
515
|
if (type === amxxpc_1.AMXPCMessageType.Error || type === amxxpc_1.AMXPCMessageType.FatalError) {
|
|
513
|
-
logger_1.default.error("".concat((0, normalize_path_1.default)(relativeFilePath), "
|
|
516
|
+
logger_1.default.error("".concat((0, normalize_path_1.default)(relativeFilePath), ":").concat(startLine), '-', type, code, ':', text);
|
|
514
517
|
}
|
|
515
518
|
else if (type === amxxpc_1.AMXPCMessageType.Warning) {
|
|
516
|
-
logger_1.default.warn("".concat((0, normalize_path_1.default)(relativeFilePath), "
|
|
519
|
+
logger_1.default.warn("".concat((0, normalize_path_1.default)(relativeFilePath), ":").concat(startLine), '-', type, code, ':', text);
|
|
517
520
|
}
|
|
518
521
|
else if (type === amxxpc_1.AMXPCMessageType.Echo) {
|
|
519
522
|
logger_1.default.debug(text);
|
|
@@ -554,10 +557,23 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
554
557
|
AmxxBuilder.prototype.watchDir = function (baseDir, pattern, cb) {
|
|
555
558
|
return __awaiter(this, void 0, void 0, function () {
|
|
556
559
|
var pathPattern, watcher, updateFn;
|
|
560
|
+
var _this = this;
|
|
557
561
|
return __generator(this, function (_a) {
|
|
558
562
|
pathPattern = (0, lodash_1.map)((0, lodash_1.castArray)(baseDir), function (dir) { return path_1.default.join(dir, pattern); });
|
|
559
563
|
watcher = (0, setup_watch_1.default)(pathPattern);
|
|
560
|
-
updateFn = function (filePath) { return
|
|
564
|
+
updateFn = function (filePath) { return __awaiter(_this, void 0, void 0, function () {
|
|
565
|
+
return __generator(this, function (_a) {
|
|
566
|
+
switch (_a.label) {
|
|
567
|
+
case 0:
|
|
568
|
+
logger_1.default.info('File change detected. Starting incremental compilation...');
|
|
569
|
+
return [4 /*yield*/, cb(path_1.default.normalize(filePath)).catch(function (err) { return logger_1.default.error(err.message); })];
|
|
570
|
+
case 1:
|
|
571
|
+
_a.sent();
|
|
572
|
+
logger_1.default.info('Compilation complete. Watching for file changes.');
|
|
573
|
+
return [2 /*return*/];
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
}); };
|
|
561
577
|
watcher.on('add', updateFn);
|
|
562
578
|
watcher.on('change', updateFn);
|
|
563
579
|
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) {
|
|
@@ -17,26 +17,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
var lodash_1 = require("lodash");
|
|
18
18
|
var path_1 = __importDefault(require("path"));
|
|
19
19
|
var defaults_1 = __importDefault(require("./defaults"));
|
|
20
|
+
var mergeConfigFn = function (val1, val2) { return ((0, lodash_1.isNil)(val2) ? val1 : undefined); };
|
|
20
21
|
function resolve(overrides, projectDir) {
|
|
21
22
|
if (overrides === void 0) { overrides = {}; }
|
|
22
23
|
if (projectDir === void 0) { projectDir = ''; }
|
|
23
|
-
var resolvePath = function (p) { return path_1.default.resolve(projectDir || '', p); };
|
|
24
|
-
var config = (0, lodash_1.
|
|
24
|
+
var resolvePath = function (p) { return (!(0, lodash_1.isNil)(p) ? path_1.default.resolve(projectDir || '', p) : null); };
|
|
25
|
+
var config = (0, lodash_1.mergeWith)({}, defaults_1.default, overrides, mergeConfigFn);
|
|
26
|
+
var outputBaseDir = resolvePath(config.output.base);
|
|
25
27
|
// resolve paths
|
|
26
28
|
var resolvedConfig = (0, lodash_1.merge)(config, {
|
|
27
29
|
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 (
|
|
30
|
+
scripts: (0, lodash_1.map)((0, lodash_1.castArray)(config.input.scripts), resolvePath),
|
|
31
|
+
include: (0, lodash_1.map)((0, lodash_1.castArray)(config.input.include), resolvePath),
|
|
32
|
+
assets: (0, lodash_1.map)((0, lodash_1.castArray)(config.input.assets), function (input) { return ((0, lodash_1.isObject)(input)
|
|
31
33
|
? __assign(__assign({}, input), { dir: resolvePath(input.dir) }) : { dir: resolvePath(input) }); })
|
|
32
34
|
},
|
|
33
35
|
output: {
|
|
34
|
-
scripts:
|
|
35
|
-
plugins:
|
|
36
|
-
include:
|
|
37
|
-
assets:
|
|
36
|
+
scripts: path_1.default.resolve(outputBaseDir, config.output.scripts),
|
|
37
|
+
plugins: path_1.default.resolve(outputBaseDir, config.output.plugins),
|
|
38
|
+
include: path_1.default.resolve(outputBaseDir, config.output.include),
|
|
39
|
+
assets: path_1.default.resolve(outputBaseDir, config.output.assets)
|
|
38
40
|
},
|
|
39
|
-
include: (0, lodash_1.map)(config.include,
|
|
41
|
+
include: (0, lodash_1.map)(config.include, resolvePath),
|
|
40
42
|
compiler: {
|
|
41
43
|
dir: resolvePath(config.compiler.dir),
|
|
42
44
|
},
|
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
|
}
|