amxxpack 0.1.4 → 1.0.2

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 +26 -21
  2. package/lib/builder/builder.d.ts +2 -3
  3. package/lib/builder/builder.js +20 -41
  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 +121 -65
  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 +292 -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
@@ -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
  });
@@ -0,0 +1,21 @@
1
+ import { IProjectOptions } from '../types';
2
+ import { IProjectConfig } from '../../types';
3
+ declare class ProjectCreator {
4
+ projectDir: string;
5
+ projectConfig: IProjectConfig;
6
+ options: IProjectOptions;
7
+ isCurrentDir: boolean;
8
+ constructor(options?: IProjectOptions);
9
+ createProject(): Promise<void>;
10
+ updatePackage(): Promise<void>;
11
+ createConfig(): Promise<void>;
12
+ createDirectories(): Promise<void>;
13
+ installDependencies(): Promise<void>;
14
+ initGit(): Promise<void>;
15
+ updateGitignore(): Promise<void>;
16
+ isInitialized(): boolean;
17
+ isGitInitialized(): boolean;
18
+ isNpmPackageInitialized(): boolean;
19
+ execCommand(command: string): Promise<unknown>;
20
+ }
21
+ export default ProjectCreator;
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ var path_1 = __importDefault(require("path"));
54
+ var fs_1 = __importDefault(require("fs"));
55
+ var child_process_1 = require("child_process");
56
+ var mkdirp_1 = __importDefault(require("mkdirp"));
57
+ var lodash_1 = require("lodash");
58
+ var project_config_1 = __importDefault(require("../../project-config"));
59
+ var config_1 = __importDefault(require("../../config"));
60
+ var logger_1 = __importDefault(require("../../logger/logger"));
61
+ var ProjectCreator = /** @class */ (function () {
62
+ function ProjectCreator(options) {
63
+ if (options === void 0) { options = null; }
64
+ this.projectDir = null;
65
+ this.projectConfig = null;
66
+ this.options = null;
67
+ this.isCurrentDir = false;
68
+ if (options) {
69
+ if (!options.name) {
70
+ throw new Error('Project name cannot be empty!');
71
+ }
72
+ this.isCurrentDir = options.name === '.';
73
+ var cwd = options.cwd || process.cwd();
74
+ this.options = __assign(__assign({}, options), { name: this.isCurrentDir ? path_1.default.basename(cwd) : options.name, cwd: options.cwd || cwd });
75
+ this.projectDir = this.isCurrentDir
76
+ ? cwd
77
+ : path_1.default.join(cwd, this.options.name);
78
+ }
79
+ this.projectConfig = project_config_1.default.defaults;
80
+ }
81
+ ProjectCreator.prototype.createProject = function () {
82
+ return __awaiter(this, void 0, void 0, function () {
83
+ return __generator(this, function (_a) {
84
+ switch (_a.label) {
85
+ case 0:
86
+ if (!this.isCurrentDir && fs_1.default.existsSync(this.projectDir)) {
87
+ logger_1.default.error('Project', this.options.name, 'is already exists!');
88
+ return [2 /*return*/];
89
+ }
90
+ if (this.isCurrentDir && this.isInitialized()) {
91
+ logger_1.default.error('Cannot create a project! The directory is not empty!');
92
+ return [2 /*return*/];
93
+ }
94
+ return [4 /*yield*/, this.createConfig()];
95
+ case 1:
96
+ _a.sent();
97
+ return [4 /*yield*/, this.createDirectories()];
98
+ case 2:
99
+ _a.sent();
100
+ if (!!this.options.nonpm) return [3 /*break*/, 4];
101
+ return [4 /*yield*/, this.updatePackage()];
102
+ case 3:
103
+ _a.sent();
104
+ _a.label = 4;
105
+ case 4:
106
+ if (!(this.options.git && !this.isGitInitialized())) return [3 /*break*/, 6];
107
+ return [4 /*yield*/, this.initGit()];
108
+ case 5:
109
+ _a.sent();
110
+ _a.label = 6;
111
+ case 6:
112
+ if (!this.isGitInitialized()) return [3 /*break*/, 8];
113
+ return [4 /*yield*/, this.updateGitignore()];
114
+ case 7:
115
+ _a.sent();
116
+ _a.label = 8;
117
+ case 8:
118
+ if (!this.isNpmPackageInitialized()) return [3 /*break*/, 10];
119
+ return [4 /*yield*/, this.installDependencies()];
120
+ case 9:
121
+ _a.sent();
122
+ _a.label = 10;
123
+ case 10:
124
+ logger_1.default.success('Your project is ready! Thanks for using AMXXPack CLI! 🤗');
125
+ return [2 /*return*/];
126
+ }
127
+ });
128
+ });
129
+ };
130
+ ProjectCreator.prototype.updatePackage = function () {
131
+ return __awaiter(this, void 0, void 0, function () {
132
+ var packagePath, packageData, _a, _b, _c, _d, _e;
133
+ return __generator(this, function (_f) {
134
+ switch (_f.label) {
135
+ case 0:
136
+ logger_1.default.info('📦 Initializing npm package...');
137
+ packagePath = path_1.default.join(this.projectDir, 'package.json');
138
+ packageData = {
139
+ name: this.options.name,
140
+ version: (0, lodash_1.get)(this.options, 'version', '0.1.0'),
141
+ author: (0, lodash_1.get)(this.options, 'author', 'AMXXPack'),
142
+ description: (0, lodash_1.get)(this.options, 'description', 'This project was generated by AMXXPack CLI')
143
+ };
144
+ if (!fs_1.default.existsSync(packagePath)) return [3 /*break*/, 4];
145
+ _f.label = 1;
146
+ case 1:
147
+ _f.trys.push([1, 3, , 4]);
148
+ _a = lodash_1.merge;
149
+ _b = [packageData];
150
+ _d = (_c = JSON).parse;
151
+ return [4 /*yield*/, fs_1.default.promises.readFile(packagePath, 'utf8')];
152
+ case 2:
153
+ _a.apply(void 0, _b.concat([_d.apply(_c, [_f.sent()])]));
154
+ return [3 /*break*/, 4];
155
+ case 3:
156
+ _e = _f.sent();
157
+ logger_1.default.error('Cannot read package.json file');
158
+ return [3 /*break*/, 4];
159
+ case 4:
160
+ (0, lodash_1.merge)(packageData, {
161
+ scripts: {
162
+ build: 'amxxpack build',
163
+ watch: 'amxxpack build --watch',
164
+ postinstall: 'amxxpack install'
165
+ }
166
+ });
167
+ return [4 /*yield*/, fs_1.default.promises.writeFile(packagePath, JSON.stringify(packageData, null, 2))];
168
+ case 5:
169
+ _f.sent();
170
+ return [2 /*return*/];
171
+ }
172
+ });
173
+ });
174
+ };
175
+ ProjectCreator.prototype.createConfig = function () {
176
+ return __awaiter(this, void 0, void 0, function () {
177
+ var configPath;
178
+ return __generator(this, function (_a) {
179
+ switch (_a.label) {
180
+ case 0:
181
+ logger_1.default.info('🔧 Creating project configuration file...');
182
+ return [4 /*yield*/, (0, mkdirp_1.default)(this.projectDir)];
183
+ case 1:
184
+ _a.sent();
185
+ configPath = path_1.default.join(this.projectDir, config_1.default.projectConfig);
186
+ return [4 /*yield*/, fs_1.default.promises.writeFile(configPath, JSON.stringify(this.projectConfig, null, 2))];
187
+ case 2:
188
+ _a.sent();
189
+ return [2 /*return*/];
190
+ }
191
+ });
192
+ });
193
+ };
194
+ ProjectCreator.prototype.createDirectories = function () {
195
+ return __awaiter(this, void 0, void 0, function () {
196
+ return __generator(this, function (_a) {
197
+ switch (_a.label) {
198
+ case 0:
199
+ logger_1.default.info('📁 Creating project directories...');
200
+ return [4 /*yield*/, (0, mkdirp_1.default)(path_1.default.join(this.projectDir, this.projectConfig.input.assets))];
201
+ case 1:
202
+ _a.sent();
203
+ return [4 /*yield*/, (0, mkdirp_1.default)(path_1.default.join(this.projectDir, this.projectConfig.input.include))];
204
+ case 2:
205
+ _a.sent();
206
+ return [4 /*yield*/, (0, mkdirp_1.default)(path_1.default.join(this.projectDir, this.projectConfig.input.scripts))];
207
+ case 3:
208
+ _a.sent();
209
+ return [2 /*return*/];
210
+ }
211
+ });
212
+ });
213
+ };
214
+ ProjectCreator.prototype.installDependencies = function () {
215
+ return __awaiter(this, void 0, void 0, function () {
216
+ return __generator(this, function (_a) {
217
+ switch (_a.label) {
218
+ case 0:
219
+ logger_1.default.info('🔄 Installing dependencies...');
220
+ return [4 /*yield*/, this.execCommand('npm install amxxpack --save-dev')];
221
+ case 1:
222
+ _a.sent();
223
+ return [4 /*yield*/, this.execCommand('npm run postinstall')];
224
+ case 2:
225
+ _a.sent();
226
+ return [2 /*return*/];
227
+ }
228
+ });
229
+ });
230
+ };
231
+ ProjectCreator.prototype.initGit = function () {
232
+ return __awaiter(this, void 0, void 0, function () {
233
+ return __generator(this, function (_a) {
234
+ switch (_a.label) {
235
+ case 0:
236
+ logger_1.default.info('🌿 Initializing git...');
237
+ return [4 /*yield*/, this.execCommand('git init')];
238
+ case 1:
239
+ _a.sent();
240
+ return [2 /*return*/];
241
+ }
242
+ });
243
+ });
244
+ };
245
+ ProjectCreator.prototype.updateGitignore = function () {
246
+ return __awaiter(this, void 0, void 0, function () {
247
+ var filePath, lines, addDir;
248
+ var _this = this;
249
+ return __generator(this, function (_a) {
250
+ switch (_a.label) {
251
+ case 0:
252
+ logger_1.default.info('❔ Updating .gitignore file...');
253
+ filePath = path_1.default.join(this.projectDir, '.gitignore');
254
+ lines = ['*.amxx'];
255
+ addDir = function (dir) { return !path_1.default.isAbsolute(dir) && lines.push("".concat(path_1.default.relative(_this.projectDir, dir), "/")); };
256
+ addDir('node_modules');
257
+ addDir(this.projectConfig.compiler.dir);
258
+ addDir(this.projectConfig.thirdparty.dir);
259
+ addDir(this.projectConfig.output.assets);
260
+ if (fs_1.default.existsSync(filePath)) {
261
+ lines.unshift('');
262
+ }
263
+ lines.push('');
264
+ return [4 /*yield*/, fs_1.default.promises.appendFile(filePath, lines.join('\n'))];
265
+ case 1:
266
+ _a.sent();
267
+ return [2 /*return*/];
268
+ }
269
+ });
270
+ });
271
+ };
272
+ ProjectCreator.prototype.isInitialized = function () {
273
+ return fs_1.default.existsSync(path_1.default.join(this.projectDir, config_1.default.projectConfig));
274
+ };
275
+ ProjectCreator.prototype.isGitInitialized = function () {
276
+ return fs_1.default.existsSync(path_1.default.join(this.projectDir, '.git'));
277
+ };
278
+ ProjectCreator.prototype.isNpmPackageInitialized = function () {
279
+ return fs_1.default.existsSync(path_1.default.join(this.projectDir, 'package.json'));
280
+ };
281
+ ProjectCreator.prototype.execCommand = function (command) {
282
+ var process = (0, child_process_1.exec)(command, {
283
+ cwd: this.projectDir
284
+ });
285
+ return new Promise(function (resolve) {
286
+ process.on('error', resolve);
287
+ process.on('close', resolve);
288
+ });
289
+ };
290
+ return ProjectCreator;
291
+ }());
292
+ exports.default = ProjectCreator;
@@ -0,0 +1,11 @@
1
+ import { IAddTemplateContext } from '../types';
2
+ import { IProjectConfig } from '../../types';
3
+ declare class TemplateBuilder {
4
+ projectConfig: IProjectConfig;
5
+ context: IAddTemplateContext;
6
+ rawIncludes: string;
7
+ constructor(projectConfig: IProjectConfig, context: IAddTemplateContext, contextDefaults: Partial<IAddTemplateContext>);
8
+ buildTemplate(name: string, contextOverride: Partial<IAddTemplateContext>): Promise<string>;
9
+ createFileFromTemplate(filePath: string, template: string, overwrite: boolean): Promise<void>;
10
+ }
11
+ export default TemplateBuilder;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var fs_1 = __importDefault(require("fs"));
43
+ var path_1 = __importDefault(require("path"));
44
+ var lodash_1 = require("lodash");
45
+ var mkdirp_1 = __importDefault(require("mkdirp"));
46
+ var TemplateBuilder = /** @class */ (function () {
47
+ function TemplateBuilder(projectConfig, context, contextDefaults) {
48
+ this.projectConfig = projectConfig;
49
+ this.context = null;
50
+ this.rawIncludes = null;
51
+ this.context = (0, lodash_1.defaults)((0, lodash_1.merge)({}, this.projectConfig.cli.templates.context, context), contextDefaults);
52
+ }
53
+ TemplateBuilder.prototype.buildTemplate = function (name, contextOverride) {
54
+ return __awaiter(this, void 0, void 0, function () {
55
+ var templatePath, templateString, data;
56
+ var _this = this;
57
+ return __generator(this, function (_a) {
58
+ switch (_a.label) {
59
+ case 0:
60
+ templatePath = (0, lodash_1.get)(this.projectConfig.cli.templates.files, name, path_1.default.join(__dirname, "../../../resources/templates/".concat(name, ".txt")));
61
+ return [4 /*yield*/, fs_1.default.promises.readFile(templatePath, 'utf8')];
62
+ case 1:
63
+ templateString = _a.sent();
64
+ data = templateString.replace(/\{\{([a-zA-Z0-9_]+)\}\}/gm, function (substring) {
65
+ var args = [];
66
+ for (var _i = 1; _i < arguments.length; _i++) {
67
+ args[_i - 1] = arguments[_i];
68
+ }
69
+ var key = args[0];
70
+ return (0, lodash_1.get)(contextOverride, key, (0, lodash_1.get)(_this.context, key, substring));
71
+ });
72
+ return [2 /*return*/, data];
73
+ }
74
+ });
75
+ });
76
+ };
77
+ TemplateBuilder.prototype.createFileFromTemplate = function (filePath, template, overwrite) {
78
+ return __awaiter(this, void 0, void 0, function () {
79
+ var dir, rawIncludes, _a, _b, _c;
80
+ var _this = this;
81
+ return __generator(this, function (_d) {
82
+ switch (_d.label) {
83
+ case 0:
84
+ dir = path_1.default.parse(filePath).dir;
85
+ return [4 /*yield*/, (0, mkdirp_1.default)(dir)];
86
+ case 1:
87
+ _d.sent();
88
+ return [4 /*yield*/, Promise.all((0, lodash_1.map)(this.context.INCLUDES, function (includeName) { return _this.buildTemplate('include-directive', { FILE: includeName }); }))];
89
+ case 2:
90
+ rawIncludes = (_d.sent()).join('\n');
91
+ _b = (_a = fs_1.default.promises).writeFile;
92
+ _c = [filePath];
93
+ return [4 /*yield*/, this.buildTemplate(template, { INCLUDES: rawIncludes })];
94
+ case 3: return [4 /*yield*/, _b.apply(_a, _c.concat([_d.sent(), { flag: overwrite ? 'w' : 'wx' }]))];
95
+ case 4:
96
+ _d.sent();
97
+ return [2 /*return*/];
98
+ }
99
+ });
100
+ });
101
+ };
102
+ return TemplateBuilder;
103
+ }());
104
+ exports.default = TemplateBuilder;
@@ -0,0 +1,12 @@
1
+ export interface IAddTemplateContext {
2
+ [key: string]: any;
3
+ }
4
+ export interface IProjectOptions {
5
+ name: string;
6
+ author: string;
7
+ description: string;
8
+ version: string;
9
+ nonpm: boolean;
10
+ git: boolean;
11
+ cwd?: string;
12
+ }
File without changes
@@ -0,0 +1,8 @@
1
+ declare const _default: {
2
+ downloadHost: string;
3
+ scriptingDir: string;
4
+ extensionsIgnoreList: string[];
5
+ downloadDir: string;
6
+ projectConfig: string;
7
+ };
8
+ export default _default;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var path_1 = __importDefault(require("path"));
7
+ var os_1 = __importDefault(require("os"));
8
+ exports.default = {
9
+ downloadHost: 'https://www.amxmodx.org',
10
+ scriptingDir: 'addons/amxmodx/scripting/',
11
+ extensionsIgnoreList: ['.sma'],
12
+ downloadDir: path_1.default.join(os_1.default.tmpdir(), '.amxxpack/downloads'),
13
+ projectConfig: '.amxxpack.json'
14
+ };
@@ -0,0 +1,9 @@
1
+ export declare enum CompilerPlatform {
2
+ Windows = "windows",
3
+ Linux = "linux",
4
+ Mac = "mac"
5
+ }
6
+ export declare enum DistSource {
7
+ Dev = "amxxdrop",
8
+ Release = "release"
9
+ }
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DistSource = exports.CompilerPlatform = exports.EXTENSIONS_IGNORE_LIST = exports.SCRIPTING_DIR = exports.DOWNLOAD_HOST = void 0;
4
- exports.DOWNLOAD_HOST = 'https://www.amxmodx.org';
5
- exports.SCRIPTING_DIR = 'addons/amxmodx/scripting/';
6
- exports.EXTENSIONS_IGNORE_LIST = ['.sma'];
3
+ exports.DistSource = exports.CompilerPlatform = void 0;
7
4
  var CompilerPlatform;
8
5
  (function (CompilerPlatform) {
9
6
  CompilerPlatform["Windows"] = "windows";
@@ -0,0 +1,3 @@
1
+ import { IDownloadCompilerOptions } from './types';
2
+ declare function downloadCompiler(options: IDownloadCompilerOptions): Promise<void>;
3
+ export default downloadCompiler;