amxxpack 0.1.4 → 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 (61) hide show
  1. package/README.md +25 -20
  2. package/lib/builder/builder.d.ts +2 -3
  3. package/lib/builder/builder.js +19 -40
  4. package/lib/builder/index.d.ts +0 -1
  5. package/lib/builder/index.js +0 -11
  6. package/lib/cli/controller.d.ts +13 -9
  7. package/lib/cli/controller.js +106 -49
  8. package/lib/cli/index.d.ts +2 -1
  9. package/lib/cli/index.js +5 -0
  10. package/lib/cli/program.js +76 -20
  11. package/lib/cli/services/project-creator.d.ts +21 -0
  12. package/lib/cli/services/project-creator.js +274 -0
  13. package/lib/cli/services/template-builder.d.ts +11 -0
  14. package/lib/cli/services/template-builder.js +104 -0
  15. package/lib/cli/types.d.ts +12 -0
  16. package/lib/{builder → cli}/types.js +0 -0
  17. package/lib/config/index.d.ts +8 -0
  18. package/lib/config/index.js +14 -0
  19. package/lib/downloaders/compiler/constants.d.ts +9 -0
  20. package/lib/{compiler-downloader → downloaders/compiler}/constants.js +1 -4
  21. package/lib/downloaders/compiler/downloader.d.ts +3 -0
  22. package/lib/{compiler-downloader → downloaders/compiler}/downloader.js +14 -37
  23. package/lib/{compiler-downloader → downloaders/compiler}/index.d.ts +0 -0
  24. package/lib/{compiler-downloader → downloaders/compiler}/index.js +0 -0
  25. package/lib/{compiler-downloader → downloaders/compiler}/resolvers.d.ts +1 -1
  26. package/lib/{compiler-downloader → downloaders/compiler}/resolvers.js +2 -1
  27. package/lib/{compiler-downloader → downloaders/compiler}/types.d.ts +0 -0
  28. package/lib/{compiler-downloader → downloaders/compiler}/types.js +0 -0
  29. package/lib/downloaders/thirdparty/downloader.d.ts +3 -0
  30. package/lib/downloaders/thirdparty/downloader.js +69 -0
  31. package/lib/downloaders/thirdparty/index.d.ts +1 -0
  32. package/lib/downloaders/thirdparty/index.js +9 -0
  33. package/lib/downloaders/thirdparty/types.d.ts +5 -0
  34. package/lib/downloaders/thirdparty/types.js +2 -0
  35. package/lib/logger/constants.d.ts +7 -0
  36. package/lib/logger/constants.js +12 -0
  37. package/lib/{services → logger}/logger.d.ts +5 -11
  38. package/lib/{services → logger}/logger.js +17 -25
  39. package/lib/logger/types.d.ts +3 -0
  40. package/lib/logger/types.js +2 -0
  41. package/lib/project-config/defaults.d.ts +3 -0
  42. package/lib/project-config/defaults.js +38 -0
  43. package/lib/project-config/index.d.ts +6 -0
  44. package/lib/project-config/index.js +8 -0
  45. package/lib/project-config/resolve.d.ts +3 -0
  46. package/lib/project-config/resolve.js +110 -0
  47. package/lib/types/index.d.ts +45 -0
  48. package/lib/types/index.js +2 -0
  49. package/lib/utils/accumulator.d.ts +2 -1
  50. package/lib/utils/download.d.ts +6 -0
  51. package/lib/utils/download.js +63 -0
  52. package/package.json +7 -1
  53. package/resources/templates/include-directive.txt +1 -0
  54. package/resources/templates/include.txt +5 -0
  55. package/resources/templates/library-include.txt +6 -0
  56. package/resources/templates/library-script.txt +10 -0
  57. package/resources/templates/script.txt +5 -0
  58. package/lib/builder/types.d.ts +0 -20
  59. package/lib/compiler-downloader/constants.d.ts +0 -12
  60. package/lib/compiler-downloader/downloader.d.ts +0 -2
  61. package/resources/default-config.json +0 -22
