amxxpack 1.1.1 β 1.2.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/LICENSE +21 -0
- package/README.md +5 -2
- package/lib/builder/amxxpc.js +6 -3
- package/lib/builder/builder.d.ts +16 -10
- package/lib/builder/builder.js +279 -75
- package/lib/builder/plugins-cache.d.ts +16 -0
- package/lib/builder/plugins-cache.js +151 -0
- package/lib/cli/controller.d.ts +8 -2
- package/lib/cli/controller.js +34 -25
- package/lib/cli/program.js +10 -6
- package/lib/cli/services/project-creator.js +20 -6
- package/lib/config/index.d.ts +1 -0
- package/lib/config/index.js +5 -1
- package/lib/project-config/resolve.d.ts +1 -1
- package/lib/project-config/resolve.js +6 -5
- package/lib/types/index.d.ts +3 -3
- package/lib/utils/copy-file.d.ts +8 -0
- package/lib/utils/copy-file.js +83 -0
- package/lib/utils/setup-watch.d.ts +3 -0
- package/lib/utils/setup-watch.js +28 -0
- package/package.json +8 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Hedgehog Fog
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# π¦ AMXXPack [](https://www.npmjs.com/package/amxxpack)
|
|
1
|
+
# π¦ AMXXPack πΊπ¦ [](https://www.npmjs.com/package/amxxpack)
|
|
2
2
|
Simple build system and **CLI** for **AMX Mod X** projects.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
## π About
|
|
5
5
|
|
|
6
6
|
This system will be useful for projects with multiple plugins and assets. Using the command-line interface you can build entire project with a single command. It also supports hot rebuild to keep your plugins and assets up to date during the work.
|
|
7
7
|
|
|
@@ -47,8 +47,11 @@ npm install -g amxxpack
|
|
|
47
47
|
- `amxxpack build` - command to build the project
|
|
48
48
|
- `--watch` - flag to watch changes
|
|
49
49
|
- `--config` - config file
|
|
50
|
+
- `--ignore` - ignore build errors
|
|
51
|
+
- `--no-cache` - disable caching
|
|
50
52
|
- `amxxpack compile <path|glob>` - compile specific plugin in the project
|
|
51
53
|
- `--config` - config file
|
|
54
|
+
- `--no-cache` - disable caching
|
|
52
55
|
- `amxxpack new <script|lib|include> [name]` - create new file in the project workspace
|
|
53
56
|
- `--config` - config file
|
|
54
57
|
- `--name` - plugin name
|
package/lib/builder/amxxpc.js
CHANGED
|
@@ -90,9 +90,12 @@ function formatArgs(params, outPath) {
|
|
|
90
90
|
}
|
|
91
91
|
function compile(params) {
|
|
92
92
|
var parsedPath = path_1.default.parse(params.path);
|
|
93
|
-
var
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
var dest = params.dest.endsWith(".".concat(PLUGIN_EXT))
|
|
94
|
+
? params.dest
|
|
95
|
+
: path_1.default.join(params.dest, "".concat(parsedPath.name, ".").concat(PLUGIN_EXT));
|
|
96
|
+
var parsedDest = path_1.default.parse(dest);
|
|
97
|
+
var fileName = path_1.default.parse(dest).base;
|
|
98
|
+
mkdirp_1.default.sync(parsedDest.dir);
|
|
96
99
|
return new Promise(function (resolve) {
|
|
97
100
|
var output = (0, accumulator_1.default)();
|
|
98
101
|
var done = function (error) {
|
package/lib/builder/builder.d.ts
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import { IProjectConfig } from '../types';
|
|
2
|
+
export interface CompileOptions {
|
|
3
|
+
ignoreErrors?: boolean;
|
|
4
|
+
noCache?: boolean;
|
|
5
|
+
}
|
|
2
6
|
export default class AmxxBuilder {
|
|
3
|
-
private
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
private projectConfig;
|
|
8
|
+
private pluginCache;
|
|
9
|
+
constructor(projectConfig: IProjectConfig);
|
|
10
|
+
build(compileOptions: CompileOptions): Promise<void>;
|
|
11
|
+
watch(compileOptions: CompileOptions): Promise<void>;
|
|
12
|
+
buildScripts(compileOptions: CompileOptions): Promise<boolean>;
|
|
8
13
|
buildInclude(): Promise<void>;
|
|
9
14
|
buildAssets(): Promise<void>;
|
|
10
|
-
|
|
15
|
+
watchScripts(compileOptions: CompileOptions): Promise<void>;
|
|
11
16
|
watchInclude(): Promise<void>;
|
|
12
17
|
watchAssets(): Promise<void>;
|
|
13
|
-
updatePlugin(
|
|
14
|
-
updateScript(
|
|
15
|
-
updateAsset(
|
|
18
|
+
updatePlugin(srcDir: string, srcFile: string, compileOptions: CompileOptions): Promise<boolean>;
|
|
19
|
+
updateScript(srcDir: string, srcFile: string): Promise<void>;
|
|
20
|
+
updateAsset(srcDir: string, srcFile: string): Promise<void>;
|
|
16
21
|
updateInclude(filePath: string): Promise<void>;
|
|
17
22
|
findPlugins(pattern: string): Promise<string[]>;
|
|
18
|
-
compilePlugin(
|
|
23
|
+
compilePlugin(srcDir: string, srcFile: string, compileOptions?: CompileOptions): Promise<void>;
|
|
19
24
|
private buildDir;
|
|
20
25
|
private watchDir;
|
|
26
|
+
private initPluginCache;
|
|
21
27
|
}
|
package/lib/builder/builder.js
CHANGED
|
@@ -68,40 +68,59 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
68
68
|
};
|
|
69
69
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
70
70
|
var path_1 = __importDefault(require("path"));
|
|
71
|
-
var fs_1 = __importDefault(require("fs"));
|
|
72
71
|
var mkdirp_1 = __importDefault(require("mkdirp"));
|
|
73
|
-
var
|
|
74
|
-
var chokidar_1 = __importDefault(require("chokidar"));
|
|
72
|
+
var globule_1 = __importDefault(require("globule"));
|
|
75
73
|
var normalize_path_1 = __importDefault(require("normalize-path"));
|
|
74
|
+
var lodash_1 = require("lodash");
|
|
76
75
|
var amxxpc_1 = __importStar(require("./amxxpc"));
|
|
77
76
|
var constants_1 = require("./constants");
|
|
78
77
|
var logger_1 = __importDefault(require("../logger/logger"));
|
|
78
|
+
var plugins_cache_1 = __importDefault(require("./plugins-cache"));
|
|
79
|
+
var copy_file_1 = __importDefault(require("../utils/copy-file"));
|
|
80
|
+
var config_1 = __importDefault(require("../config"));
|
|
81
|
+
var setup_watch_1 = __importDefault(require("../utils/setup-watch"));
|
|
79
82
|
var AmxxBuilder = /** @class */ (function () {
|
|
80
|
-
function AmxxBuilder(
|
|
81
|
-
this.
|
|
83
|
+
function AmxxBuilder(projectConfig) {
|
|
84
|
+
this.projectConfig = projectConfig;
|
|
85
|
+
this.initPluginCache();
|
|
82
86
|
}
|
|
83
|
-
AmxxBuilder.prototype.build = function () {
|
|
87
|
+
AmxxBuilder.prototype.build = function (compileOptions) {
|
|
84
88
|
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
+
var success, err_1;
|
|
85
90
|
return __generator(this, function (_a) {
|
|
86
91
|
switch (_a.label) {
|
|
87
92
|
case 0:
|
|
88
93
|
logger_1.default.info('Building...');
|
|
89
|
-
|
|
94
|
+
_a.label = 1;
|
|
90
95
|
case 1:
|
|
91
|
-
_a.
|
|
92
|
-
return [4 /*yield*/, this.
|
|
96
|
+
_a.trys.push([1, 5, , 6]);
|
|
97
|
+
return [4 /*yield*/, this.buildAssets()];
|
|
93
98
|
case 2:
|
|
94
99
|
_a.sent();
|
|
95
|
-
return [4 /*yield*/, this.
|
|
100
|
+
return [4 /*yield*/, this.buildInclude()];
|
|
96
101
|
case 3:
|
|
97
102
|
_a.sent();
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
return [4 /*yield*/, this.buildScripts(compileOptions)];
|
|
104
|
+
case 4:
|
|
105
|
+
success = _a.sent();
|
|
106
|
+
if (success) {
|
|
107
|
+
logger_1.default.success('Build finished!');
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
logger_1.default.error('Build finished with errors!');
|
|
111
|
+
}
|
|
112
|
+
return [3 /*break*/, 6];
|
|
113
|
+
case 5:
|
|
114
|
+
err_1 = _a.sent();
|
|
115
|
+
logger_1.default.error('Build failed! Error:', err_1.message);
|
|
116
|
+
process.exit(1);
|
|
117
|
+
return [3 /*break*/, 6];
|
|
118
|
+
case 6: return [2 /*return*/];
|
|
100
119
|
}
|
|
101
120
|
});
|
|
102
121
|
});
|
|
103
122
|
};
|
|
104
|
-
AmxxBuilder.prototype.watch = function () {
|
|
123
|
+
AmxxBuilder.prototype.watch = function (compileOptions) {
|
|
105
124
|
return __awaiter(this, void 0, void 0, function () {
|
|
106
125
|
return __generator(this, function (_a) {
|
|
107
126
|
switch (_a.label) {
|
|
@@ -111,7 +130,7 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
111
130
|
return [4 /*yield*/, this.watchInclude()];
|
|
112
131
|
case 2:
|
|
113
132
|
_a.sent();
|
|
114
|
-
return [4 /*yield*/, this.
|
|
133
|
+
return [4 /*yield*/, this.watchScripts(compileOptions)];
|
|
115
134
|
case 3:
|
|
116
135
|
_a.sent();
|
|
117
136
|
return [2 /*return*/];
|
|
@@ -119,15 +138,63 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
119
138
|
});
|
|
120
139
|
});
|
|
121
140
|
};
|
|
122
|
-
AmxxBuilder.prototype.
|
|
141
|
+
AmxxBuilder.prototype.buildScripts = function (compileOptions) {
|
|
123
142
|
return __awaiter(this, void 0, void 0, function () {
|
|
143
|
+
var scriptsDirs, success, _loop_1, this_1, _i, scriptsDirs_1, scriptsDir;
|
|
124
144
|
var _this = this;
|
|
125
145
|
return __generator(this, function (_a) {
|
|
126
146
|
switch (_a.label) {
|
|
127
|
-
case 0:
|
|
147
|
+
case 0:
|
|
148
|
+
scriptsDirs = (0, lodash_1.castArray)(this.projectConfig.input.scripts);
|
|
149
|
+
success = true;
|
|
150
|
+
_a.label = 1;
|
|
128
151
|
case 1:
|
|
152
|
+
_a.trys.push([1, , 6, 7]);
|
|
153
|
+
_loop_1 = function (scriptsDir) {
|
|
154
|
+
return __generator(this, function (_b) {
|
|
155
|
+
switch (_b.label) {
|
|
156
|
+
case 0: return [4 /*yield*/, this_1.buildDir(scriptsDir, constants_1.SCRIPTS_PATH_PATTERN,
|
|
157
|
+
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
|
158
|
+
function (filePath) { return __awaiter(_this, void 0, void 0, function () {
|
|
159
|
+
var srcFile, isUpdated;
|
|
160
|
+
return __generator(this, function (_a) {
|
|
161
|
+
switch (_a.label) {
|
|
162
|
+
case 0:
|
|
163
|
+
srcFile = path_1.default.relative(scriptsDir, filePath);
|
|
164
|
+
return [4 /*yield*/, this.updatePlugin(scriptsDir, srcFile, compileOptions)];
|
|
165
|
+
case 1:
|
|
166
|
+
isUpdated = _a.sent();
|
|
167
|
+
success = success && isUpdated;
|
|
168
|
+
return [2 /*return*/];
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}); })];
|
|
172
|
+
case 1:
|
|
173
|
+
_b.sent();
|
|
174
|
+
return [2 /*return*/];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
this_1 = this;
|
|
179
|
+
_i = 0, scriptsDirs_1 = scriptsDirs;
|
|
180
|
+
_a.label = 2;
|
|
181
|
+
case 2:
|
|
182
|
+
if (!(_i < scriptsDirs_1.length)) return [3 /*break*/, 5];
|
|
183
|
+
scriptsDir = scriptsDirs_1[_i];
|
|
184
|
+
return [5 /*yield**/, _loop_1(scriptsDir)];
|
|
185
|
+
case 3:
|
|
129
186
|
_a.sent();
|
|
130
|
-
|
|
187
|
+
_a.label = 4;
|
|
188
|
+
case 4:
|
|
189
|
+
_i++;
|
|
190
|
+
return [3 /*break*/, 2];
|
|
191
|
+
case 5: return [3 /*break*/, 7];
|
|
192
|
+
case 6:
|
|
193
|
+
if (!compileOptions.noCache) {
|
|
194
|
+
this.pluginCache.save(config_1.default.cacheFile);
|
|
195
|
+
}
|
|
196
|
+
return [7 /*endfinally*/];
|
|
197
|
+
case 7: return [2 /*return*/, success];
|
|
131
198
|
}
|
|
132
199
|
});
|
|
133
200
|
});
|
|
@@ -137,7 +204,7 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
137
204
|
var _this = this;
|
|
138
205
|
return __generator(this, function (_a) {
|
|
139
206
|
switch (_a.label) {
|
|
140
|
-
case 0: return [4 /*yield*/, this.buildDir(this.
|
|
207
|
+
case 0: return [4 /*yield*/, this.buildDir(this.projectConfig.input.include, constants_1.INCLUDE_PATH_PATTERN, function (filePath) { return _this.updateInclude(filePath); })];
|
|
141
208
|
case 1:
|
|
142
209
|
_a.sent();
|
|
143
210
|
return [2 /*return*/];
|
|
@@ -147,30 +214,99 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
147
214
|
};
|
|
148
215
|
AmxxBuilder.prototype.buildAssets = function () {
|
|
149
216
|
return __awaiter(this, void 0, void 0, function () {
|
|
217
|
+
var assetsDirs, _loop_2, this_2, _i, assetsDirs_1, assetsDir;
|
|
150
218
|
var _this = this;
|
|
151
219
|
return __generator(this, function (_a) {
|
|
152
220
|
switch (_a.label) {
|
|
153
221
|
case 0:
|
|
154
|
-
if (!this.
|
|
222
|
+
if (!this.projectConfig.input.assets) {
|
|
155
223
|
return [2 /*return*/];
|
|
156
224
|
}
|
|
157
|
-
|
|
225
|
+
assetsDirs = (0, lodash_1.castArray)(this.projectConfig.input.assets);
|
|
226
|
+
_loop_2 = function (assetsDir) {
|
|
227
|
+
return __generator(this, function (_b) {
|
|
228
|
+
switch (_b.label) {
|
|
229
|
+
case 0: return [4 /*yield*/, this_2.buildDir(assetsDir, constants_1.ASSETS_PATH_PATTERN, function (filePath) { return __awaiter(_this, void 0, void 0, function () {
|
|
230
|
+
var assetFile;
|
|
231
|
+
return __generator(this, function (_a) {
|
|
232
|
+
switch (_a.label) {
|
|
233
|
+
case 0:
|
|
234
|
+
assetFile = path_1.default.relative(assetsDir, filePath);
|
|
235
|
+
return [4 /*yield*/, this.updateAsset(assetsDir, assetFile)];
|
|
236
|
+
case 1:
|
|
237
|
+
_a.sent();
|
|
238
|
+
return [2 /*return*/];
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}); })];
|
|
242
|
+
case 1:
|
|
243
|
+
_b.sent();
|
|
244
|
+
return [2 /*return*/];
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
this_2 = this;
|
|
249
|
+
_i = 0, assetsDirs_1 = assetsDirs;
|
|
250
|
+
_a.label = 1;
|
|
158
251
|
case 1:
|
|
252
|
+
if (!(_i < assetsDirs_1.length)) return [3 /*break*/, 4];
|
|
253
|
+
assetsDir = assetsDirs_1[_i];
|
|
254
|
+
return [5 /*yield**/, _loop_2(assetsDir)];
|
|
255
|
+
case 2:
|
|
159
256
|
_a.sent();
|
|
160
|
-
|
|
257
|
+
_a.label = 3;
|
|
258
|
+
case 3:
|
|
259
|
+
_i++;
|
|
260
|
+
return [3 /*break*/, 1];
|
|
261
|
+
case 4: return [2 /*return*/];
|
|
161
262
|
}
|
|
162
263
|
});
|
|
163
264
|
});
|
|
164
265
|
};
|
|
165
|
-
AmxxBuilder.prototype.
|
|
266
|
+
AmxxBuilder.prototype.watchScripts = function (compileOptions) {
|
|
166
267
|
return __awaiter(this, void 0, void 0, function () {
|
|
268
|
+
var scriptsDirs, _loop_3, this_3, _i, scriptsDirs_2, scriptsDir;
|
|
167
269
|
var _this = this;
|
|
168
270
|
return __generator(this, function (_a) {
|
|
169
271
|
switch (_a.label) {
|
|
170
|
-
case 0:
|
|
272
|
+
case 0:
|
|
273
|
+
scriptsDirs = (0, lodash_1.castArray)(this.projectConfig.input.scripts);
|
|
274
|
+
_loop_3 = function (scriptsDir) {
|
|
275
|
+
return __generator(this, function (_b) {
|
|
276
|
+
switch (_b.label) {
|
|
277
|
+
case 0: return [4 /*yield*/, this_3.watchDir(scriptsDir, constants_1.SCRIPTS_PATH_PATTERN, function (filePath) { return __awaiter(_this, void 0, void 0, function () {
|
|
278
|
+
var srcFile;
|
|
279
|
+
return __generator(this, function (_a) {
|
|
280
|
+
switch (_a.label) {
|
|
281
|
+
case 0:
|
|
282
|
+
srcFile = path_1.default.relative(scriptsDir, filePath);
|
|
283
|
+
return [4 /*yield*/, this.updatePlugin(scriptsDir, srcFile, compileOptions)];
|
|
284
|
+
case 1:
|
|
285
|
+
_a.sent();
|
|
286
|
+
return [2 /*return*/];
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}); })];
|
|
290
|
+
case 1:
|
|
291
|
+
_b.sent();
|
|
292
|
+
return [2 /*return*/];
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
this_3 = this;
|
|
297
|
+
_i = 0, scriptsDirs_2 = scriptsDirs;
|
|
298
|
+
_a.label = 1;
|
|
171
299
|
case 1:
|
|
300
|
+
if (!(_i < scriptsDirs_2.length)) return [3 /*break*/, 4];
|
|
301
|
+
scriptsDir = scriptsDirs_2[_i];
|
|
302
|
+
return [5 /*yield**/, _loop_3(scriptsDir)];
|
|
303
|
+
case 2:
|
|
172
304
|
_a.sent();
|
|
173
|
-
|
|
305
|
+
_a.label = 3;
|
|
306
|
+
case 3:
|
|
307
|
+
_i++;
|
|
308
|
+
return [3 /*break*/, 1];
|
|
309
|
+
case 4: return [2 /*return*/];
|
|
174
310
|
}
|
|
175
311
|
});
|
|
176
312
|
});
|
|
@@ -180,7 +316,7 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
180
316
|
var _this = this;
|
|
181
317
|
return __generator(this, function (_a) {
|
|
182
318
|
switch (_a.label) {
|
|
183
|
-
case 0: return [4 /*yield*/, this.watchDir(this.
|
|
319
|
+
case 0: return [4 /*yield*/, this.watchDir(this.projectConfig.input.include, constants_1.INCLUDE_PATH_PATTERN, function (filePath) { return _this.updateInclude(filePath); })];
|
|
184
320
|
case 1:
|
|
185
321
|
_a.sent();
|
|
186
322
|
return [2 /*return*/];
|
|
@@ -190,51 +326,95 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
190
326
|
};
|
|
191
327
|
AmxxBuilder.prototype.watchAssets = function () {
|
|
192
328
|
return __awaiter(this, void 0, void 0, function () {
|
|
329
|
+
var assetsDirs, _loop_4, this_4, _i, assetsDirs_2, assetsDir;
|
|
193
330
|
var _this = this;
|
|
194
331
|
return __generator(this, function (_a) {
|
|
195
332
|
switch (_a.label) {
|
|
196
333
|
case 0:
|
|
197
|
-
if (!this.
|
|
334
|
+
if (!this.projectConfig.input.assets) {
|
|
198
335
|
return [2 /*return*/];
|
|
199
336
|
}
|
|
200
|
-
|
|
337
|
+
assetsDirs = (0, lodash_1.castArray)(this.projectConfig.input.assets);
|
|
338
|
+
_loop_4 = function (assetsDir) {
|
|
339
|
+
return __generator(this, function (_b) {
|
|
340
|
+
switch (_b.label) {
|
|
341
|
+
case 0: return [4 /*yield*/, this_4.watchDir(assetsDir, constants_1.ASSETS_PATH_PATTERN, function (filePath) { return __awaiter(_this, void 0, void 0, function () {
|
|
342
|
+
var assetFile;
|
|
343
|
+
return __generator(this, function (_a) {
|
|
344
|
+
switch (_a.label) {
|
|
345
|
+
case 0:
|
|
346
|
+
assetFile = path_1.default.relative(assetsDir, filePath);
|
|
347
|
+
return [4 /*yield*/, this.updateAsset(assetsDir, assetFile)];
|
|
348
|
+
case 1:
|
|
349
|
+
_a.sent();
|
|
350
|
+
return [2 /*return*/];
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
}); })];
|
|
354
|
+
case 1:
|
|
355
|
+
_b.sent();
|
|
356
|
+
return [2 /*return*/];
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
};
|
|
360
|
+
this_4 = this;
|
|
361
|
+
_i = 0, assetsDirs_2 = assetsDirs;
|
|
362
|
+
_a.label = 1;
|
|
201
363
|
case 1:
|
|
364
|
+
if (!(_i < assetsDirs_2.length)) return [3 /*break*/, 4];
|
|
365
|
+
assetsDir = assetsDirs_2[_i];
|
|
366
|
+
return [5 /*yield**/, _loop_4(assetsDir)];
|
|
367
|
+
case 2:
|
|
202
368
|
_a.sent();
|
|
203
|
-
|
|
369
|
+
_a.label = 3;
|
|
370
|
+
case 3:
|
|
371
|
+
_i++;
|
|
372
|
+
return [3 /*break*/, 1];
|
|
373
|
+
case 4: return [2 /*return*/];
|
|
204
374
|
}
|
|
205
375
|
});
|
|
206
376
|
});
|
|
207
377
|
};
|
|
208
|
-
AmxxBuilder.prototype.updatePlugin = function (
|
|
378
|
+
AmxxBuilder.prototype.updatePlugin = function (srcDir, srcFile, compileOptions) {
|
|
209
379
|
return __awaiter(this, void 0, void 0, function () {
|
|
380
|
+
var err_2;
|
|
210
381
|
return __generator(this, function (_a) {
|
|
211
382
|
switch (_a.label) {
|
|
212
|
-
case 0:
|
|
383
|
+
case 0:
|
|
384
|
+
_a.trys.push([0, 2, , 3]);
|
|
385
|
+
return [4 /*yield*/, this.compilePlugin(srcDir, srcFile, compileOptions)];
|
|
213
386
|
case 1:
|
|
214
387
|
_a.sent();
|
|
215
|
-
return [
|
|
388
|
+
return [3 /*break*/, 3];
|
|
216
389
|
case 2:
|
|
390
|
+
err_2 = _a.sent();
|
|
391
|
+
if (!compileOptions.ignoreErrors) {
|
|
392
|
+
throw err_2;
|
|
393
|
+
}
|
|
394
|
+
return [2 /*return*/, false];
|
|
395
|
+
case 3: return [4 /*yield*/, this.updateScript(srcDir, srcFile)];
|
|
396
|
+
case 4:
|
|
217
397
|
_a.sent();
|
|
218
|
-
return [2 /*return
|
|
398
|
+
return [2 /*return*/, true];
|
|
219
399
|
}
|
|
220
400
|
});
|
|
221
401
|
});
|
|
222
402
|
};
|
|
223
|
-
AmxxBuilder.prototype.updateScript = function (
|
|
403
|
+
AmxxBuilder.prototype.updateScript = function (srcDir, srcFile) {
|
|
224
404
|
return __awaiter(this, void 0, void 0, function () {
|
|
225
405
|
var srcPath, destPath;
|
|
226
406
|
return __generator(this, function (_a) {
|
|
227
407
|
switch (_a.label) {
|
|
228
408
|
case 0:
|
|
229
|
-
if (!this.
|
|
409
|
+
if (!this.projectConfig.output.scripts) {
|
|
230
410
|
return [2 /*return*/];
|
|
231
411
|
}
|
|
232
|
-
srcPath = path_1.default.resolve(
|
|
233
|
-
destPath = path_1.default.join(this.
|
|
234
|
-
return [4 /*yield*/, (0, mkdirp_1.default)(this.
|
|
412
|
+
srcPath = path_1.default.resolve(srcDir, srcFile);
|
|
413
|
+
destPath = path_1.default.join(this.projectConfig.output.scripts, path_1.default.parse(srcFile).base);
|
|
414
|
+
return [4 /*yield*/, (0, mkdirp_1.default)(this.projectConfig.output.scripts)];
|
|
235
415
|
case 1:
|
|
236
416
|
_a.sent();
|
|
237
|
-
return [4 /*yield*/,
|
|
417
|
+
return [4 /*yield*/, (0, copy_file_1.default)(srcPath, destPath)];
|
|
238
418
|
case 2:
|
|
239
419
|
_a.sent();
|
|
240
420
|
logger_1.default.info('Script updated:', (0, normalize_path_1.default)(destPath));
|
|
@@ -243,19 +423,18 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
243
423
|
});
|
|
244
424
|
});
|
|
245
425
|
};
|
|
246
|
-
AmxxBuilder.prototype.updateAsset = function (
|
|
426
|
+
AmxxBuilder.prototype.updateAsset = function (srcDir, srcFile) {
|
|
247
427
|
return __awaiter(this, void 0, void 0, function () {
|
|
248
|
-
var srcPath,
|
|
428
|
+
var srcPath, destPath;
|
|
249
429
|
return __generator(this, function (_a) {
|
|
250
430
|
switch (_a.label) {
|
|
251
431
|
case 0:
|
|
252
|
-
srcPath = path_1.default.resolve(
|
|
253
|
-
|
|
254
|
-
destPath = path_1.default.join(this.config.output.assets, relativePath);
|
|
432
|
+
srcPath = path_1.default.resolve(srcDir, srcFile);
|
|
433
|
+
destPath = path_1.default.join(this.projectConfig.output.assets, srcFile);
|
|
255
434
|
return [4 /*yield*/, (0, mkdirp_1.default)(path_1.default.parse(destPath).dir)];
|
|
256
435
|
case 1:
|
|
257
436
|
_a.sent();
|
|
258
|
-
return [4 /*yield*/,
|
|
437
|
+
return [4 /*yield*/, (0, copy_file_1.default)(srcPath, destPath)];
|
|
259
438
|
case 2:
|
|
260
439
|
_a.sent();
|
|
261
440
|
logger_1.default.info('Asset updated', (0, normalize_path_1.default)(destPath));
|
|
@@ -271,11 +450,11 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
271
450
|
switch (_a.label) {
|
|
272
451
|
case 0:
|
|
273
452
|
srcPath = path_1.default.resolve(filePath);
|
|
274
|
-
destPath = path_1.default.join(this.
|
|
275
|
-
return [4 /*yield*/, (0, mkdirp_1.default)(this.
|
|
453
|
+
destPath = path_1.default.join(this.projectConfig.output.include, path_1.default.parse(filePath).base);
|
|
454
|
+
return [4 /*yield*/, (0, mkdirp_1.default)(this.projectConfig.output.include)];
|
|
276
455
|
case 1:
|
|
277
456
|
_a.sent();
|
|
278
|
-
return [4 /*yield*/,
|
|
457
|
+
return [4 /*yield*/, (0, copy_file_1.default)(srcPath, destPath)];
|
|
279
458
|
case 2:
|
|
280
459
|
_a.sent();
|
|
281
460
|
logger_1.default.info('Include updated:', (0, normalize_path_1.default)(destPath));
|
|
@@ -290,8 +469,8 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
290
469
|
return __generator(this, function (_a) {
|
|
291
470
|
switch (_a.label) {
|
|
292
471
|
case 0:
|
|
293
|
-
pathPattern =
|
|
294
|
-
return [4 /*yield*/,
|
|
472
|
+
pathPattern = (0, lodash_1.map)((0, lodash_1.castArray)(this.projectConfig.input.scripts), function (dir) { return path_1.default.join(dir, '**', pattern); });
|
|
473
|
+
return [4 /*yield*/, globule_1.default.find(pathPattern)];
|
|
295
474
|
case 1:
|
|
296
475
|
matches = _a.sent();
|
|
297
476
|
return [2 /*return*/, matches.filter(function (filePath) { return path_1.default.extname(filePath) === '.sma'; })];
|
|
@@ -299,35 +478,56 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
299
478
|
});
|
|
300
479
|
});
|
|
301
480
|
};
|
|
302
|
-
AmxxBuilder.prototype.compilePlugin = function (
|
|
481
|
+
AmxxBuilder.prototype.compilePlugin = function (srcDir, srcFile, compileOptions) {
|
|
482
|
+
if (compileOptions === void 0) { compileOptions = {}; }
|
|
303
483
|
return __awaiter(this, void 0, void 0, function () {
|
|
304
|
-
var srcPath, destDir,
|
|
305
|
-
return __generator(this, function (
|
|
306
|
-
switch (
|
|
484
|
+
var srcPath, _a, scriptName, srcNestedDir, destDir, pluginDest, isUpdated, _b, relateiveSrcPath, executablePath, result, destPath, relativeFilePath;
|
|
485
|
+
return __generator(this, function (_c) {
|
|
486
|
+
switch (_c.label) {
|
|
307
487
|
case 0:
|
|
308
|
-
srcPath = path_1.default.resolve(
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
488
|
+
srcPath = path_1.default.resolve(srcDir, srcFile);
|
|
489
|
+
_a = path_1.default.parse(srcFile), scriptName = _a.name, srcNestedDir = _a.dir;
|
|
490
|
+
destDir = path_1.default.resolve(this.projectConfig.output.plugins, this.projectConfig.rules.flatCompilation ? '.' : srcNestedDir);
|
|
491
|
+
pluginDest = path_1.default.join(destDir, "".concat(scriptName, ".amxx"));
|
|
492
|
+
if (!compileOptions.noCache) return [3 /*break*/, 1];
|
|
493
|
+
_b = false;
|
|
494
|
+
return [3 /*break*/, 3];
|
|
495
|
+
case 1: return [4 /*yield*/, this.pluginCache.isPluginUpdated(srcPath, pluginDest)];
|
|
496
|
+
case 2:
|
|
497
|
+
_b = _c.sent();
|
|
498
|
+
_c.label = 3;
|
|
499
|
+
case 3:
|
|
500
|
+
isUpdated = _b;
|
|
314
501
|
relateiveSrcPath = path_1.default.relative(process.cwd(), srcPath);
|
|
315
|
-
|
|
502
|
+
if (isUpdated) {
|
|
503
|
+
logger_1.default.info("Script \"".concat((0, normalize_path_1.default)(relateiveSrcPath), "\" is already up to date. Skipped!"));
|
|
504
|
+
return [2 /*return*/];
|
|
505
|
+
}
|
|
506
|
+
executablePath = path_1.default.join(this.projectConfig.compiler.dir, this.projectConfig.compiler.executable);
|
|
316
507
|
return [4 /*yield*/, (0, mkdirp_1.default)(destDir)];
|
|
317
|
-
case
|
|
318
|
-
|
|
508
|
+
case 4:
|
|
509
|
+
_c.sent();
|
|
319
510
|
return [4 /*yield*/, (0, amxxpc_1.default)({
|
|
320
511
|
path: srcPath,
|
|
321
|
-
dest:
|
|
322
|
-
compiler:
|
|
512
|
+
dest: pluginDest,
|
|
513
|
+
compiler: executablePath,
|
|
323
514
|
includeDir: __spreadArray(__spreadArray([
|
|
324
|
-
path_1.default.join(this.
|
|
325
|
-
], this.
|
|
326
|
-
this.config.input.include,
|
|
327
|
-
], false)
|
|
515
|
+
path_1.default.join(this.projectConfig.compiler.dir, 'include')
|
|
516
|
+
], this.projectConfig.include, true), (0, lodash_1.castArray)(this.projectConfig.input.include), true)
|
|
328
517
|
})];
|
|
329
|
-
case
|
|
330
|
-
result =
|
|
518
|
+
case 5:
|
|
519
|
+
result = _c.sent();
|
|
520
|
+
if (!!compileOptions.noCache) return [3 /*break*/, 9];
|
|
521
|
+
if (!!result.error) return [3 /*break*/, 7];
|
|
522
|
+
return [4 /*yield*/, this.pluginCache.updatePlugin(srcPath, pluginDest)];
|
|
523
|
+
case 6:
|
|
524
|
+
_c.sent();
|
|
525
|
+
return [3 /*break*/, 9];
|
|
526
|
+
case 7: return [4 /*yield*/, this.pluginCache.deletePlugin(srcPath)];
|
|
527
|
+
case 8:
|
|
528
|
+
_c.sent();
|
|
529
|
+
_c.label = 9;
|
|
530
|
+
case 9:
|
|
331
531
|
result.output.messages.forEach(function (message) {
|
|
332
532
|
var startLine = message.startLine, type = message.type, code = message.code, text = message.text, filename = message.filename;
|
|
333
533
|
var relativeFilePath = filename ? path_1.default.relative(process.cwd(), filename) : relateiveSrcPath;
|
|
@@ -343,7 +543,7 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
343
543
|
});
|
|
344
544
|
if (result.success) {
|
|
345
545
|
destPath = path_1.default.join(destDir, result.plugin);
|
|
346
|
-
relativeFilePath = path_1.default.relative(process.cwd(),
|
|
546
|
+
relativeFilePath = path_1.default.relative(process.cwd(), srcPath);
|
|
347
547
|
logger_1.default.success('Compilation success:', (0, normalize_path_1.default)(relativeFilePath));
|
|
348
548
|
logger_1.default.info('Plugin updated:', (0, normalize_path_1.default)(destPath));
|
|
349
549
|
}
|
|
@@ -361,8 +561,8 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
361
561
|
return __generator(this, function (_a) {
|
|
362
562
|
switch (_a.label) {
|
|
363
563
|
case 0:
|
|
364
|
-
pathPattern = path_1.default.join(
|
|
365
|
-
return [4 /*yield*/,
|
|
564
|
+
pathPattern = (0, lodash_1.map)((0, lodash_1.castArray)(baseDir), function (dir) { return path_1.default.join(dir, pattern); });
|
|
565
|
+
return [4 /*yield*/, globule_1.default.find(pathPattern, { nodir: true })];
|
|
366
566
|
case 1:
|
|
367
567
|
matches = _a.sent();
|
|
368
568
|
return [4 /*yield*/, matches.reduce(function (acc, match) { return acc.then(function () { return cb(match); }); }, Promise.resolve())];
|
|
@@ -377,8 +577,8 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
377
577
|
return __awaiter(this, void 0, void 0, function () {
|
|
378
578
|
var pathPattern, watcher, updateFn;
|
|
379
579
|
return __generator(this, function (_a) {
|
|
380
|
-
pathPattern = path_1.default.join(
|
|
381
|
-
watcher =
|
|
580
|
+
pathPattern = (0, lodash_1.map)((0, lodash_1.castArray)(baseDir), function (dir) { return path_1.default.join(dir, pattern); });
|
|
581
|
+
watcher = (0, setup_watch_1.default)(pathPattern);
|
|
382
582
|
updateFn = function (filePath) { return cb(filePath).catch(function (err) { return logger_1.default.error(err.message); }); };
|
|
383
583
|
watcher.on('add', updateFn);
|
|
384
584
|
watcher.on('change', updateFn);
|
|
@@ -386,6 +586,10 @@ var AmxxBuilder = /** @class */ (function () {
|
|
|
386
586
|
});
|
|
387
587
|
});
|
|
388
588
|
};
|
|
589
|
+
AmxxBuilder.prototype.initPluginCache = function () {
|
|
590
|
+
this.pluginCache = new plugins_cache_1.default();
|
|
591
|
+
this.pluginCache.load(config_1.default.cacheFile);
|
|
592
|
+
};
|
|
389
593
|
return AmxxBuilder;
|
|
390
594
|
}());
|
|
391
595
|
exports.default = AmxxBuilder;
|