amxxpack 0.1.2 → 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 (69) hide show
  1. package/README.md +26 -21
  2. package/lib/builder/amxxpc.d.ts +27 -27
  3. package/lib/builder/amxxpc.js +122 -122
  4. package/lib/builder/builder.d.ts +21 -22
  5. package/lib/builder/builder.js +379 -400
  6. package/lib/builder/constants.d.ts +3 -3
  7. package/lib/builder/constants.js +6 -6
  8. package/lib/builder/index.d.ts +1 -2
  9. package/lib/builder/index.js +9 -20
  10. package/lib/cli/controller.d.ts +20 -16
  11. package/lib/cli/controller.js +238 -181
  12. package/lib/cli/index.d.ts +3 -2
  13. package/lib/cli/index.js +13 -8
  14. package/lib/cli/program.d.ts +4 -4
  15. package/lib/cli/program.js +174 -118
  16. package/lib/cli/services/project-creator.d.ts +21 -0
  17. package/lib/cli/services/project-creator.js +274 -0
  18. package/lib/cli/services/template-builder.d.ts +11 -0
  19. package/lib/cli/services/template-builder.js +104 -0
  20. package/lib/cli/types.d.ts +12 -0
  21. package/lib/{compiler-downloader → cli}/types.js +2 -2
  22. package/lib/config/index.d.ts +8 -0
  23. package/lib/config/index.js +14 -0
  24. package/lib/downloaders/compiler/constants.d.ts +9 -0
  25. package/lib/{compiler-downloader → downloaders/compiler}/constants.js +14 -17
  26. package/lib/downloaders/compiler/downloader.d.ts +3 -0
  27. package/lib/{compiler-downloader → downloaders/compiler}/downloader.js +151 -174
  28. package/lib/{compiler-downloader → downloaders/compiler}/index.d.ts +1 -1
  29. package/lib/{compiler-downloader → downloaders/compiler}/index.js +9 -9
  30. package/lib/{compiler-downloader → downloaders/compiler}/resolvers.d.ts +6 -6
  31. package/lib/{compiler-downloader → downloaders/compiler}/resolvers.js +40 -39
  32. package/lib/{compiler-downloader → downloaders/compiler}/types.d.ts +16 -16
  33. package/lib/{builder → downloaders/compiler}/types.js +2 -2
  34. package/lib/downloaders/thirdparty/downloader.d.ts +3 -0
  35. package/lib/downloaders/thirdparty/downloader.js +69 -0
  36. package/lib/downloaders/thirdparty/index.d.ts +1 -0
  37. package/lib/downloaders/thirdparty/index.js +9 -0
  38. package/lib/downloaders/thirdparty/types.d.ts +5 -0
  39. package/lib/downloaders/thirdparty/types.js +2 -0
  40. package/lib/index.d.ts +2 -2
  41. package/lib/index.js +20 -20
  42. package/lib/logger/constants.d.ts +7 -0
  43. package/lib/logger/constants.js +12 -0
  44. package/lib/{services → logger}/logger.d.ts +16 -22
  45. package/lib/{services → logger}/logger.js +96 -104
  46. package/lib/logger/types.d.ts +3 -0
  47. package/lib/logger/types.js +2 -0
  48. package/lib/project-config/defaults.d.ts +3 -0
  49. package/lib/project-config/defaults.js +38 -0
  50. package/lib/project-config/index.d.ts +6 -0
  51. package/lib/project-config/index.js +8 -0
  52. package/lib/project-config/resolve.d.ts +3 -0
  53. package/lib/project-config/resolve.js +110 -0
  54. package/lib/types/index.d.ts +45 -0
  55. package/lib/types/index.js +2 -0
  56. package/lib/utils/accumulator.d.ts +2 -1
  57. package/lib/utils/accumulator.js +10 -10
  58. package/lib/utils/download.d.ts +6 -0
  59. package/lib/utils/download.js +63 -0
  60. package/package.json +7 -1
  61. package/resources/templates/include-directive.txt +1 -0
  62. package/resources/templates/include.txt +5 -0
  63. package/resources/templates/library-include.txt +6 -0
  64. package/resources/templates/library-script.txt +10 -0
  65. package/resources/templates/script.txt +5 -0
  66. package/lib/builder/types.d.ts +0 -20
  67. package/lib/compiler-downloader/constants.d.ts +0 -12
  68. package/lib/compiler-downloader/downloader.d.ts +0 -2
  69. package/resources/default-config.json +0 -22
