amxxpack 1.0.1 → 1.1.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 CHANGED
@@ -28,11 +28,11 @@ npm install -g amxxpack
28
28
 
29
29
  ## ▶ Quick start
30
30
  - Open a terminal inside the project directory (existing or create a new one)
31
- - Execute `npm install amxxpack --save-dev` command to install `amxxpack` locally
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
31
+ - Execute `npm install amxxpack -g` command to install `amxxpack` globally
32
+ - Execute `amxxpack create .` command to create new config
33
+ - Execute `amxxpack install` to download project dependencies (compiler, thirdparty etc.)
34
+ - Use `amxxpack build` command to build the project
35
+ - Use `amxxpack watch` command to build the project and watch changes
36
36
 
37
37
  ## 📋 Commands
38
38
  - `amxxpack create <name>` - create new project
@@ -150,7 +150,11 @@ var AmxxBuilder = /** @class */ (function () {
150
150
  var _this = this;
151
151
  return __generator(this, function (_a) {
152
152
  switch (_a.label) {
153
- case 0: return [4 /*yield*/, this.buildDir(this.config.input.assets, constants_1.ASSETS_PATH_PATTERN, function (filePath) { return _this.updateAsset(filePath); })];
153
+ case 0:
154
+ if (!this.config.input.assets) {
155
+ return [2 /*return*/];
156
+ }
157
+ return [4 /*yield*/, this.buildDir(this.config.input.assets, constants_1.ASSETS_PATH_PATTERN, function (filePath) { return _this.updateAsset(filePath); })];
154
158
  case 1:
155
159
  _a.sent();
156
160
  return [2 /*return*/];
@@ -189,7 +193,11 @@ var AmxxBuilder = /** @class */ (function () {
189
193
  var _this = this;
190
194
  return __generator(this, function (_a) {
191
195
  switch (_a.label) {
192
- case 0: return [4 /*yield*/, this.watchDir(this.config.input.assets, constants_1.ASSETS_PATH_PATTERN, function (filePath) { return _this.updateAsset(filePath); })];
196
+ case 0:
197
+ if (!this.config.input.assets) {
198
+ return [2 /*return*/];
199
+ }
200
+ return [4 /*yield*/, this.watchDir(this.config.input.assets, constants_1.ASSETS_PATH_PATTERN, function (filePath) { return _this.updateAsset(filePath); })];
193
201
  case 1:
194
202
  _a.sent();
195
203
  return [2 /*return*/];
@@ -218,6 +226,9 @@ var AmxxBuilder = /** @class */ (function () {
218
226
  return __generator(this, function (_a) {
219
227
  switch (_a.label) {
220
228
  case 0:
229
+ if (!this.config.output.scripts) {
230
+ return [2 /*return*/];
231
+ }
221
232
  srcPath = path_1.default.resolve(filePath);
222
233
  destPath = path_1.default.join(this.config.output.scripts, path_1.default.parse(filePath).base);
223
234
  return [4 /*yield*/, (0, mkdirp_1.default)(this.config.output.scripts)];
@@ -283,7 +294,7 @@ var AmxxBuilder = /** @class */ (function () {
283
294
  return [4 /*yield*/, (0, glob_promise_1.default)(pathPattern)];
284
295
  case 1:
285
296
  matches = _a.sent();
286
- return [2 /*return*/, matches];
297
+ return [2 /*return*/, matches.filter(function (filePath) { return path_1.default.extname(filePath) === '.sma'; })];
287
298
  }
288
299
  });
289
300
  });
@@ -318,12 +329,13 @@ var AmxxBuilder = /** @class */ (function () {
318
329
  case 2:
319
330
  result = _a.sent();
320
331
  result.output.messages.forEach(function (message) {
321
- var startLine = message.startLine, type = message.type, code = message.code, text = message.text;
332
+ var startLine = message.startLine, type = message.type, code = message.code, text = message.text, filename = message.filename;
333
+ var relativeFilePath = path_1.default.relative(process.cwd(), filename);
322
334
  if (type === amxxpc_1.AMXPCMessageType.Error || type === amxxpc_1.AMXPCMessageType.FatalError) {
323
- logger_1.default.error("".concat((0, normalize_path_1.default)(relateiveSrcPath), "(").concat(startLine, ")"), type, code, ':', text);
335
+ logger_1.default.error("".concat((0, normalize_path_1.default)(relativeFilePath), "(").concat(startLine, ")"), type, code, ':', text);
324
336
  }
325
337
  else if (type === amxxpc_1.AMXPCMessageType.Warning) {
326
- logger_1.default.warn("".concat((0, normalize_path_1.default)(relateiveSrcPath), "(").concat(startLine, ")"), type, code, ':', text);
338
+ logger_1.default.warn("".concat((0, normalize_path_1.default)(relativeFilePath), "(").concat(startLine, ")"), type, code, ':', text);
327
339
  }
328
340
  else if (type === amxxpc_1.AMXPCMessageType.Echo) {
329
341
  logger_1.default.debug(text);
@@ -366,7 +378,7 @@ var AmxxBuilder = /** @class */ (function () {
366
378
  var pathPattern, watcher, updateFn;
367
379
  return __generator(this, function (_a) {
368
380
  pathPattern = path_1.default.join(baseDir, pattern);
369
- watcher = chokidar_1.default.watch(pathPattern, { ignoreInitial: true });
381
+ watcher = chokidar_1.default.watch(pathPattern, { ignoreInitial: true, interval: 300 });
370
382
  updateFn = function (filePath) { return cb(filePath).catch(function (err) { return logger_1.default.error(err.message); }); };
371
383
  watcher.on('add', updateFn);
372
384
  watcher.on('change', updateFn);
@@ -97,8 +97,7 @@ var Controller = /** @class */ (function () {
97
97
  };
98
98
  Controller.prototype.compile = function (scriptPath, configPath) {
99
99
  return __awaiter(this, void 0, void 0, function () {
100
- var builder, matches;
101
- var _this = this;
100
+ var builder, matches, _i, matches_1, filePath, srcPath;
102
101
  return __generator(this, function (_a) {
103
102
  switch (_a.label) {
104
103
  case 0: return [4 /*yield*/, this.createBuilder(configPath)];
@@ -107,20 +106,20 @@ var Controller = /** @class */ (function () {
107
106
  return [4 /*yield*/, builder.findPlugins(scriptPath)];
108
107
  case 2:
109
108
  matches = _a.sent();
110
- matches.map(function (filePath) { return __awaiter(_this, void 0, void 0, function () {
111
- var srcPath;
112
- return __generator(this, function (_a) {
113
- switch (_a.label) {
114
- case 0:
115
- srcPath = path_1.default.resolve(filePath);
116
- return [4 /*yield*/, builder.compilePlugin(srcPath)];
117
- case 1:
118
- _a.sent();
119
- return [2 /*return*/];
120
- }
121
- });
122
- }); });
123
- return [2 /*return*/];
109
+ _i = 0, matches_1 = matches;
110
+ _a.label = 3;
111
+ case 3:
112
+ if (!(_i < matches_1.length)) return [3 /*break*/, 6];
113
+ filePath = matches_1[_i];
114
+ srcPath = path_1.default.resolve(filePath);
115
+ return [4 /*yield*/, builder.compilePlugin(srcPath)];
116
+ case 4:
117
+ _a.sent();
118
+ _a.label = 5;
119
+ case 5:
120
+ _i++;
121
+ return [3 /*break*/, 3];
122
+ case 6: return [2 /*return*/];
124
123
  }
125
124
  });
126
125
  });
@@ -7,7 +7,7 @@ declare class ProjectCreator {
7
7
  isCurrentDir: boolean;
8
8
  constructor(options?: IProjectOptions);
9
9
  createProject(): Promise<void>;
10
- createPackage(): Promise<void>;
10
+ updatePackage(): Promise<void>;
11
11
  createConfig(): Promise<void>;
12
12
  createDirectories(): Promise<void>;
13
13
  installDependencies(): Promise<void>;
@@ -98,7 +98,7 @@ var ProjectCreator = /** @class */ (function () {
98
98
  case 2:
99
99
  _a.sent();
100
100
  if (!!this.options.nonpm) return [3 /*break*/, 4];
101
- return [4 /*yield*/, this.createPackage()];
101
+ return [4 /*yield*/, this.updatePackage()];
102
102
  case 3:
103
103
  _a.sent();
104
104
  _a.label = 4;
@@ -109,14 +109,14 @@ var ProjectCreator = /** @class */ (function () {
109
109
  _a.sent();
110
110
  _a.label = 6;
111
111
  case 6:
112
- if (!this.isNpmPackageInitialized()) return [3 /*break*/, 8];
113
- return [4 /*yield*/, this.installDependencies()];
112
+ if (!this.isGitInitialized()) return [3 /*break*/, 8];
113
+ return [4 /*yield*/, this.updateGitignore()];
114
114
  case 7:
115
115
  _a.sent();
116
116
  _a.label = 8;
117
117
  case 8:
118
- if (!this.isGitInitialized()) return [3 /*break*/, 10];
119
- return [4 /*yield*/, this.updateGitignore()];
118
+ if (!this.isNpmPackageInitialized()) return [3 /*break*/, 10];
119
+ return [4 /*yield*/, this.installDependencies()];
120
120
  case 9:
121
121
  _a.sent();
122
122
  _a.label = 10;
@@ -127,11 +127,11 @@ var ProjectCreator = /** @class */ (function () {
127
127
  });
128
128
  });
129
129
  };
130
- ProjectCreator.prototype.createPackage = function () {
130
+ ProjectCreator.prototype.updatePackage = function () {
131
131
  return __awaiter(this, void 0, void 0, function () {
132
- var packagePath, packageData;
133
- return __generator(this, function (_a) {
134
- switch (_a.label) {
132
+ var packagePath, packageData, _a, _b, _c, _d, _e;
133
+ return __generator(this, function (_f) {
134
+ switch (_f.label) {
135
135
  case 0:
136
136
  logger_1.default.info('📦 Initializing npm package...');
137
137
  packagePath = path_1.default.join(this.projectDir, 'package.json');
@@ -139,16 +139,34 @@ var ProjectCreator = /** @class */ (function () {
139
139
  name: this.options.name,
140
140
  version: (0, lodash_1.get)(this.options, 'version', '0.1.0'),
141
141
  author: (0, lodash_1.get)(this.options, 'author', 'AMXXPack'),
142
- description: (0, lodash_1.get)(this.options, 'description', 'This project was generated by AMXXPack CLI'),
142
+ description: (0, lodash_1.get)(this.options, 'description', 'This project was generated by AMXXPack CLI')
143
+ };
144
+ if (!fs_1.default.existsSync(packagePath)) return [3 /*break*/, 4];
145
+ _f.label = 1;
146
+ case 1:
147
+ _f.trys.push([1, 3, , 4]);
148
+ _a = lodash_1.merge;
149
+ _b = [packageData];
150
+ _d = (_c = JSON).parse;
151
+ return [4 /*yield*/, fs_1.default.promises.readFile(packagePath, 'utf8')];
152
+ case 2:
153
+ _a.apply(void 0, _b.concat([_d.apply(_c, [_f.sent()])]));
154
+ return [3 /*break*/, 4];
155
+ case 3:
156
+ _e = _f.sent();
157
+ logger_1.default.error('Cannot read package.json file');
158
+ return [3 /*break*/, 4];
159
+ case 4:
160
+ (0, lodash_1.merge)(packageData, {
143
161
  scripts: {
144
162
  build: 'amxxpack build',
145
163
  watch: 'amxxpack build --watch',
146
164
  postinstall: 'amxxpack install'
147
165
  }
148
- };
166
+ });
149
167
  return [4 /*yield*/, fs_1.default.promises.writeFile(packagePath, JSON.stringify(packageData, null, 2))];
150
- case 1:
151
- _a.sent();
168
+ case 5:
169
+ _f.sent();
152
170
  return [2 /*return*/];
153
171
  }
154
172
  });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "amxxpack",
3
3
  "description": "AMXXPack",
4
4
  "author": "Hedgehog Fog",
5
- "version": "1.0.1",
5
+ "version": "1.1.0",
6
6
  "license": "MIT",
7
7
  "main": "lib/builder/index.js",
8
8
  "types": "lib/builder/index.d.ts",