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.
- package/README.md +25 -20
- package/lib/builder/builder.d.ts +2 -3
- package/lib/builder/builder.js +19 -40
- package/lib/builder/index.d.ts +0 -1
- package/lib/builder/index.js +0 -11
- package/lib/cli/controller.d.ts +13 -9
- package/lib/cli/controller.js +106 -49
- package/lib/cli/index.d.ts +2 -1
- package/lib/cli/index.js +5 -0
- package/lib/cli/program.js +76 -20
- package/lib/cli/services/project-creator.d.ts +21 -0
- package/lib/cli/services/project-creator.js +274 -0
- package/lib/cli/services/template-builder.d.ts +11 -0
- package/lib/cli/services/template-builder.js +104 -0
- package/lib/cli/types.d.ts +12 -0
- package/lib/{builder → cli}/types.js +0 -0
- package/lib/config/index.d.ts +8 -0
- package/lib/config/index.js +14 -0
- package/lib/downloaders/compiler/constants.d.ts +9 -0
- package/lib/{compiler-downloader → downloaders/compiler}/constants.js +1 -4
- package/lib/downloaders/compiler/downloader.d.ts +3 -0
- package/lib/{compiler-downloader → downloaders/compiler}/downloader.js +14 -37
- package/lib/{compiler-downloader → downloaders/compiler}/index.d.ts +0 -0
- package/lib/{compiler-downloader → downloaders/compiler}/index.js +0 -0
- package/lib/{compiler-downloader → downloaders/compiler}/resolvers.d.ts +1 -1
- package/lib/{compiler-downloader → downloaders/compiler}/resolvers.js +2 -1
- package/lib/{compiler-downloader → downloaders/compiler}/types.d.ts +0 -0
- package/lib/{compiler-downloader → downloaders/compiler}/types.js +0 -0
- package/lib/downloaders/thirdparty/downloader.d.ts +3 -0
- package/lib/downloaders/thirdparty/downloader.js +69 -0
- package/lib/downloaders/thirdparty/index.d.ts +1 -0
- package/lib/downloaders/thirdparty/index.js +9 -0
- package/lib/downloaders/thirdparty/types.d.ts +5 -0
- package/lib/downloaders/thirdparty/types.js +2 -0
- package/lib/logger/constants.d.ts +7 -0
- package/lib/logger/constants.js +12 -0
- package/lib/{services → logger}/logger.d.ts +5 -11
- package/lib/{services → logger}/logger.js +17 -25
- package/lib/logger/types.d.ts +3 -0
- package/lib/logger/types.js +2 -0
- package/lib/project-config/defaults.d.ts +3 -0
- package/lib/project-config/defaults.js +38 -0
- package/lib/project-config/index.d.ts +6 -0
- package/lib/project-config/index.js +8 -0
- package/lib/project-config/resolve.d.ts +3 -0
- package/lib/project-config/resolve.js +110 -0
- package/lib/types/index.d.ts +45 -0
- package/lib/types/index.js +2 -0
- package/lib/utils/accumulator.d.ts +2 -1
- package/lib/utils/download.d.ts +6 -0
- package/lib/utils/download.js +63 -0
- package/package.json +7 -1
- package/resources/templates/include-directive.txt +1 -0
- package/resources/templates/include.txt +5 -0
- package/resources/templates/library-include.txt +6 -0
- package/resources/templates/library-script.txt +10 -0
- package/resources/templates/script.txt +5 -0
- package/lib/builder/types.d.ts +0 -20
- package/lib/compiler-downloader/constants.d.ts +0 -12
- package/lib/compiler-downloader/downloader.d.ts +0 -2
- 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
|
-
-
|
|
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
|
|
35
|
-
- Execute `npx amxxpack
|
|
36
|
-
- Use `
|
|
37
|
-
-
|
|
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
|
|
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
|
|
52
|
+
- `amxxpack new <script|lib|include> [name]` - create new file in the project workspace
|
|
55
53
|
- `--config` - config file
|
|
56
|
-
- `--
|
|
57
|
-
- `--
|
|
58
|
-
- `--
|
|
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
|
package/lib/builder/builder.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IProjectConfig } from '../types';
|
|
2
2
|
export default class AmxxBuilder {
|
|
3
|
-
private logger;
|
|
4
3
|
private config;
|
|
5
|
-
constructor(config:
|
|
4
|
+
constructor(config: IProjectConfig);
|
|
6
5
|
build(): Promise<void>;
|
|
7
6
|
watch(): Promise<void>;
|
|
8
7
|
buildSrc(): Promise<void>;
|
package/lib/builder/builder.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
334
|
-
includeDir: __spreadArray(__spreadArray([
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
356
|
-
|
|
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
|
|
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*/];
|
package/lib/builder/index.d.ts
CHANGED
package/lib/builder/index.js
CHANGED
|
@@ -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);
|
package/lib/cli/controller.d.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import AmxxBuilder
|
|
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
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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;
|
package/lib/cli/controller.js
CHANGED
|
@@ -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
|
|
47
|
-
|
|
48
|
-
|
|
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.
|
|
53
|
+
Controller.prototype.createBuilder = function (configPath) {
|
|
54
54
|
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
-
var
|
|
55
|
+
var projectConfig, builder;
|
|
56
56
|
return __generator(this, function (_a) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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.
|
|
67
|
+
Controller.prototype.create = function (options) {
|
|
69
68
|
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
-
var
|
|
69
|
+
var projectCreator;
|
|
71
70
|
return __generator(this, function (_a) {
|
|
72
71
|
switch (_a.label) {
|
|
73
|
-
case 0:
|
|
72
|
+
case 0:
|
|
73
|
+
projectCreator = new project_creator_1.default(options);
|
|
74
|
+
return [4 /*yield*/, projectCreator.createProject()];
|
|
74
75
|
case 1:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return [2 /*return*/, builder];
|
|
76
|
+
_a.sent();
|
|
77
|
+
return [2 /*return*/];
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
81
|
};
|
|
82
|
-
Controller.prototype.
|
|
82
|
+
Controller.prototype.config = function (projectDir) {
|
|
83
83
|
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
-
var
|
|
85
|
-
return __generator(this, function (
|
|
86
|
-
switch (
|
|
84
|
+
var projectCreator;
|
|
85
|
+
return __generator(this, function (_a) {
|
|
86
|
+
switch (_a.label) {
|
|
87
87
|
case 0:
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
projectCreator = new project_creator_1.default();
|
|
89
|
+
projectCreator.projectDir = projectDir;
|
|
90
|
+
return [4 /*yield*/, projectCreator.createProject()];
|
|
90
91
|
case 1:
|
|
91
|
-
|
|
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.
|
|
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
|
|
151
|
+
var projectConfig, _i, _a, dependency;
|
|
165
152
|
return __generator(this, function (_b) {
|
|
166
153
|
switch (_b.label) {
|
|
167
|
-
case 0: return [4 /*yield*/,
|
|
154
|
+
case 0: return [4 /*yield*/, project_config_1.default.resolve(configPath)];
|
|
168
155
|
case 1:
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
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
|
});
|
package/lib/cli/index.d.ts
CHANGED
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; } });
|
package/lib/cli/program.js
CHANGED
|
@@ -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('
|
|
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.
|
|
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',
|
|
68
|
-
.action(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(
|
|
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
|
-
.
|
|
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('
|
|
100
|
-
.
|
|
101
|
-
.option('--
|
|
102
|
-
.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
110
|
-
|
|
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
|
-
|
|
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
|
});
|