amxxpack 0.1.3 → 1.0.1

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
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # 📦 AMXXPack
1
+ # 📦 AMXXPack [![npm](https://img.shields.io/npm/v/amxxpack.svg)](https://www.npmjs.com/package/amxxpack)
2
2
  Simple build system and **CLI** for **AMX Mod X** projects.
3
3
 
4
4
  # 📄 About
@@ -27,32 +27,37 @@ npm install -g amxxpack
27
27
  ```
28
28
 
29
29
  ## ▶ Quick start
30
- - Create new directory for your project
31
- - Open a terminal inside the project directory
32
- - Execute `npm init -y` command to init the package
30
+ - Open a terminal inside the project directory (existing or create a new one)
33
31
  - Execute `npm install amxxpack --save-dev` command to install `amxxpack` locally
34
- - Execute `npx amxxpack init` command to create new config
35
- - Execute `npx amxxpack fetch-compiler` to download latest compiler release
36
- - Use `npx amxxpack build` command to build the project
37
- - Adding build scripts *(optional)*
38
-
39
- To use `npm run build` and `npm run watch` to build or watch the project update the `scripts` section in `package.json`:
40
- ```json
41
- "scripts": {
42
- "build": "amxxpack build",
43
- "watch": "amxxpack build --watch"
44
- }
45
- ```
32
+ - Execute `npx amxxpack create .` command to create new config
33
+ - Execute `npx amxxpack install` to download project dependencies (compiler, thirdparty etc.)
34
+ - Use `npm run build` command to build the project
35
+ - Use `npm run watch` command to build the project and watch changes
46
36
 
47
37
  ## 📋 Commands
48
- - `amxxpack init` - init config for a new project
38
+ - `amxxpack create <name>` - create new project
39
+ - `--git` - initialize git
40
+ - `--nonpm` - don't initialize npm pacakge
41
+ - `--version` - project version
42
+ - `--author` - project author
43
+ - `--description` - project name
44
+ - `amxxpack config` - initialize project config in current workspace
45
+ - `amxxpack install` - install project dependencies
46
+ - `--config` - config file
49
47
  - `amxxpack build` - command to build the project
50
48
  - `--watch` - flag to watch changes
51
49
  - `--config` - config file
52
50
  - `amxxpack compile <path|glob>` - compile specific plugin in the project
53
51
  - `--config` - config file
54
- - `amxxpack fetch-compiler` - fetch amxmodx compiler
52
+ - `amxxpack new <script|lib|include> [name]` - create new file in the project workspace
55
53
  - `--config` - config file
56
- - `--version` - compiler version
57
- - `--addon` - addon name
58
- - `--dev` - search for dev build
54
+ - `--name` - plugin name
55
+ - `--version` - plugin version
56
+ - `--author` - plugin author
57
+ - `--lib` - library name
58
+ - `--include` - include list separated by a comma
59
+ - `--overwrite` - overwrite file if it already exists
60
+ - `amxpack i` - alias to `install` command
61
+ - `amxpack n` - alias to `new` command
62
+ - `amxpack b` - alias to `build` command
63
+ - `amxpack c` - alias to `compile` command
@@ -1,27 +1,27 @@
1
- export declare enum AMXPCMessageType {
2
- Echo = "echo",
3
- Error = "error",
4
- Warning = "warning",
5
- FatalError = "fatal error"
6
- }
7
- interface IMessage {
8
- filename?: string;
9
- startLine?: number;
10
- endLine?: number;
11
- code?: number;
12
- type: AMXPCMessageType;
13
- text: string;
14
- }
15
- interface IParseOutputResult {
16
- messages: IMessage[];
17
- aborted: boolean;
18
- error: boolean;
19
- }
20
- interface ICompileResult {
21
- output: IParseOutputResult;
22
- plugin: string;
23
- error?: string;
24
- success: boolean;
25
- }
26
- declare function compile(params: any): Promise<ICompileResult>;
27
- export default compile;
1
+ export declare enum AMXPCMessageType {
2
+ Echo = "echo",
3
+ Error = "error",
4
+ Warning = "warning",
5
+ FatalError = "fatal error"
6
+ }
7
+ interface IMessage {
8
+ filename?: string;
9
+ startLine?: number;
10
+ endLine?: number;
11
+ code?: number;
12
+ type: AMXPCMessageType;
13
+ text: string;
14
+ }
15
+ interface IParseOutputResult {
16
+ messages: IMessage[];
17
+ aborted: boolean;
18
+ error: boolean;
19
+ }
20
+ interface ICompileResult {
21
+ output: IParseOutputResult;
22
+ plugin: string;
23
+ error?: string;
24
+ success: boolean;
25
+ }
26
+ declare function compile(params: any): Promise<ICompileResult>;
27
+ export default compile;
@@ -1,122 +1,122 @@
1
- "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.AMXPCMessageType = void 0;
16
- var path_1 = __importDefault(require("path"));
17
- var child_process_1 = __importDefault(require("child_process"));
18
- var mkdirp_1 = __importDefault(require("mkdirp"));
19
- var accumulator_1 = __importDefault(require("../utils/accumulator"));
20
- var PLUGIN_EXT = 'amxx';
21
- var AMXPCMessageType;
22
- (function (AMXPCMessageType) {
23
- AMXPCMessageType["Echo"] = "echo";
24
- AMXPCMessageType["Error"] = "error";
25
- AMXPCMessageType["Warning"] = "warning";
26
- AMXPCMessageType["FatalError"] = "fatal error";
27
- })(AMXPCMessageType = exports.AMXPCMessageType || (exports.AMXPCMessageType = {}));
28
- var MessageRegExp = {
29
- filename: /([a-zA-Z0-9.\-_/:\\\s]+)/,
30
- line: /\(([0-9]+)(?:\s--\s([0-9]+))?\)/,
31
- type: /((?:fatal\s)?error|warning)/,
32
- code: /([0-9]+)/,
33
- text: /(.*)/
34
- };
35
- function buildMessageRegExp() {
36
- var filename = MessageRegExp.filename, line = MessageRegExp.line, type = MessageRegExp.type, code = MessageRegExp.code, text = MessageRegExp.text;
37
- var pattern = [
38
- filename,
39
- line,
40
- /\s:\s/,
41
- type,
42
- /\s/,
43
- code,
44
- /:\s/,
45
- text
46
- ].map(function (r) { return r.toString().slice(1, -1); }).join('');
47
- return new RegExp(pattern);
48
- }
49
- var messageRegExp = buildMessageRegExp();
50
- function parseLine(line) {
51
- var match = line.match(messageRegExp);
52
- if (!match) {
53
- return { type: AMXPCMessageType.Echo, text: line };
54
- }
55
- var filename = match[1], startLine = match[2], endLine = match[3], type = match[4], code = match[5], text = match[6];
56
- return {
57
- filename: filename,
58
- startLine: +startLine,
59
- endLine: endLine ? +endLine : -1,
60
- type: type,
61
- code: +code,
62
- text: text
63
- };
64
- }
65
- function isAbortedEcho(line) {
66
- return line.startsWith('Compilation aborted.')
67
- || line.startsWith('Could not locate output file');
68
- }
69
- function parseOutput(output) {
70
- var result = { messages: [], aborted: false, error: false };
71
- output.split('\n').forEach(function (line) {
72
- var message = parseLine(line);
73
- var type = message.type;
74
- if (type === AMXPCMessageType.Error || type === AMXPCMessageType.FatalError) {
75
- result.error = true;
76
- }
77
- else if (type === AMXPCMessageType.Echo && isAbortedEcho(line)) {
78
- result.error = true;
79
- result.aborted = true;
80
- }
81
- result.messages.push(message);
82
- });
83
- return result;
84
- }
85
- function formatArgs(params, outPath) {
86
- var includeArgs = params.includeDir instanceof Array
87
- ? params.includeDir.map(function (dir) { return "-i".concat(dir); })
88
- : ["-i".concat(params.includeDir)];
89
- return __spreadArray([params.path, "-o".concat(outPath)], includeArgs, true);
90
- }
91
- function compile(params) {
92
- var parsedPath = path_1.default.parse(params.path);
93
- var fileName = "".concat(parsedPath.name, ".").concat(PLUGIN_EXT);
94
- var dest = path_1.default.join(params.dest, fileName);
95
- mkdirp_1.default.sync(params.dest);
96
- return new Promise(function (resolve) {
97
- var output = (0, accumulator_1.default)();
98
- var done = function (error) {
99
- var outputData = output();
100
- var parsedOutput = parseOutput(outputData);
101
- var errorMessage = error && error.message;
102
- if (!errorMessage && parsedOutput.error) {
103
- errorMessage = 'Compilation error';
104
- }
105
- resolve({
106
- error: errorMessage,
107
- plugin: fileName,
108
- success: !errorMessage,
109
- output: parsedOutput
110
- });
111
- };
112
- var compilerProcess = child_process_1.default.spawn(params.compiler, formatArgs(params, dest), {
113
- env: process.env,
114
- cwd: path_1.default.parse(params.compiler).dir
115
- });
116
- compilerProcess.on('error', done);
117
- compilerProcess.on('close', done);
118
- compilerProcess.stdout.on('data', output);
119
- compilerProcess.stderr.on('data', function (data) { return console.error(data); });
120
- });
121
- }
122
- exports.default = compile;
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AMXPCMessageType = void 0;
16
+ var path_1 = __importDefault(require("path"));
17
+ var child_process_1 = __importDefault(require("child_process"));
18
+ var mkdirp_1 = __importDefault(require("mkdirp"));
19
+ var accumulator_1 = __importDefault(require("../utils/accumulator"));
20
+ var PLUGIN_EXT = 'amxx';
21
+ var AMXPCMessageType;
22
+ (function (AMXPCMessageType) {
23
+ AMXPCMessageType["Echo"] = "echo";
24
+ AMXPCMessageType["Error"] = "error";
25
+ AMXPCMessageType["Warning"] = "warning";
26
+ AMXPCMessageType["FatalError"] = "fatal error";
27
+ })(AMXPCMessageType = exports.AMXPCMessageType || (exports.AMXPCMessageType = {}));
28
+ var MessageRegExp = {
29
+ filename: /([a-zA-Z0-9.\-_/:\\\s]+)/,
30
+ line: /\(([0-9]+)(?:\s--\s([0-9]+))?\)/,
31
+ type: /((?:fatal\s)?error|warning)/,
32
+ code: /([0-9]+)/,
33
+ text: /(.*)/
34
+ };
35
+ function buildMessageRegExp() {
36
+ var filename = MessageRegExp.filename, line = MessageRegExp.line, type = MessageRegExp.type, code = MessageRegExp.code, text = MessageRegExp.text;
37
+ var pattern = [
38
+ filename,
39
+ line,
40
+ /\s:\s/,
41
+ type,
42
+ /\s/,
43
+ code,
44
+ /:\s/,
45
+ text
46
+ ].map(function (r) { return r.toString().slice(1, -1); }).join('');
47
+ return new RegExp(pattern);
48
+ }
49
+ var messageRegExp = buildMessageRegExp();
50
+ function parseLine(line) {
51
+ var match = line.match(messageRegExp);
52
+ if (!match) {
53
+ return { type: AMXPCMessageType.Echo, text: line };
54
+ }
55
+ var filename = match[1], startLine = match[2], endLine = match[3], type = match[4], code = match[5], text = match[6];
56
+ return {
57
+ filename: filename,
58
+ startLine: +startLine,
59
+ endLine: endLine ? +endLine : -1,
60
+ type: type,
61
+ code: +code,
62
+ text: text
63
+ };
64
+ }
65
+ function isAbortedEcho(line) {
66
+ return line.startsWith('Compilation aborted.')
67
+ || line.startsWith('Could not locate output file');
68
+ }
69
+ function parseOutput(output) {
70
+ var result = { messages: [], aborted: false, error: false };
71
+ output.split('\n').forEach(function (line) {
72
+ var message = parseLine(line);
73
+ var type = message.type;
74
+ if (type === AMXPCMessageType.Error || type === AMXPCMessageType.FatalError) {
75
+ result.error = true;
76
+ }
77
+ else if (type === AMXPCMessageType.Echo && isAbortedEcho(line)) {
78
+ result.error = true;
79
+ result.aborted = true;
80
+ }
81
+ result.messages.push(message);
82
+ });
83
+ return result;
84
+ }
85
+ function formatArgs(params, outPath) {
86
+ var includeArgs = params.includeDir instanceof Array
87
+ ? params.includeDir.map(function (dir) { return "-i".concat(dir); })
88
+ : ["-i".concat(params.includeDir)];
89
+ return __spreadArray([params.path, "-o".concat(outPath)], includeArgs, true);
90
+ }
91
+ function compile(params) {
92
+ var parsedPath = path_1.default.parse(params.path);
93
+ var fileName = "".concat(parsedPath.name, ".").concat(PLUGIN_EXT);
94
+ var dest = path_1.default.join(params.dest, fileName);
95
+ mkdirp_1.default.sync(params.dest);
96
+ return new Promise(function (resolve) {
97
+ var output = (0, accumulator_1.default)();
98
+ var done = function (error) {
99
+ var outputData = output();
100
+ var parsedOutput = parseOutput(outputData);
101
+ var errorMessage = error && error.message;
102
+ if (!errorMessage && parsedOutput.error) {
103
+ errorMessage = 'Compilation error';
104
+ }
105
+ resolve({
106
+ error: errorMessage,
107
+ plugin: fileName,
108
+ success: !errorMessage,
109
+ output: parsedOutput
110
+ });
111
+ };
112
+ var compilerProcess = child_process_1.default.spawn(params.compiler, formatArgs(params, dest), {
113
+ env: process.env,
114
+ cwd: path_1.default.parse(params.compiler).dir
115
+ });
116
+ compilerProcess.on('error', done);
117
+ compilerProcess.on('close', done);
118
+ compilerProcess.stdout.on('data', output);
119
+ compilerProcess.stderr.on('data', function (data) { return console.error(data); });
120
+ });
121
+ }
122
+ exports.default = compile;
@@ -1,22 +1,21 @@
1
- import { IAmxxBuilderConfig } from './types';
2
- export default class AmxxBuilder {
3
- private logger;
4
- private config;
5
- constructor(config: IAmxxBuilderConfig);
6
- build(): Promise<void>;
7
- watch(): Promise<void>;
8
- buildSrc(): Promise<void>;
9
- buildInclude(): Promise<void>;
10
- buildAssets(): Promise<void>;
11
- watchSrc(): Promise<void>;
12
- watchInclude(): Promise<void>;
13
- watchAssets(): Promise<void>;
14
- updatePlugin(filePath: string): Promise<void>;
15
- updateScript(filePath: string): Promise<void>;
16
- updateAsset(filePath: string): Promise<void>;
17
- updateInclude(filePath: string): Promise<void>;
18
- findPlugins(pattern: string): Promise<string[]>;
19
- compilePlugin(filePath: string): Promise<void>;
20
- private buildDir;
21
- private watchDir;
22
- }
1
+ import { IProjectConfig } from '../types';
2
+ export default class AmxxBuilder {
3
+ private config;
4
+ constructor(config: IProjectConfig);
5
+ build(): Promise<void>;
6
+ watch(): Promise<void>;
7
+ buildSrc(): Promise<void>;
8
+ buildInclude(): Promise<void>;
9
+ buildAssets(): Promise<void>;
10
+ watchSrc(): Promise<void>;
11
+ watchInclude(): Promise<void>;
12
+ watchAssets(): Promise<void>;
13
+ updatePlugin(filePath: string): Promise<void>;
14
+ updateScript(filePath: string): Promise<void>;
15
+ updateAsset(filePath: string): Promise<void>;
16
+ updateInclude(filePath: string): Promise<void>;
17
+ findPlugins(pattern: string): Promise<string[]>;
18
+ compilePlugin(filePath: string): Promise<void>;
19
+ private buildDir;
20
+ private watchDir;
21
+ }