amxxpack 1.3.2 → 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 CHANGED
@@ -52,7 +52,7 @@ npm install -g amxxpack
52
52
  - `amxxpack compile <path|glob>` - compile specific plugin in the project
53
53
  - `--config` - config file
54
54
  - `--no-cache` - disable caching
55
- - `amxxpack new <script|lib|include> [name]` - create a new file in the project workspace
55
+ - `amxxpack generate <script|lib|include> [name]` - create a new file in the project workspace
56
56
  - `--config` - config file
57
57
  - `--name` - plugin name
58
58
  - `--version` - plugin version
@@ -61,7 +61,7 @@ npm install -g amxxpack
61
61
  - `--include` - include list separated by a comma
62
62
  - `--overwrite` - overwrite the file if it already exists
63
63
  - `amxpack i` - alias to `install` command
64
- - `amxpack n` - alias to `new` command
64
+ - `amxpack g` - alias to `generate` command
65
65
  - `amxpack b` - alias to `build` command
66
66
  - `amxpack c` - alias to `compile` command
67
67
 
@@ -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
+ ```
@@ -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), "(").concat(startLine, ")"), type, code, ':', text);
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), "(").concat(startLine, ")"), type, code, ':', text);
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 cb(path_1.default.normalize(filePath)).catch(function (err) { return logger_1.default.error(err.message); }); };
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*/];
@@ -141,8 +141,10 @@ program
141
141
  });
142
142
  }); });
143
143
  program
144
- .command('new')
144
+ .command('generate')
145
+ .alias('new')
145
146
  .alias('n')
147
+ .alias('g')
146
148
  .arguments('<type> <filename>')
147
149
  .option('--config, -c <path>', 'Config file', config_1.default.projectConfig)
148
150
  .option('--name, -n <name>', 'Plugin name')
@@ -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
- return [4 /*yield*/, fs_1.default.promises.writeFile(configPath, JSON.stringify(project_config_1.default.defaults, null, 2))];
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:
@@ -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) {
@@ -7,6 +7,7 @@ exports.default = {
7
7
  assets: './assets',
8
8
  },
9
9
  output: {
10
+ base: '',
10
11
  scripts: './dist/addons/amxmodx/scripting',
11
12
  plugins: './dist/addons/amxmodx/plugins',
12
13
  include: './dist/addons/amxmodx/scripting/include',
@@ -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.merge)({}, defaults_1.default, overrides);
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), function (dir) { return resolvePath(dir); }),
29
- include: (0, lodash_1.map)((0, lodash_1.castArray)(config.input.include), function (dir) { return resolvePath(dir); }),
30
- assets: (0, lodash_1.map)((0, lodash_1.castArray)(config.input.assets), function (input) { return (typeof input === 'object'
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: resolvePath(config.output.scripts),
35
- plugins: resolvePath(config.output.plugins),
36
- include: resolvePath(config.output.include),
37
- assets: resolvePath(config.output.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, function (include) { return resolvePath(include); }),
41
+ include: (0, lodash_1.map)(config.include, resolvePath),
40
42
  compiler: {
41
43
  dir: resolvePath(config.compiler.dir),
42
44
  },
@@ -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: string | string[] | IAssetInput | IAssetInput[];
8
+ scripts: null | string | string[];
9
+ include: null | string | string[];
10
+ assets: null | string | IAssetInput | (string | IAssetInput)[];
11
11
  };
12
12
  output: {
13
- scripts: string;
14
- plugins: string;
15
- include: string;
16
- assets: string;
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
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "amxxpack",
3
3
  "description": "AMXXPack",
4
4
  "author": "Hedgehog Fog",
5
- "version": "1.3.2",
5
+ "version": "1.4.0",
6
6
  "license": "MIT",
7
7
  "main": "lib/builder/index.js",
8
8
  "types": "lib/builder/index.d.ts",