amxxpack 1.4.2 → 1.4.4

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
@@ -60,6 +60,7 @@ npm install -g amxxpack
60
60
  - `--lib` - library name
61
61
  - `--include` - include list separated by a comma
62
62
  - `--overwrite` - overwrite the file if it already exists
63
+ - `amxxpack cache clean` - clean amxxpack cache
63
64
  - `amxpack i` - alias to `install` command
64
65
  - `amxpack g` - alias to `generate` command
65
66
  - `amxpack b` - alias to `build` command
@@ -13,7 +13,7 @@ export default class AmxxBuilder {
13
13
  buildInclude(): Promise<void>;
14
14
  buildAssets(): Promise<void>;
15
15
  watchScripts(compileOptions: CompileOptions): Promise<void>;
16
- watchInclude(): Promise<void>;
16
+ watchInclude(compileOptions: CompileOptions): Promise<void>;
17
17
  watchAssets(): Promise<void>;
18
18
  updatePlugin(srcDir: string, srcFile: string, compileOptions: CompileOptions): Promise<boolean>;
19
19
  updateScript(srcDir: string, srcFile: string): Promise<void>;
@@ -131,7 +131,7 @@ var AmxxBuilder = /** @class */ (function () {
131
131
  case 0: return [4 /*yield*/, this.watchAssets()];
132
132
  case 1:
133
133
  _a.sent();
134
- return [4 /*yield*/, this.watchInclude()];
134
+ return [4 /*yield*/, this.watchInclude(compileOptions)];
135
135
  case 2:
136
136
  _a.sent();
137
137
  return [4 /*yield*/, this.watchScripts(compileOptions)];
@@ -300,12 +300,26 @@ var AmxxBuilder = /** @class */ (function () {
300
300
  });
301
301
  });
302
302
  };