@@ -1,118 +1,174 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
- var __generator = (this && this.__generator) || function (thisArg, body) {
13
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
14
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
15
- function verb(n) { return function (v) { return step([n, v]); }; }
16
- function step(op) {
17
- if (f) throw new TypeError("Generator is already executing.");
18
- while (_) try {
19
- 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;
20
- if (y = 0, t) op = [op[0] & 2, t.value];
21
- switch (op[0]) {
22
- case 0: case 1: t = op; break;
23
- case 4: _.label++; return { value: op[1], done: false };
24
- case 5: _.label++; y = op[1]; op = [0]; continue;
25
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
26
- default:
27
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
28
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
29
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
30
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
31
- if (t[2]) _.ops.pop();
32
- _.trys.pop(); continue;
33
- }
34
- op = body.call(thisArg, _);
35
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
36
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
37
- }
38
- };
39
- var __importDefault = (this && this.__importDefault) || function (mod) {
40
- return (mod && mod.__esModule) ? mod : { "default": mod };
41
- };
42
- Object.defineProperty(exports, "__esModule", { value: true });
43
- var commander_1 = require("commander");
44
- var controller_1 = __importDefault(require("./controller"));
45
- var program = new commander_1.Command();
46
- program
47
- .name('AMXXPack CLI')
48
- .description('Simple AmxModX CLI');
49
- program
50
- .command('init')
51
- .action(function () { return __awaiter(void 0, void 0, void 0, function () {
52
- var projectDir;
53
- return __generator(this, function (_a) {
54
- switch (_a.label) {
55
- case 0:
56
- projectDir = process.cwd();
57
- return [4 /*yield*/, controller_1.default.init(projectDir)];
58
- case 1:
59
- _a.sent();
60
- return [2 /*return*/];
61
- }
62
- });
63
- }); });
64
- program
65
- .command('compile')
66
- .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 () {
69
- var configPath;
70
- return __generator(this, function (_a) {
71
- switch (_a.label) {
72
- case 0:
73
- configPath = options.C;
74
- return [4 /*yield*/, controller_1.default.compile(str, configPath)];
75
- case 1:
76
- _a.sent();
77
- return [2 /*return*/];
78
- }
79
- });
80
- }); });
81
- program
82
- .command('build')
83
- .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 () {
86
- var _a, configPath, watch;
87
- return __generator(this, function (_b) {
88
- switch (_b.label) {
89
- case 0:
90
- _a = options.opts(), configPath = _a.C, watch = _a.W;
91
- return [4 /*yield*/, controller_1.default.build(configPath, watch)];
92
- case 1:
93
- _b.sent();
94
- return [2 /*return*/];
95
- }
96
- });
97
- }); });
98
- 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) {
108
- 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 })];
112
- case 1:
113
- _b.sent();
114
- return [2 /*return*/];
115
- }
116
- });
117
- }); });
118
- exports.default = program;
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __generator = (this && this.__generator) || function (thisArg, body) {
13
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
14
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
15
+ function verb(n) { return function (v) { return step([n, v]); }; }
16
+ function step(op) {
17
+ if (f) throw new TypeError("Generator is already executing.");
18
+ while (_) try {
19
+ 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;
20
+ if (y = 0, t) op = [op[0] & 2, t.value];
21
+ switch (op[0]) {
22
+ case 0: case 1: t = op; break;
23
+ case 4: _.label++; return { value: op[1], done: false };
24
+ case 5: _.label++; y = op[1]; op = [0]; continue;
25
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
26
+ default:
27
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
28
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
29
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
30
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
31
+ if (t[2]) _.ops.pop();
32
+ _.trys.pop(); continue;
33
+ }
34
+ op = body.call(thisArg, _);
35
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
36
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
37
+ }
38
+ };
39
+ var __importDefault = (this && this.__importDefault) || function (mod) {
40
+ return (mod && mod.__esModule) ? mod : { "default": mod };
41
+ };
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ var commander_1 = require("commander");
44
+ var config_1 = __importDefault(require("../config"));
45
+ var controller_1 = __importDefault(require("./controller"));
46
+ var program = new commander_1.Command();
47
+ program
48
+ .name('AMXXPack CLI')
49
+ .description('Simple AmxModX CLI');
50
+ program
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')
73
+ .action(function () { return __awaiter(void 0, void 0, void 0, function () {
74
+ var projectDir;
75
+ return __generator(this, function (_a) {
76
+ switch (_a.label) {
77
+ case 0:
78
+ projectDir = process.cwd();
79
+ return [4 /*yield*/, controller_1.default.config(projectDir)];
80
+ case 1:
81
+ _a.sent();
82
+ return [2 /*return*/];
83
+ }
84
+ });
85
+ }); });
86
+ program
87
+ .command('compile')
88
+ .alias('c')
89
+ .argument('<path>', 'Script path or glob')
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 () {
92
+ var configPath;
93
+ return __generator(this, function (_a) {
94
+ switch (_a.label) {
95
+ case 0:
96
+ configPath = options.C;
97
+ return [4 /*yield*/, controller_1.default.compile(filePath, configPath)];
98
+ case 1:
99
+ _a.sent();
100
+ return [2 /*return*/];
101
+ }
102
+ });
103
+ }); });
104
+ program
105
+ .command('build')
106
+ .alias('b')
107
+ .option('--config, -c <path>', 'Config file', config_1.default.projectConfig)
108
+ .option('--watch, -w', 'Watch project')
109
+ .action(function (_argument, options) { return __awaiter(void 0, void 0, void 0, function () {
110
+ var _a, configPath, watch;
111
+ return __generator(this, function (_b) {
112
+ switch (_b.label) {
113
+ case 0:
114
+ _a = options.opts(), configPath = _a.C, watch = _a.W;
115
+ return [4 /*yield*/, controller_1.default.build(configPath, watch)];
116
+ case 1:
117
+ _b.sent();
118
+ return [2 /*return*/];
119
+ }
120
+ });
121
+ }); });
122
+ program
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) {
130
+ case 0:
131
+ configPath = options.opts().C;
132
+ return [4 /*yield*/, controller_1.default.install(configPath)];
133
+ case 1:
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();
170
+ return [2 /*return*/];
171
+ }
172
+ });
173
+ }); });
174
+ exports.default = program;
@@ -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
+ createPackage(): 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,274 @@
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.createPackage()];
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.isNpmPackageInitialized()) return [3 /*break*/, 8];
113
+ return [4 /*yield*/, this.installDependencies()];
114
+ case 7:
115
+ _a.sent();
116
+ _a.label = 8;
117
+ case 8:
118
+ if (!this.isGitInitialized()) return [3 /*break*/, 10];
119
+ return [4 /*yield*/, this.updateGitignore()];
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.createPackage = function () {
131
+ return __awaiter(this, void 0, void 0, function () {
132
+ var packagePath, packageData;
133
+ return __generator(this, function (_a) {
134
+ switch (_a.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
+ scripts: {
144
+ build: 'amxxpack build',
145
+ watch: 'amxxpack build --watch',
146
+ postinstall: 'amxxpack install'
147
+ }
148
+ };
149
+ return [4 /*yield*/, fs_1.default.promises.writeFile(packagePath, JSON.stringify(packageData, null, 2))];
150
+ case 1:
151
+ _a.sent();
152
+ return [2 /*return*/];
153
+ }
154
+ });
155
+ });
156
+ };
157
+ ProjectCreator.prototype.createConfig = function () {
158
+ return __awaiter(this, void 0, void 0, function () {
159
+ var configPath;
160
+ return __generator(this, function (_a) {
161
+ switch (_a.label) {
162
+ case 0:
163
+ logger_1.default.info('🔧 Creating project configuration file...');
164
+ return [4 /*yield*/, (0, mkdirp_1.default)(this.projectDir)];
165
+ case 1:
166
+ _a.sent();
167
+ configPath = path_1.default.join(this.projectDir, config_1.default.projectConfig);
168
+ return [4 /*yield*/, fs_1.default.promises.writeFile(configPath, JSON.stringify(this.projectConfig, null, 2))];
169
+ case 2:
170
+ _a.sent();
171
+ return [2 /*return*/];
172
+ }
173
+ });
174
+ });
175
+ };
176
+ ProjectCreator.prototype.createDirectories = function () {
177
+ return __awaiter(this, void 0, void 0, function () {
178
+ return __generator(this, function (_a) {
179
+ switch (_a.label) {
180
+ case 0:
181
+ logger_1.default.info('📁 Creating project directories...');
182
+ return [4 /*yield*/, (0, mkdirp_1.default)(path_1.default.join(this.projectDir, this.projectConfig.input.assets))];
183
+ case 1:
184
+ _a.sent();
185
+ return [4 /*yield*/, (0, mkdirp_1.default)(path_1.default.join(this.projectDir, this.projectConfig.input.include))];
186
+ case 2:
187
+ _a.sent();
188
+ return [4 /*yield*/, (0, mkdirp_1.default)(path_1.default.join(this.projectDir, this.projectConfig.input.scripts))];
189
+ case 3:
190
+ _a.sent();
191
+ return [2 /*return*/];
192
+ }
193
+ });
194
+ });
195
+ };
196
+ ProjectCreator.prototype.installDependencies = function () {
197
+ return __awaiter(this, void 0, void 0, function () {
198
+ return __generator(this, function (_a) {
199
+ switch (_a.label) {
200
+ case 0:
201
+ logger_1.default.info('🔄 Installing dependencies...');
202
+ return [4 /*yield*/, this.execCommand('npm install amxxpack --save-dev')];
203
+ case 1:
204
+ _a.sent();
205
+ return [4 /*yield*/, this.execCommand('npm run postinstall')];
206
+ case 2:
207
+ _a.sent();
208
+ return [2 /*return*/];
209
+ }
210
+ });
211
+ });
212
+ };
213
+ ProjectCreator.prototype.initGit = function () {
214
+ return __awaiter(this, void 0, void 0, function () {
215
+ return __generator(this, function (_a) {
216
+ switch (_a.label) {
217
+ case 0:
218
+ logger_1.default.info('🌿 Initializing git...');
219
+ return [4 /*yield*/, this.execCommand('git init')];
220
+ case 1:
221
+ _a.sent();
222
+ return [2 /*return*/];
223
+ }
224
+ });
225
+ });
226
+ };
227
+ ProjectCreator.prototype.updateGitignore = function () {
228
+ return __awaiter(this, void 0, void 0, function () {
229
+ var filePath, lines, addDir;
230
+ var _this = this;
231
+ return __generator(this, function (_a) {
232
+ switch (_a.label) {
233
+ case 0:
234
+ logger_1.default.info('❔ Updating .gitignore file...');
235
+ filePath = path_1.default.join(this.projectDir, '.gitignore');
236
+ lines = ['*.amxx'];
237
+ addDir = function (dir) { return !path_1.default.isAbsolute(dir) && lines.push("".concat(path_1.default.relative(_this.projectDir, dir), "/")); };
238
+ addDir('node_modules');
239
+ addDir(this.projectConfig.compiler.dir);
240
+ addDir(this.projectConfig.thirdparty.dir);
241
+ addDir(this.projectConfig.output.assets);
242
+ if (fs_1.default.existsSync(filePath)) {
243
+ lines.unshift('');
244
+ }
245
+ lines.push('');
246
+ return [4 /*yield*/, fs_1.default.promises.appendFile(filePath, lines.join('\n'))];
247
+ case 1:
248
+ _a.sent();
249
+ return [2 /*return*/];
250
+ }
251
+ });
252
+ });
253
+ };
254
+ ProjectCreator.prototype.isInitialized = function () {
255
+ return fs_1.default.existsSync(path_1.default.join(this.projectDir, config_1.default.projectConfig));
256
+ };
257
+ ProjectCreator.prototype.isGitInitialized = function () {
258
+ return fs_1.default.existsSync(path_1.default.join(this.projectDir, '.git'));
259
+ };
260
+ ProjectCreator.prototype.isNpmPackageInitialized = function () {
261
+ return fs_1.default.existsSync(path_1.default.join(this.projectDir, 'package.json'));
262
+ };
263
+ ProjectCreator.prototype.execCommand = function (command) {
264
+ var process = (0, child_process_1.exec)(command, {
265
+ cwd: this.projectDir
266
+ });
267
+ return new Promise(function (resolve) {
268
+ process.on('error', resolve);
269
+ process.on('close', resolve);
270
+ });
271
+ };
272
+ return ProjectCreator;
273
+ }());
274
+ 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;