amxxpack 0.0.7 → 0.1.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.
package/README.md CHANGED
@@ -32,7 +32,7 @@ npm install -g amxxpack
32
32
  - Execute `npm init -y` command to init the package
33
33
  - Execute `npm install amxxpack --save-dev` command to install `amxxpack` locally
34
34
  - Execute `npx amxxpack init` command to create new config
35
- - Extract the **Amx Mod X** compiler to the `./compiler` dir of the project (content of `scripting` folder).
35
+ - Execute `npx amxxpack fetch-compiler` to download latest compiler release
36
36
  - Use `npx amxxpack build` command to build the project
37
37
  - Adding build scripts *(optional)*
38
38
 
@@ -45,9 +45,14 @@ npm install -g amxxpack
45
45
  ```
46
46
 
47
47
  ## 📋 Commands
48
- - `amxxpack init` init config for a new project
49
- - `amxxpack build` command to build the project
50
- - `--watch` flag to watch changes
51
- - `--config` config file
52
- - `amxxpack compile <path|glob>` to compile specific plugin in the project
53
- - `--config` config file
48
+ - `amxxpack init` - init config for a new project
49
+ - `amxxpack build` - command to build the project
50
+ - `--watch` - flag to watch changes
51
+ - `--config` - config file
52
+ - `amxxpack compile <path|glob>` - compile specific plugin in the project
53
+ - `--config` - config file
54
+ - `amxxpack fetch-compiler` - fetch amxmodx compiler
55
+ - `--config` - config file
56
+ - `--version` - compiler version
57
+ - `--addon` - addon name
58
+ - `--dev` - search for dev build
@@ -5,6 +5,12 @@ declare class Controller {
5
5
  init(projectDir: string): Promise<void>;
6
6
  compile(scriptPath: string, configPath: string): Promise<void>;
7
7
  build(configPath: string, watch: boolean): Promise<void>;
8
+ fetchCompiler({ configPath, version, dev, addons }: {
9
+ configPath: string;
10
+ version: string;
11
+ dev: boolean;
12
+ addons: string[];
13
+ }): Promise<void>;
8
14
  }
9
15
  declare const _default: Controller;
10
16
  export default _default;
@@ -42,8 +42,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var path_1 = __importDefault(require("path"));
43
43
  var fs_1 = __importDefault(require("fs"));
44
44
  var mkdirp_1 = __importDefault(require("mkdirp"));
45
- // import childProcess from 'child_process';
46
45
  var builder_1 = __importDefault(require("../builder"));
46
+ var compiler_downloader_1 = __importDefault(require("../compiler-downloader"));
47
47
  function resolveConfigPath(configPath) {
48
48
  return path_1.default.isAbsolute(configPath) ? configPath : path_1.default.join(process.cwd(), configPath);
49
49
  }
@@ -158,6 +158,24 @@ var Controller = /** @class */ (function () {
158
158
  });
159
159
  });
160
160
  };
161
+ Controller.prototype.fetchCompiler = function (_a) {
162
+ var configPath = _a.configPath, version = _a.version, dev = _a.dev, addons = _a.addons;
163
+ return __awaiter(this, void 0, void 0, function () {
164
+ var config, compilerPath;
165
+ return __generator(this, function (_b) {
166
+ switch (_b.label) {
167
+ case 0: return [4 /*yield*/, this.loadConfig(configPath)];
168
+ case 1:
169
+ config = _b.sent();
170
+ compilerPath = path_1.default.parse(config.compiler.executable).dir;
171
+ return [4 /*yield*/, (0, compiler_downloader_1.default)({ path: path_1.default.resolve(compilerPath), dists: addons, version: version, dev: dev })];
172
+ case 2:
173
+ _b.sent();
174
+ return [2 /*return*/];
175
+ }
176
+ });
177
+ });
178
+ };
161
179
  return Controller;
162
180
  }());
163
181
  exports.default = new Controller();
@@ -66,9 +66,12 @@ program
66
66
  .argument('<path>', 'Script path or glob')
67
67
  .option('--config, -c <path>', 'Config file', '.amxxpack.json')
68
68
  .action(function (str, options) { return __awaiter(void 0, void 0, void 0, function () {
69
+ var configPath;
69
70
  return __generator(this, function (_a) {
70
71
  switch (_a.label) {
71
- case 0: return [4 /*yield*/, controller_1.default.compile(str, options.C)];
72
+ case 0:
73
+ configPath = options.C;
74
+ return [4 /*yield*/, controller_1.default.compile(str, configPath)];
72
75
  case 1:
73
76
  _a.sent();
74
77
  return [2 /*return*/];
@@ -80,22 +83,36 @@ program
80
83
  .option('--watch, -w', 'Watch project')
81
84
  .option('--config, -c <path>', 'Config file', '.amxxpack.json')
82
85
  .action(function (str, options) { return __awaiter(void 0, void 0, void 0, function () {
83
- var opts;
84
- return __generator(this, function (_a) {
85
- switch (_a.label) {
86
+ var _a, configPath, watch;
87
+ return __generator(this, function (_b) {
88
+ switch (_b.label) {
86
89
  case 0:
87
- opts = options.opts();
88
- return [4 /*yield*/, controller_1.default.build(opts.C, opts.W)];
90
+ _a = options.opts(), configPath = _a.C, watch = _a.W;
91
+ return [4 /*yield*/, controller_1.default.build(configPath, watch)];
89
92
  case 1:
90
- _a.sent();
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();
91
114
  return [2 /*return*/];
92
115
  }
93
116
  });
94
117
  }); });
95
- // program
96
- // .command('create')
97
- // .argument('<name>', 'Project name')
98
- // .action(async (name: string) => {
99
- // await controller.createProject(name);
100
- // });
101
118
  exports.default = program;
@@ -0,0 +1,13 @@
1
+ export declare const DOWNLOAD_HOST = "https://www.amxmodx.org";
2
+ export declare const SCRIPTING_DIR = "addons/amxmodx/scripting/";
3
+ export declare const EXTENSIONS_IGNORE_LIST: string[];
4
+ export declare const DOWNLOAD_DIR = ".downloads";
5
+ export declare enum CompilerPlatform {
6
+ Windows = "windows",
7
+ Linux = "linux",
8
+ Mac = "mac"
9
+ }
10
+ export declare enum DistSource {
11
+ Dev = "amxxdrop",
12
+ Release = "release"
13
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DistSource = exports.CompilerPlatform = exports.DOWNLOAD_DIR = exports.EXTENSIONS_IGNORE_LIST = exports.SCRIPTING_DIR = exports.DOWNLOAD_HOST = void 0;
4
+ exports.DOWNLOAD_HOST = 'https://www.amxmodx.org';
5
+ exports.SCRIPTING_DIR = 'addons/amxmodx/scripting/';
6
+ exports.EXTENSIONS_IGNORE_LIST = ['.sma'];
7
+ exports.DOWNLOAD_DIR = '.downloads';
8
+ var CompilerPlatform;
9
+ (function (CompilerPlatform) {
10
+ CompilerPlatform["Windows"] = "windows";
11
+ CompilerPlatform["Linux"] = "linux";
12
+ CompilerPlatform["Mac"] = "mac";
13
+ })(CompilerPlatform = exports.CompilerPlatform || (exports.CompilerPlatform = {}));
14
+ var DistSource;
15
+ (function (DistSource) {
16
+ DistSource["Dev"] = "amxxdrop";
17
+ DistSource["Release"] = "release";
18
+ })(DistSource = exports.DistSource || (exports.DistSource = {}));
@@ -0,0 +1,2 @@
1
+ import { IDownloadCompilerOptions } from './types';
2
+ export default function downloadCompiler(options: IDownloadCompilerOptions): Promise<void>;
@@ -0,0 +1,173 @@
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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
58
+ var __importDefault = (this && this.__importDefault) || function (mod) {
59
+ return (mod && mod.__esModule) ? mod : { "default": mod };
60
+ };
61
+ Object.defineProperty(exports, "__esModule", { value: true });
62
+ var fs_1 = __importDefault(require("fs"));
63
+ var path_1 = __importDefault(require("path"));
64
+ var https_1 = __importDefault(require("https"));
65
+ var mkdirp_1 = __importDefault(require("mkdirp"));
66
+ var normalize_path_1 = __importDefault(require("normalize-path"));
67
+ var decompress_1 = __importDefault(require("decompress"));
68
+ var resolvers_1 = require("./resolvers");
69
+ var constants_1 = require("./constants");
70
+ function downloadDist(dist) {
71
+ return __awaiter(this, void 0, void 0, function () {
72
+ var downloadDir, fileName, filePath, file;
73
+ return __generator(this, function (_a) {
74
+ switch (_a.label) {
75
+ case 0:
76
+ downloadDir = path_1.default.join(__dirname, '../..', constants_1.DOWNLOAD_DIR);
77
+ return [4 /*yield*/, (0, mkdirp_1.default)(downloadDir)];
78
+ case 1:
79
+ _a.sent();
80
+ fileName = (0, resolvers_1.resolveFileName)(dist);
81
+ filePath = path_1.default.join(downloadDir, fileName);
82
+ file = fs_1.default.createWriteStream(filePath);
83
+ return [2 /*return*/, new Promise(function (resolve, reject) {
84
+ var source = (0, resolvers_1.resolveSource)(dist);
85
+ var url = (0, resolvers_1.resolveUrl)(source, fileName);
86
+ console.log('Fetching dist from', url, '...');
87
+ var done = function () {
88
+ file.close();
89
+ resolve({ dist: dist, path: filePath });
90
+ };
91
+ var cancel = function (err) {
92
+ fs_1.default.unlink(filePath, function () { return reject(err); });
93
+ };
94
+ var request = https_1.default.get(url, function (response) {
95
+ if (!response.statusCode || response.statusCode < 200 || response.statusCode >= 300) {
96
+ cancel(new Error("HTTP Error: ".concat(response.statusCode)));
97
+ return;
98
+ }
99
+ response.pipe(file);
100
+ });
101
+ file.on('finish', done);
102
+ request.on('error', cancel);
103
+ file.on('error', cancel);
104
+ })];
105
+ }
106
+ });
107
+ });
108
+ }
109
+ function extractDist(archivePath, outDir) {
110
+ return __awaiter(this, void 0, void 0, function () {
111
+ return __generator(this, function (_a) {
112
+ switch (_a.label) {
113
+ case 0: return [4 /*yield*/, (0, mkdirp_1.default)(outDir)];
114
+ case 1:
115
+ _a.sent();
116
+ return [4 /*yield*/, (0, decompress_1.default)(archivePath, outDir, {
117
+ map: function (file) {
118
+ var newFile = __assign({}, file);
119
+ var filePath = (0, normalize_path_1.default)(newFile.path);
120
+ if (filePath.startsWith(constants_1.SCRIPTING_DIR)) {
121
+ newFile.path = newFile.path.slice(constants_1.SCRIPTING_DIR.length);
122
+ }
123
+ return newFile;
124
+ },
125
+ filter: function (file) {
126
+ var filePath = (0, normalize_path_1.default)(file.path);
127
+ if (!filePath.startsWith(constants_1.SCRIPTING_DIR)) {
128
+ return false;
129
+ }
130
+ var ext = path_1.default.parse(file.path).ext;
131
+ return !constants_1.EXTENSIONS_IGNORE_LIST.includes(ext);
132
+ }
133
+ })];
134
+ case 2:
135
+ _a.sent();
136
+ return [2 /*return*/];
137
+ }
138
+ });
139
+ });
140
+ }
141
+ function downloadCompiler(options) {
142
+ return __awaiter(this, void 0, void 0, function () {
143
+ var version, dev, dists, compilerPath, platform, newDists, _i, newDists_1, dist, distArchive;
144
+ return __generator(this, function (_a) {
145
+ switch (_a.label) {
146
+ case 0:
147
+ version = options.version, dev = options.dev, dists = options.dists, compilerPath = options.path;
148
+ platform = (0, resolvers_1.resolvePlatform)();
149
+ newDists = __spreadArray([], dists, true);
150
+ if (!newDists.includes('base')) {
151
+ newDists.unshift('base');
152
+ }
153
+ _i = 0, newDists_1 = newDists;
154
+ _a.label = 1;
155
+ case 1:
156
+ if (!(_i < newDists_1.length)) return [3 /*break*/, 5];
157
+ dist = newDists_1[_i];
158
+ return [4 /*yield*/, downloadDist({ name: dist, version: version, platform: platform, dev: dev })];
159
+ case 2:
160
+ distArchive = _a.sent();
161
+ return [4 /*yield*/, extractDist(distArchive.path, compilerPath)];
162
+ case 3:
163
+ _a.sent();
164
+ _a.label = 4;
165
+ case 4:
166
+ _i++;
167
+ return [3 /*break*/, 1];
168
+ case 5: return [2 /*return*/];
169
+ }
170
+ });
171
+ });
172
+ }
173
+ exports.default = downloadCompiler;
@@ -0,0 +1 @@
1
+ export { default } from './downloader';
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = void 0;
7
+ // eslint-disable-next-line no-restricted-exports
8
+ var downloader_1 = require("./downloader");
9
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(downloader_1).default; } });
@@ -0,0 +1,6 @@
1
+ import { IDist } from './types';
2
+ import { CompilerPlatform } from './constants';
3
+ export declare function resolveSource({ dev, version }: IDist): string;
4
+ export declare function resolveFileName({ name: dist, version, platform }: IDist): string;
5
+ export declare function resolvePlatform(): CompilerPlatform;
6
+ export declare function resolveUrl(source: string, file: string): string;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveUrl = exports.resolvePlatform = exports.resolveFileName = exports.resolveSource = void 0;
7
+ var os_1 = __importDefault(require("os"));
8
+ var constants_1 = require("./constants");
9
+ function resolveSource(_a) {
10
+ var dev = _a.dev, version = _a.version;
11
+ var urlPath = [
12
+ dev ? constants_1.DistSource.Dev : constants_1.DistSource.Release
13
+ ];
14
+ if (dev) {
15
+ urlPath.push(version.split('.').slice(0, 2).join('.'));
16
+ }
17
+ return urlPath.join('/');
18
+ }
19
+ exports.resolveSource = resolveSource;
20
+ function resolveFileName(_a) {
21
+ var dist = _a.name, version = _a.version, platform = _a.platform;
22
+ var ext = platform === 'linux' ? '.tar.gz' : '.zip';
23
+ return "amxmodx-".concat(version, "-").concat(dist, "-").concat(platform).concat(ext);
24
+ }
25
+ exports.resolveFileName = resolveFileName;
26
+ function resolvePlatform() {
27
+ var platform = os_1.default.platform();
28
+ switch (platform) {
29
+ case 'win32': return constants_1.CompilerPlatform.Windows;
30
+ case 'linux': return constants_1.CompilerPlatform.Linux;
31
+ case 'darwin': return constants_1.CompilerPlatform.Mac;
32
+ }
33
+ throw new Error("Unable to resolve platform for ".concat(platform));
34
+ }
35
+ exports.resolvePlatform = resolvePlatform;
36
+ function resolveUrl(source, file) {
37
+ return "".concat(constants_1.DOWNLOAD_HOST, "/").concat(source, "/").concat(file);
38
+ }
39
+ exports.resolveUrl = resolveUrl;
@@ -0,0 +1,16 @@
1
+ export interface IDist {
2
+ name: string;
3
+ version: string;
4
+ platform: string;
5
+ dev: boolean;
6
+ }
7
+ export interface IDistFile {
8
+ dist: IDist;
9
+ path: string;
10
+ }
11
+ export interface IDownloadCompilerOptions {
12
+ path: string;
13
+ version: string;
14
+ dev: boolean;
15
+ dists: string[];
16
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "amxxpack",
3
3
  "description": "AMXXPack",
4
4
  "author": "Hedgehog Fog",
5
- "version": "0.0.7",
5
+ "version": "0.1.1",
6
6
  "license": "MIT",
7
7
  "main": "lib/builder/index.js",
8
8
  "types": "lib/builder/index.d.ts",
@@ -37,6 +37,7 @@
37
37
  "chokidar": "^3.5.3",
38
38
  "colors": "^1.4.0",
39
39
  "commander": "^9.0.0",
40
+ "decompress": "^4.2.1",
40
41
  "glob": "^7.2.0",
41
42
  "glob-promise": "^4.2.2",
42
43
  "lodash": "^4.17.21",
@@ -47,6 +48,7 @@
47
48
  "@types/chokidar": "^2.1.3",
48
49
  "@types/colors": "^1.2.1",
49
50
  "@types/commander": "^2.12.2",
51
+ "@types/decompress": "^4.2.4",
50
52
  "@types/lodash": "^4.14.178",
51
53
  "@types/mkdirp": "^1.0.2",
52
54
  "@types/normalize-path": "^3.0.0",