303
- AmxxBuilder.prototype.watchInclude = function () {
303
+ AmxxBuilder.prototype.watchInclude = function (compileOptions) {
304
304
  return __awaiter(this, void 0, void 0, function () {
305
305
  var _this = this;
306
306
  return __generator(this, function (_a) {
307
307
  switch (_a.label) {
308
- case 0: return [4 /*yield*/, this.watchDir(this.projectConfig.input.include, constants_1.INCLUDE_PATH_PATTERN, function (filePath) { return _this.updateInclude(filePath); })];
308
+ case 0: return [4 /*yield*/, this.watchDir(this.projectConfig.input.include, constants_1.INCLUDE_PATH_PATTERN, function (filePath) { return __awaiter(_this, void 0, void 0, function () {
309
+ return __generator(this, function (_a) {
310
+ switch (_a.label) {
311
+ case 0: return [4 /*yield*/, this.updateInclude(filePath)];
312
+ case 1:
313
+ _a.sent();
314
+ if (!!compileOptions.noCache) return [3 /*break*/, 3];
315
+ return [4 /*yield*/, this.pluginCache.updateProjectIncludes(this.projectConfig.input.include)];
316
+ case 2:
317
+ _a.sent();
318
+ _a.label = 3;
319
+ case 3: return [2 /*return*/];
320
+ }
321
+ });
322
+ }); })];
309
323
  case 1:
310
324
  _a.sent();
311
325
  return [2 /*return*/];
@@ -587,8 +601,9 @@ var AmxxBuilder = /** @class */ (function () {
587
601
  });
588
602
  };
589
603
  AmxxBuilder.prototype.initPluginCache = function () {
590
- this.pluginCache = new plugins_cache_1.default();
604
+ this.pluginCache = new plugins_cache_1.default(process.cwd());
591
605
  this.pluginCache.load(config_1.default.cacheFile);
606
+ this.pluginCache.updateProjectIncludes(this.projectConfig.input.include);
592
607
  };
593
608
  AmxxBuilder.prototype.execPathFilter = function (filePath, filter) {
594
609
  return globule_1.default.isMatch(filter, filePath, {
@@ -1,16 +1,20 @@
1
1
  export declare enum CacheValueType {
2
2
  Source = "src",
3
- Compiled = "compiled"
3
+ Compiled = "compiled",
4
+ Includes = "Includes"
4
5
  }
5
6
  export default class PluginsCache {
7
+ projectDir: string;
6
8
  private cache;
7
- constructor();
9
+ constructor(projectDir: string);
8
10
  save(cacheFile: string): void;
9
11
  load(cacheFile: string): void;
10
12
  isPluginUpdated(srcPath: string, pluginPath: string): Promise<boolean>;
11
13
  updatePlugin(srcPath: string, pluginPath: string): Promise<void>;
14
+ updateProjectIncludes(includeDirs: string[]): Promise<void>;
12
15
  deletePlugin(srcPath: string): Promise<void>;
13
16
  getFileCacheKey(filePath: string, type: CacheValueType): string;
17
+ private createProjectIncludesHash;
14
18
  private createHash;
15
19
  private createFileHash;
16
20
  }
@@ -41,15 +41,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.CacheValueType = void 0;
43
43
  var fs_1 = __importDefault(require("fs"));
44
+ var path_1 = __importDefault(require("path"));
44
45
  var crypto_1 = __importDefault(require("crypto"));
45
46
  var node_cache_1 = __importDefault(require("node-cache"));
47
+ var create_dir_hash_1 = __importDefault(require("../utils/create-dir-hash"));
46
48
  var CacheValueType;
47
49
  (function (CacheValueType) {
48
50
  CacheValueType["Source"] = "src";
49
51
  CacheValueType["Compiled"] = "compiled";
52
+ CacheValueType["Includes"] = "Includes";
50
53
  })(CacheValueType = exports.CacheValueType || (exports.CacheValueType = {}));
51
54
  var PluginsCache = /** @class */ (function () {
52
- function PluginsCache() {
55
+ function PluginsCache(projectDir) {
56
+ this.projectDir = projectDir;
53
57
  this.cache = new node_cache_1.default();
54
58
  }
55
59
  PluginsCache.prototype.save = function (cacheFile) {
@@ -64,7 +68,7 @@ var PluginsCache = /** @class */ (function () {
64
68
  };
65
69
  PluginsCache.prototype.isPluginUpdated = function (srcPath, pluginPath) {
66
70
  return __awaiter(this, void 0, void 0, function () {
67
- var srcCachedHash, srcHash, pluginHash, pluginCachedHash;
71
+ var srcCachedHash, srcHash, pluginHash, pluginCachedHash, projectIncludeHash, includesHash;
68
72
  return __generator(this, function (_a) {
69
73
  switch (_a.label) {
70
74
  case 0:
@@ -88,6 +92,11 @@ var PluginsCache = /** @class */ (function () {
88
92
  if (pluginHash !== pluginCachedHash) {
89
93
  return [2 /*return*/, false];
90
94
  }
95
+ projectIncludeHash = this.cache.get(this.getFileCacheKey('.', CacheValueType.Includes));
96
+ includesHash = this.cache.get(this.getFileCacheKey(srcPath, CacheValueType.Includes));
97
+ if (projectIncludeHash !== includesHash) {
98
+ return [2 /*return*/, false];
99
+ }
91
100
  return [2 /*return*/, true];
92
101
  }
93
102
  });
@@ -95,7 +104,7 @@ var PluginsCache = /** @class */ (function () {
95
104
  };
96
105
  PluginsCache.prototype.updatePlugin = function (srcPath, pluginPath) {
97
106
  return __awaiter(this, void 0, void 0, function () {
98
- var srcHash, pluginHash;
107
+ var srcHash, pluginHash, includeHash;
99
108
  return __generator(this, function (_a) {
100
109
  switch (_a.label) {
101
110
  case 0: return [4 /*yield*/, this.createFileHash(srcPath)];
@@ -106,6 +115,22 @@ var PluginsCache = /** @class */ (function () {
106
115
  case 2:
107
116
  pluginHash = _a.sent();
108
117
  this.cache.set(this.getFileCacheKey(srcPath, CacheValueType.Compiled), pluginHash);
118
+ includeHash = this.cache.get(this.getFileCacheKey('.', CacheValueType.Includes));
119
+ this.cache.set(this.getFileCacheKey(srcPath, CacheValueType.Includes), includeHash);
120
+ return [2 /*return*/];
121
+ }
122
+ });
123
+ });
124
+ };
125
+ PluginsCache.prototype.updateProjectIncludes = function (includeDirs) {
126
+ return __awaiter(this, void 0, void 0, function () {
127
+ var includeHash;
128
+ return __generator(this, function (_a) {
129
+ switch (_a.label) {
130
+ case 0: return [4 /*yield*/, this.createProjectIncludesHash(includeDirs)];
131
+ case 1:
132
+ includeHash = _a.sent();
133
+ this.cache.set(this.getFileCacheKey('.', CacheValueType.Includes), includeHash);
109
134
  return [2 /*return*/];
110
135
  }
111
136
  });
@@ -116,12 +141,26 @@ var PluginsCache = /** @class */ (function () {
116
141
  return __generator(this, function (_a) {
117
142
  this.cache.del(this.getFileCacheKey(srcPath, CacheValueType.Source));
118
143
  this.cache.del(this.getFileCacheKey(srcPath, CacheValueType.Compiled));
144
+ this.cache.del(this.getFileCacheKey(srcPath, CacheValueType.Includes));
119
145
  return [2 /*return*/];
120
146
  });
121
147
  });
122
148
  };
123
149
  PluginsCache.prototype.getFileCacheKey = function (filePath, type) {
124
- return "".concat(filePath, "?").concat(type);
150
+ return this.createHash("".concat(this.projectDir, ":").concat(filePath, "?").concat(type));
151
+ };
152
+ PluginsCache.prototype.createProjectIncludesHash = function (includeDirs) {
153
+ return __awaiter(this, void 0, void 0, function () {
154
+ var includeHash;
155
+ return __generator(this, function (_a) {
156
+ switch (_a.label) {
157
+ case 0: return [4 /*yield*/, (0, create_dir_hash_1.default)(includeDirs, function (p) { return !p.info.isFile() || path_1.default.parse(p.info.name).ext === '.inc'; })];
158
+ case 1:
159
+ includeHash = _a.sent();
160
+ return [2 /*return*/, includeHash];
161
+ }
162
+ });
163
+ });
125
164
  };
126
165
  PluginsCache.prototype.createHash = function (data) {
127
166
  var hashSum = crypto_1.default.createHash('sha256');
@@ -21,6 +21,7 @@ declare class Controller {
21
21
  overwrite: boolean;
22
22
  include: string[];
23
23
  }): Promise<any>;
24
+ cleanCache(): Promise<void>;
24
25
  }
25
26
  declare const _default: Controller;
26
27
  export default _default;
@@ -40,6 +40,7 @@ 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"));
43
44
  var lodash_1 = require("lodash");
44
45
  var builder_1 = __importDefault(require("../builder"));
45
46
  var compiler_1 = __importDefault(require("../downloaders/compiler"));
@@ -48,6 +49,7 @@ var project_creator_1 = __importDefault(require("./services/project-creator"));
48
49
  var template_builder_1 = __importDefault(require("./services/template-builder"));
49
50
  var project_config_1 = __importDefault(require("../project-config"));
50
51
  var logger_1 = __importDefault(require("../logger/logger"));
52
+ var config_1 = __importDefault(require("../config"));
51
53
  var Controller = /** @class */ (function () {
52
54
  function Controller() {
53
55
  }
@@ -173,7 +175,9 @@ var Controller = /** @class */ (function () {
173
175
  return [4 /*yield*/, (0, thirdparty_1.default)({
174
176
  name: dependency.name,
175
177
  url: dependency.url,
176
- dir: projectConfig.thirdparty.dir
178
+ dir: projectConfig.thirdparty.dir,
179
+ strip: dependency.strip,
180
+ filter: dependency.filter
177
181
  })];
178
182
  case 4:
179
183
  _b.sent();
@@ -240,6 +244,15 @@ var Controller = /** @class */ (function () {
240
244
  });
241
245
  });
242
246
  };
247
+ Controller.prototype.cleanCache = function () {
248
+ return __awaiter(this, void 0, void 0, function () {
249
+ return __generator(this, function (_a) {
250
+ fs_1.default.promises.rm(config_1.default.cacheFile);
251
+ fs_1.default.promises.rm(config_1.default.downloadDir, { recursive: true, force: true });
252
+ return [2 /*return*/];
253
+ });
254
+ });
255
+ };
243
256
  return Controller;
244
257
  }());
245
258
  exports.default = new Controller();
@@ -140,6 +140,18 @@ program
140
140
  }
141
141
  });
142
142
  }); });
143
+ program
144
+ .command('cache clean')
145
+ .action(function () { return __awaiter(void 0, void 0, void 0, function () {
146
+ return __generator(this, function (_a) {
147
+ switch (_a.label) {
148
+ case 0: return [4 /*yield*/, controller_1.default.cleanCache()];
149
+ case 1:
150
+ _a.sent();
151
+ return [2 /*return*/];
152
+ }
153
+ });
154
+ }); });
143
155
  program
144
156
  .command('generate')
145
157
  .alias('new')
@@ -42,6 +42,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var path_1 = __importDefault(require("path"));
43
43
  var mkdirp_1 = __importDefault(require("mkdirp"));
44
44
  var decompress_1 = __importDefault(require("decompress"));
45
+ var globule_1 = __importDefault(require("globule"));
45
46
  var download_1 = __importDefault(require("../../utils/download"));
46
47
  var config_1 = __importDefault(require("../../config"));
47
48
  function downloadThirdparty(options) {
@@ -58,7 +59,14 @@ function downloadThirdparty(options) {
58
59
  return [4 /*yield*/, (0, mkdirp_1.default)(outDir)];
59
60
  case 2:
60
61
  _a.sent();
61
- return [4 /*yield*/, (0, decompress_1.default)(filePath, outDir)];
62
+ return [4 /*yield*/, (0, decompress_1.default)(filePath, outDir, {
63
+ strip: options.strip,
64
+ filter: options.filter && (function (file) { return globule_1.default.isMatch(options.filter, file.path, {
65
+ dot: true,
66
+ nocase: true,
67
+ matchBase: true
68
+ }); })
69
+ })];
62
70
  case 3:
63
71
  _a.sent();
64
72
  return [2 /*return*/];
@@ -2,4 +2,6 @@ export interface IDownloadThirdpartyOptions {
2
2
  name: string;
3
3
  url: string;
4
4
  dir: string;
5
+ strip: number;
6
+ filter?: string | string[];
5
7
  }
@@ -42,7 +42,8 @@ function resolve(overrides, projectDir) {
42
42
  dir: resolvePath(config.compiler.dir),
43
43
  },
44
44
  thirdparty: {
45
- dir: resolvePath(config.thirdparty.dir)
45
+ dir: resolvePath(config.thirdparty.dir),
46
+ dependencies: (0, lodash_1.map)(config.thirdparty.dependencies, function (dependency) { return (__assign(__assign({}, dependency), { strip: dependency.strip || 0 })); })
46
47
  }
47
48
  });
48
49
  return resolvedConfig;
@@ -3,6 +3,12 @@ export interface IAssetInput {
3
3
  dest?: string;
4
4
  filter?: string | string[];
5
5
  }
6
+ export interface IDependency {
7
+ name: string;
8
+ url: string;
9
+ strip?: number;
10
+ filter?: string | string[];
11
+ }
6
12
  export interface IProjectConfig {
7
13
  input: {
8
14
  scripts: null | string | string[];
@@ -25,10 +31,7 @@ export interface IProjectConfig {
25
31
  };
26
32
  thirdparty: {
27
33
  dir: string | null;
28
- dependencies: {
29
- name: string;
30
- url: string;
31
- }[];
34
+ dependencies: IDependency[];
32
35
  };
33
36
  include: null | string[];
34
37
  rules: {
@@ -67,5 +70,8 @@ export interface IResolvedProjectConfig extends IProjectConfig {
67
70
  };
68
71
  thirdparty: IProjectConfig['thirdparty'] & {
69
72
  dir: string;
73
+ dependencies: (IDependency & {
74
+ strip: number;
75
+ })[];
70
76
  };
71
77
  }
@@ -0,0 +1,9 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import fs from 'fs';
4
+ import crypto from 'crypto';
5
+ declare function createDirHash(dirs: string[], filterFn?: (p: {
6
+ dir: string;
7
+ info: fs.Dirent;
8
+ }) => boolean, initialHash?: crypto.Hash): Promise<string>;
9
+ export default createDirHash;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var fs_1 = __importDefault(require("fs"));
43
+ var path_1 = __importDefault(require("path"));
44
+ var crypto_1 = __importDefault(require("crypto"));
45
+ function createDirHash(dirs, filterFn, initialHash) {
46
+ if (filterFn === void 0) { filterFn = null; }
47
+ if (initialHash === void 0) { initialHash = null; }
48
+ return __awaiter(this, void 0, void 0, function () {
49
+ var hashSum, _i, dirs_1, dir, items, _a, items_1, item, fullPath, fileStat, data;
50
+ return __generator(this, function (_b) {
51
+ switch (_b.label) {
52
+ case 0:
53
+ hashSum = initialHash || crypto_1.default.createHash('sha256');
54
+ _i = 0, dirs_1 = dirs;
55
+ _b.label = 1;
56
+ case 1:
57
+ if (!(_i < dirs_1.length)) return [3 /*break*/, 8];
58
+ dir = dirs_1[_i];
59
+ if (!fs_1.default.existsSync(dir)) {
60
+ return [3 /*break*/, 7];
61
+ }
62
+ return [4 /*yield*/, fs_1.default.promises.readdir(dir, { withFileTypes: true })];
63
+ case 2:
64
+ items = _b.sent();
65
+ _a = 0, items_1 = items;
66
+ _b.label = 3;
67
+ case 3:
68
+ if (!(_a < items_1.length)) return [3 /*break*/, 7];
69
+ item = items_1[_a];
70
+ fullPath = path_1.default.join(dir, item.name);
71
+ if (filterFn && !filterFn({ dir: dir, info: item })) {
72
+ return [3 /*break*/, 6];
73
+ }
74
+ if (!item.isFile()) return [3 /*break*/, 5];
75
+ return [4 /*yield*/, fs_1.default.promises.stat(fullPath)];
76
+ case 4:
77
+ fileStat = _b.sent();
78
+ data = "".concat(fullPath, ":").concat(fileStat.size, ":").concat(fileStat.mtimeMs);
79
+ hashSum.update(data);
80
+ return [3 /*break*/, 6];
81
+ case 5:
82
+ if (item.isDirectory()) {
83
+ createDirHash([fullPath], filterFn, hashSum);
84
+ }
85
+ _b.label = 6;
86
+ case 6:
87
+ _a++;
88
+ return [3 /*break*/, 3];
89
+ case 7:
90
+ _i++;
91
+ return [3 /*break*/, 1];
92
+ case 8: return [2 /*return*/, hashSum.digest('hex')];
93
+ }
94
+ });
95
+ });
96
+ }
97
+ exports.default = createDirHash;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "amxxpack",
3
3
  "description": "AMXXPack",
4
4
  "author": "Hedgehog Fog",
5
- "version": "1.4.2",
5
+ "version": "1.4.4",
6
6
  "license": "MIT",
7
7
  "main": "lib/builder/index.js",
8
8
  "types": "lib/builder/index.d.ts",