package/README.md CHANGED
@@ -27,32 +27,37 @@ npm install -g amxxpack
27
27
  ```
28
28
 
29
29
  ## ▶ Quick start
30
- - Create new directory for your project
31
- - Open a terminal inside the project directory
32
- - Execute `npm init -y` command to init the package
30
+ - Open a terminal inside the project directory (existing or create a new one)
33
31
  - Execute `npm install amxxpack --save-dev` command to install `amxxpack` locally
34
- - Execute `npx amxxpack init` command to create new config
35
- - Execute `npx amxxpack fetch-compiler` to download latest compiler release
36
- - Use `npx amxxpack build` command to build the project
37
- - Adding build scripts *(optional)*
38
-
39
- To use `npm run build` and `npm run watch` to build or watch the project update the `scripts` section in `package.json`:
40
- ```json
41
- "scripts": {
42
- "build": "amxxpack build",
43
- "watch": "amxxpack build --watch"
44
- }
45
- ```
32
+ - Execute `npx amxxpack create .` command to create new config
33
+ - Execute `npx amxxpack install` to download project dependencies (compiler, thirdparty etc.)
34
+ - Use `npm run build` command to build the project
35
+ - Use `npm run watch` command to build the project and watch changes
46
36
 
47
37
  ## 📋 Commands
48
- - `amxxpack init` - init config for a new project
38
+ - `amxxpack create <name>` - create new project
39
+ - `--git` - initialize git
40
+ - `--nonpm` - don't initialize npm pacakge
41
+ - `--version` - project version
42
+ - `--author` - project author
43
+ - `--description` - project name
44
+ - `amxxpack config` - initialize project config in current workspace
45
+ - `amxxpack install` - install project dependencies
46
+ - `--config` - config file
49
47
  - `amxxpack build` - command to build the project
50
48
  - `--watch` - flag to watch changes
51
49
  - `--config` - config file
52
50
  - `amxxpack compile <path|glob>` - compile specific plugin in the project
53
51
  - `--config` - config file
54
- - `amxxpack fetch-compiler` - fetch amxmodx compiler
52
+ - `amxxpack new <script|lib|include> [name]` - create new file in the project workspace
55
53
  - `--config` - config file
56
- - `--version` - compiler version
57
- - `--addon` - addon name
58
- - `--dev` - search for dev build
54
+ - `--name` - plugin name
55
+ - `--version` - plugin version
56
+ - `--author` - plugin author
57
+ - `--lib` - library name
58
+ - `--include` - include list separated by a comma
59
+ - `--overwrite` - overwrite file if it already exists
60
+ - `amxpack i` - alias to `install` command
61
+ - `amxpack n` - alias to `new` command
62
+ - `amxpack b` - alias to `build` command
63
+ - `amxpack c` - alias to `compile` command
@@ -1,8 +1,7 @@
1
- import { IAmxxBuilderConfig } from './types';
1
+ import { IProjectConfig } from '../types';
2
2
  export default class AmxxBuilder {
3
- private logger;
4
3
  private config;
5
- constructor(config: IAmxxBuilderConfig);
4
+ constructor(config: IProjectConfig);
6
5
  build(): Promise<void>;
7
6
  watch(): Promise<void>;
8
7
  buildSrc(): Promise<void>;
@@ -73,41 +73,19 @@ var mkdirp_1 = __importDefault(require("mkdirp"));
73
73
  var glob_promise_1 = __importDefault(require("glob-promise"));
74
74
  var chokidar_1 = __importDefault(require("chokidar"));
75
75
  var normalize_path_1 = __importDefault(require("normalize-path"));
76
- var lodash_1 = require("lodash");
77
76
  var amxxpc_1 = __importStar(require("./amxxpc"));
78
- var logger_1 = __importDefault(require("../services/logger"));
79
77
  var constants_1 = require("./constants");
78
+ var logger_1 = __importDefault(require("../logger/logger"));
80
79
  var AmxxBuilder = /** @class */ (function () {
81
80
  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
- };
81
+ this.config = config;
104
82
  }
105
83
  AmxxBuilder.prototype.build = function () {
106
84
  return __awaiter(this, void 0, void 0, function () {
107
85
  return __generator(this, function (_a) {
108
86
  switch (_a.label) {
109
87
  case 0:
110
- this.logger.info('Building...');
88
+ logger_1.default.info('Building...');
111
89
  return [4 /*yield*/, this.buildAssets()];
112
90
  case 1:
113
91
  _a.sent();
@@ -117,7 +95,7 @@ var AmxxBuilder = /** @class */ (function () {
117
95
  return [4 /*yield*/, this.buildSrc()];
118
96
  case 3:
119
97
  _a.sent();
120
- this.logger.success('Build finished!');
98
+ logger_1.default.success('Build finished!');
121
99
  return [2 /*return*/];
122
100
  }
123
101
  });
@@ -248,7 +226,7 @@ var AmxxBuilder = /** @class */ (function () {
248
226
  return [4 /*yield*/, fs_1.default.promises.copyFile(srcPath, destPath)];
249
227
  case 2:
250
228
  _a.sent();
251
- this.logger.info('Script updated:', (0, normalize_path_1.default)(destPath));
229
+ logger_1.default.info('Script updated:', (0, normalize_path_1.default)(destPath));
252
230
  return [2 /*return*/];
253
231
  }
254
232
  });
@@ -269,7 +247,7 @@ var AmxxBuilder = /** @class */ (function () {
269
247
  return [4 /*yield*/, fs_1.default.promises.copyFile(srcPath, destPath)];
270
248
  case 2:
271
249
  _a.sent();
272
- this.logger.info('Asset updated', (0, normalize_path_1.default)(destPath));
250
+ logger_1.default.info('Asset updated', (0, normalize_path_1.default)(destPath));
273
251
  return [2 /*return*/];
274
252
  }
275
253
  });
@@ -289,7 +267,7 @@ var AmxxBuilder = /** @class */ (function () {
289
267
  return [4 /*yield*/, fs_1.default.promises.copyFile(srcPath, destPath)];
290
268
  case 2:
291
269
  _a.sent();
292
- this.logger.info('Include updated:', (0, normalize_path_1.default)(destPath));
270
+ logger_1.default.info('Include updated:', (0, normalize_path_1.default)(destPath));
293
271
  return [2 /*return*/];
294
272
  }
295
273
  });
@@ -312,8 +290,7 @@ var AmxxBuilder = /** @class */ (function () {
312
290
  };
313
291
  AmxxBuilder.prototype.compilePlugin = function (filePath) {
314
292
  return __awaiter(this, void 0, void 0, function () {
315
- var srcPath, destDir, srcDir, relateiveSrcPath, result, destPath, relativeFilePath;
316
- var _this = this;
293
+ var srcPath, destDir, srcDir, relateiveSrcPath, executable, result, destPath, relativeFilePath;
317
294
  return __generator(this, function (_a) {
318
295
  switch (_a.label) {
319
296
  case 0:
@@ -324,14 +301,17 @@ var AmxxBuilder = /** @class */ (function () {
324
301
  destDir = path_1.default.join(destDir, path_1.default.relative(this.config.input.scripts, srcDir));
325
302
  }
326
303
  relateiveSrcPath = path_1.default.relative(process.cwd(), srcPath);
304
+ executable = path_1.default.join(this.config.compiler.dir, this.config.compiler.executable);
327
305
  return [4 /*yield*/, (0, mkdirp_1.default)(destDir)];
328
306
  case 1:
329
307
  _a.sent();
330
308
  return [4 /*yield*/, (0, amxxpc_1.default)({
331
309
  path: srcPath,
332
310
  dest: destDir,
333
- compiler: this.config.compiler.executable,
334
- includeDir: __spreadArray(__spreadArray([], this.config.compiler.include, true), [
311
+ compiler: executable,
312
+ includeDir: __spreadArray(__spreadArray([
313
+ path_1.default.join(this.config.compiler.dir, 'include')
314
+ ], this.config.include, true), [
335
315
  this.config.input.include,
336
316
  ], false)
337
317
  })];
@@ -340,20 +320,20 @@ var AmxxBuilder = /** @class */ (function () {
340
320
  result.output.messages.forEach(function (message) {
341
321
  var startLine = message.startLine, type = message.type, code = message.code, text = message.text;
342
322
  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);
323
+ logger_1.default.error("".concat((0, normalize_path_1.default)(relateiveSrcPath), "(").concat(startLine, ")"), type, code, ':', text);
344
324
  }
345
325
  else if (type === amxxpc_1.AMXPCMessageType.Warning) {
346
- _this.logger.warn("".concat((0, normalize_path_1.default)(relateiveSrcPath), "(").concat(startLine, ")"), type, code, ':', text);
326
+ logger_1.default.warn("".concat((0, normalize_path_1.default)(relateiveSrcPath), "(").concat(startLine, ")"), type, code, ':', text);
347
327
  }
348
328
  else if (type === amxxpc_1.AMXPCMessageType.Echo) {
349
- _this.logger.debug(text);
329
+ logger_1.default.debug(text);
350
330
  }
351
331
  });
352
332
  if (result.success) {
353
333
  destPath = path_1.default.join(destDir, result.plugin);
354
334
  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));
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));
357
337
  }
358
338
  else {
359
339
  throw new Error("Failed to compile ".concat((0, normalize_path_1.default)(relateiveSrcPath), " : \"").concat(result.error, "\""));
@@ -384,11 +364,10 @@ var AmxxBuilder = /** @class */ (function () {
384
364
  AmxxBuilder.prototype.watchDir = function (baseDir, pattern, cb) {
385
365
  return __awaiter(this, void 0, void 0, function () {
386
366
  var pathPattern, watcher, updateFn;
387
- var _this = this;
388
367
  return __generator(this, function (_a) {
389
368
  pathPattern = path_1.default.join(baseDir, pattern);
390
369
  watcher = chokidar_1.default.watch(pathPattern, { ignoreInitial: true });
391
- updateFn = function (filePath) { return cb(filePath).catch(function (err) { return _this.logger.error(err.message); }); };
370
+ updateFn = function (filePath) { return cb(filePath).catch(function (err) { return logger_1.default.error(err.message); }); };
392
371
  watcher.on('add', updateFn);
393
372
  watcher.on('change', updateFn);
394
373
  return [2 /*return*/];
@@ -1,2 +1 @@
1
1
  export { default } from './builder';
2
- export * from './types';
@@ -1,14 +1,4 @@
1
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
13
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
14
4
  };
@@ -17,4 +7,3 @@ exports.default = void 0;
17
7
  // eslint-disable-next-line no-restricted-exports
18
8
  var builder_1 = require("./builder");
19
9
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(builder_1).default; } });
20
- __exportStar(require("./types"), exports);
@@ -1,16 +1,20 @@
1
- import AmxxBuilder, { IAmxxBuilderConfig } from '../builder';
1
+ import AmxxBuilder from '../builder';
2
+ import { IProjectOptions } from './types';
2
3
  declare class Controller {
3
- loadConfig(configPath: string): Promise<IAmxxBuilderConfig>;
4
4
  createBuilder(configPath: string): Promise<AmxxBuilder>;
5
- init(projectDir: string): Promise<void>;
5
+ create(options: IProjectOptions): Promise<void>;
6
+ config(projectDir: string): Promise<void>;
6
7
  compile(scriptPath: string, configPath: string): Promise<void>;
7
8
  build(configPath: string, watch: boolean): Promise<void>;
8
- fetchCompiler({ configPath, version, dev, addons }: {
9
- configPath: string;
10
- version: string;
11
- dev: boolean;
12
- addons: string[];
13
- }): Promise<void>;
9
+ install(configPath: string): Promise<void>;
10
+ add(configPath: string, type: string, fileName: string, options: {
11
+ name?: string;
12
+ version?: string;
13
+ author?: string;
14
+ library?: string;
15
+ overwrite: boolean;
16
+ include: string[];
17
+ }): Promise<any>;
14
18
  }
15
19
  declare const _default: Controller;
16
20
  export default _default;
@@ -40,68 +40,56 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var path_1 = __importDefault(require("path"));
43
- var fs_1 = __importDefault(require("fs"));
44
- var mkdirp_1 = __importDefault(require("mkdirp"));
45
43
  var builder_1 = __importDefault(require("../builder"));
46
- var compiler_downloader_1 = __importDefault(require("../compiler-downloader"));
47
- function resolveConfigPath(configPath) {
48
- return path_1.default.isAbsolute(configPath) ? configPath : path_1.default.join(process.cwd(), configPath);
49
- }
44
+ var compiler_1 = __importDefault(require("../downloaders/compiler"));
45
+ var thirdparty_1 = __importDefault(require("../downloaders/thirdparty"));
46
+ var project_creator_1 = __importDefault(require("./services/project-creator"));
47
+ var template_builder_1 = __importDefault(require("./services/template-builder"));
48
+ var project_config_1 = __importDefault(require("../project-config"));
49
+ var logger_1 = __importDefault(require("../logger/logger"));
50
50
  var Controller = /** @class */ (function () {
51
51
  function Controller() {
52
52
  }
53
- Controller.prototype.loadConfig = function (configPath) {
53
+ Controller.prototype.createBuilder = function (configPath) {
54
54
  return __awaiter(this, void 0, void 0, function () {
55
- var resolvedPath, config;
55
+ var projectConfig, builder;
56
56
  return __generator(this, function (_a) {
57
- resolvedPath = resolveConfigPath(configPath);
58
- if (!fs_1.default.existsSync(resolvedPath)) {
59
- // eslint-disable-next-line no-console
60
- console.log('Project is not initialzied! Use "init" command to initialize the project!');
61
- process.exit(1);
57
+ switch (_a.label) {
58
+ case 0: return [4 /*yield*/, project_config_1.default.resolve(configPath)];
59
+ case 1:
60
+ projectConfig = _a.sent();
61
+ builder = new builder_1.default(projectConfig);
62
+ return [2 /*return*/, builder];
62
63
  }
63
- config = require(resolvedPath);
64
- return [2 /*return*/, config];
65
64
  });
66
65
  });
67
66
  };
68
- Controller.prototype.createBuilder = function (configPath) {
67
+ Controller.prototype.create = function (options) {
69
68
  return __awaiter(this, void 0, void 0, function () {
70
- var config, builder;
69
+ var projectCreator;
71
70
  return __generator(this, function (_a) {
72
71
  switch (_a.label) {
73
- case 0: return [4 /*yield*/, this.loadConfig(configPath)];
72
+ case 0:
73
+ projectCreator = new project_creator_1.default(options);
74
+ return [4 /*yield*/, projectCreator.createProject()];
74
75
  case 1:
75
- config = _a.sent();
76
- builder = new builder_1.default(config);
77
- return [2 /*return*/, builder];
76
+ _a.sent();
77
+ return [2 /*return*/];
78
78
  }
79
79
  });
80
80
  });
81
81
  };
82
- Controller.prototype.init = function (projectDir) {
82
+ Controller.prototype.config = function (projectDir) {
83
83
  return __awaiter(this, void 0, void 0, function () {
84
- var configPath, config, _a, _b;
85
- return __generator(this, function (_c) {
86
- switch (_c.label) {
84
+ var projectCreator;
85
+ return __generator(this, function (_a) {
86
+ switch (_a.label) {
87
87
  case 0:
88
- configPath = path_1.default.join(projectDir, '.amxxpack.json');
89
- return [4 /*yield*/, fs_1.default.promises.copyFile(path_1.default.join(__dirname, '../../resources/default-config.json'), configPath)];
88
+ projectCreator = new project_creator_1.default();
89
+ projectCreator.projectDir = projectDir;
90
+ return [4 /*yield*/, projectCreator.createProject()];
90
91
  case 1:
91
- _c.sent();
92
- _b = (_a = JSON).parse;
93
- return [4 /*yield*/, fs_1.default.promises.readFile(configPath, 'utf8')];
94
- case 2:
95
- config = _b.apply(_a, [_c.sent()]);
96
- return [4 /*yield*/, (0, mkdirp_1.default)(path_1.default.join(projectDir, config.input.assets))];
97
- case 3:
98
- _c.sent();
99
- return [4 /*yield*/, (0, mkdirp_1.default)(path_1.default.join(projectDir, config.input.include))];
100
- case 4:
101
- _c.sent();
102
- return [4 /*yield*/, (0, mkdirp_1.default)(path_1.default.join(projectDir, config.input.scripts))];
103
- case 5:
104
- _c.sent();
92
+ _a.sent();
105
93
  return [2 /*return*/];
106
94
  }
107
95
  });
@@ -158,20 +146,89 @@ var Controller = /** @class */ (function () {
158
146
  });
159
147
  });
160
148
  };
161
- Controller.prototype.fetchCompiler = function (_a) {
162
- var configPath = _a.configPath, version = _a.version, dev = _a.dev, addons = _a.addons;
149
+ Controller.prototype.install = function (configPath) {
163
150
  return __awaiter(this, void 0, void 0, function () {
164
- var config, compilerPath;
151
+ var projectConfig, _i, _a, dependency;
165
152
  return __generator(this, function (_b) {
166
153
  switch (_b.label) {
167
- case 0: return [4 /*yield*/, this.loadConfig(configPath)];
154
+ case 0: return [4 /*yield*/, project_config_1.default.resolve(configPath)];
168
155
  case 1:
169
- config = _b.sent();
170
- compilerPath = path_1.default.parse(config.compiler.executable).dir;
171
- return [4 /*yield*/, (0, compiler_downloader_1.default)({ path: path_1.default.resolve(compilerPath), dists: addons, version: version, dev: dev })];
156
+ projectConfig = _b.sent();
157
+ return [4 /*yield*/, (0, compiler_1.default)({
158
+ path: projectConfig.compiler.dir,
159
+ dists: projectConfig.compiler.addons,
160
+ version: projectConfig.compiler.version,
161
+ dev: projectConfig.compiler.dev
162
+ })];
172
163
  case 2:
173
164
  _b.sent();
174
- return [2 /*return*/];
165
+ _i = 0, _a = projectConfig.thirdparty.dependencies;
166
+ _b.label = 3;
167
+ case 3:
168
+ if (!(_i < _a.length)) return [3 /*break*/, 6];
169
+ dependency = _a[_i];
170
+ return [4 /*yield*/, (0, thirdparty_1.default)({
171
+ name: dependency.name,
172
+ url: dependency.url,
173
+ dir: projectConfig.thirdparty.dir
174
+ })];
175
+ case 4:
176
+ _b.sent();
177
+ _b.label = 5;
178
+ case 5:
179
+ _i++;
180
+ return [3 /*break*/, 3];
181
+ case 6: return [2 /*return*/];
182
+ }
183
+ });
184
+ });
185
+ };
186
+ Controller.prototype.add = function (configPath, type, fileName, options) {
187
+ return __awaiter(this, void 0, void 0, function () {
188
+ var projectConfig, includeName, templateBuilder, _a;
189
+ return __generator(this, function (_b) {
190
+ switch (_b.label) {
191
+ case 0: return [4 /*yield*/, project_config_1.default.resolve(configPath)];
192
+ case 1:
193
+ projectConfig = _b.sent();
194
+ includeName = path_1.default.parse(fileName).base;
195
+ templateBuilder = new template_builder_1.default(projectConfig, {
196
+ FILE_NAME: fileName,
197
+ PLUGIN_NAME: options.name,
198
+ PLUGIN_VERSION: options.version,
199
+ PLUGIN_AUTHOR: options.author,
200
+ LIBRARY_NAME: options.library || includeName.replace(/-/g, '_'),
201
+ INCLUDES: options.include,
202
+ INCLUDE_NAME: includeName
203
+ }, { PLUGIN_NAME: fileName });
204
+ _a = type;
205
+ switch (_a) {
206
+ case 'script': return [3 /*break*/, 2];
207
+ case 'include': return [3 /*break*/, 4];
208
+ case 'lib': return [3 /*break*/, 6];
209
+ }
210
+ return [3 /*break*/, 9];
211
+ case 2: return [4 /*yield*/, templateBuilder.createFileFromTemplate(path_1.default.join(projectConfig.input.scripts, "".concat(fileName, ".sma")), 'script', options.overwrite)];
212
+ case 3:
213
+ _b.sent();
214
+ return [3 /*break*/, 10];
215
+ case 4: return [4 /*yield*/, templateBuilder.createFileFromTemplate(path_1.default.join(projectConfig.input.include, "".concat(fileName, ".inc")), 'include', options.overwrite)];
216
+ case 5:
217
+ _b.sent();
218
+ return [3 /*break*/, 10];
219
+ case 6: return [4 /*yield*/, templateBuilder.createFileFromTemplate(path_1.default.join(projectConfig.input.scripts, "".concat(fileName, ".sma")), 'library-script', options.overwrite)];
220
+ case 7:
221
+ _b.sent();
222
+ return [4 /*yield*/, templateBuilder.createFileFromTemplate(path_1.default.join(projectConfig.input.include, "".concat(includeName, ".inc")), 'library-include', options.overwrite)];
223
+ case 8:
224
+ _b.sent();
225
+ return [3 /*break*/, 10];
226
+ case 9:
227
+ {
228
+ logger_1.default.error("Invalid file type \"".concat(type, "\"!"));
229
+ }
230
+ _b.label = 10;
231
+ case 10: return [2 /*return*/];
175
232
  }
176
233
  });
177
234
  });
@@ -1,2 +1,3 @@
1
1
  #!/usr/bin/env node
2
- export {};
2
+ export { default as program } from './program';
3
+ export { default as controller } from './controller';
package/lib/cli/index.js CHANGED
@@ -4,5 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.controller = exports.program = void 0;
7
8
  var program_1 = __importDefault(require("./program"));
8
9
  program_1.default.parse();
10
+ var program_2 = require("./program");
11
+ Object.defineProperty(exports, "program", { enumerable: true, get: function () { return __importDefault(program_2).default; } });
12
+ var controller_1 = require("./controller");
13
+ Object.defineProperty(exports, "controller", { enumerable: true, get: function () { return __importDefault(controller_1).default; } });
@@ -41,20 +41,42 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  };
42
42
  Object.defineProperty(exports, "__esModule", { value: true });
43
43
  var commander_1 = require("commander");
44
+ var config_1 = __importDefault(require("../config"));
44
45
  var controller_1 = __importDefault(require("./controller"));
45
46
  var program = new commander_1.Command();
46
47
  program
47
48
  .name('AMXXPack CLI')
48
49
  .description('Simple AmxModX CLI');
49
50
  program
50
- .command('init')
51
+ .command('create')
52
+ .argument('<name>', 'Project name')
53
+ .option('--version, -v <version>', 'Project version')
54
+ .option('--author, -a <author>', 'Project author')
55
+ .option('--description, -d <author>', 'Project description')
56
+ .option('--nonpm', 'Don\'t initialize npm package', false)
57
+ .option('--git', 'Initialize git', false)
58
+ .action(function (name, options) { return __awaiter(void 0, void 0, void 0, function () {
59
+ var version, author, description, nonpm, git;
60
+ return __generator(this, function (_a) {
61
+ switch (_a.label) {
62
+ case 0:
63
+ version = options.V, author = options.A, description = options.D, nonpm = options.nonpm, git = options.git;
64
+ return [4 /*yield*/, controller_1.default.create({ name: name, version: version, author: author, description: description, nonpm: nonpm, git: git })];
65
+ case 1:
66
+ _a.sent();
67
+ return [2 /*return*/];
68
+ }
69
+ });
70
+ }); });
71
+ program
72
+ .command('config')
51
73
  .action(function () { return __awaiter(void 0, void 0, void 0, function () {
52
74
  var projectDir;
53
75
  return __generator(this, function (_a) {
54
76
  switch (_a.label) {
55
77
  case 0:
56
78
  projectDir = process.cwd();
57
- return [4 /*yield*/, controller_1.default.init(projectDir)];
79
+ return [4 /*yield*/, controller_1.default.config(projectDir)];
58
80
  case 1:
59
81
  _a.sent();
60
82
  return [2 /*return*/];
@@ -63,15 +85,16 @@ program
63
85
  }); });
64
86
  program
65
87
  .command('compile')
88
+ .alias('c')
66
89
  .argument('<path>', 'Script path or glob')
67
- .option('--config, -c <path>', 'Config file', '.amxxpack.json')
68
- .action(function (str, options) { return __awaiter(void 0, void 0, void 0, function () {
90
+ .option('--config, -c <path>', 'Config file', config_1.default.projectConfig)
91
+ .action(function (filePath, options) { return __awaiter(void 0, void 0, void 0, function () {
69
92
  var configPath;
70
93
  return __generator(this, function (_a) {
71
94
  switch (_a.label) {
72
95
  case 0:
73
96
  configPath = options.C;
74
- return [4 /*yield*/, controller_1.default.compile(str, configPath)];
97
+ return [4 /*yield*/, controller_1.default.compile(filePath, configPath)];
75
98
  case 1:
76
99
  _a.sent();
77
100
  return [2 /*return*/];
@@ -80,9 +103,10 @@ program
80
103
  }); });
81
104
  program
82
105
  .command('build')
106
+ .alias('b')
107
+ .option('--config, -c <path>', 'Config file', config_1.default.projectConfig)
83
108
  .option('--watch, -w', 'Watch project')
84
- .option('--config, -c <path>', 'Config file', '.amxxpack.json')
85
- .action(function (str, options) { return __awaiter(void 0, void 0, void 0, function () {
109
+ .action(function (_argument, options) { return __awaiter(void 0, void 0, void 0, function () {
86
110
  var _a, configPath, watch;
87
111
  return __generator(this, function (_b) {
88
112
  switch (_b.label) {
@@ -96,21 +120,53 @@ program
96
120
  });
97
121
  }); });
98
122
  program
99
- .command('fetch-compiler')
100
- .option('--config, -c <path>', 'Config file', '.amxxpack.json')
101
- .option('--version, -v <version>', 'Version', '1.8.2')
102
- .option('--addon, -a <addon>', 'Addon', 'base')
103
- .option('--dev, -d', 'Dev build flag', false)
104
- .action(function (str, options) { return __awaiter(void 0, void 0, void 0, function () {
105
- var _a, dev, addon, version, configPath, addons;
106
- return __generator(this, function (_b) {
107
- switch (_b.label) {
123
+ .command('install')
124
+ .alias('i')
125
+ .option('--config, -c <path>', 'Config file', config_1.default.projectConfig)
126
+ .action(function (_argument, options) { return __awaiter(void 0, void 0, void 0, function () {
127
+ var configPath;
128
+ return __generator(this, function (_a) {
129
+ switch (_a.label) {
108
130
  case 0:
109
- _a = options.opts(), dev = _a.D, addon = _a.A, version = _a.V, configPath = _a.C;
110
- addons = addon.split(' ');
111
- return [4 /*yield*/, controller_1.default.fetchCompiler({ configPath: configPath, version: version, dev: dev, addons: addons })];
131
+ configPath = options.opts().C;
132
+ return [4 /*yield*/, controller_1.default.install(configPath)];
112
133
  case 1:
113
- _b.sent();
134
+ _a.sent();
135
+ return [2 /*return*/];
136
+ }
137
+ });
138
+ }); });
139
+ program
140
+ .command('new')
141
+ .alias('n')
142
+ .arguments('<type> <filename>')
143
+ .option('--config, -c <path>', 'Config file', config_1.default.projectConfig)
144
+ .option('--name, -n <name>', 'Plugin name')
145
+ .option('--version, -v <version>', 'Plugin version')
146
+ .option('--author, -a <author>', 'Plugin author')
147
+ .option('--library, -l <library>', 'Library name')
148
+ .option('--include, -i <include>', 'Add include')
149
+ .option('--overwrite', 'Overwrite file if it already exists', false)
150
+ .action(function (type, fileName, options) { return __awaiter(void 0, void 0, void 0, function () {
151
+ var configPath, name, version, author, library, overwrite, include;
152
+ return __generator(this, function (_a) {
153
+ switch (_a.label) {
154
+ case 0:
155
+ configPath = options.C, name = options.N, version = options.V, author = options.A, library = options.L, overwrite = options.overwrite;
156
+ include = options.I ? options.I.split(/[\s|,]/) : [];
157
+ if (!include.includes('amxmodx')) {
158
+ include.unshift('amxmodx');
159
+ }
160
+ return [4 /*yield*/, controller_1.default.add(configPath, type, fileName, {
161
+ name: name,
162
+ version: version,
163
+ author: author,
164
+ library: library,
165
+ include: include,
166
+ overwrite: overwrite
167
+ })];
168
+ case 1:
169
+ _a.sent();
114
170
  return [2 /*return*/];
115
171
  }
116
172
  });