node-pluginsmanager 3.4.1 → 3.5.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.
@@ -30,6 +30,7 @@ const gitInstall_1 = __importDefault(require("./cmd/git/gitInstall"));
30
30
  const gitUpdate_1 = __importDefault(require("./cmd/git/gitUpdate"));
31
31
  // npm
32
32
  const npmInstall_1 = __importDefault(require("./cmd/npm/npmInstall"));
33
+ const npmBuild_1 = __importDefault(require("./cmd/npm/npmBuild"));
33
34
  const npmUpdate_1 = __importDefault(require("./cmd/npm/npmUpdate"));
34
35
  // consts
35
36
  const DEFAULT_PLUGINS_DIRECTORY = (0, node_path_1.join)((0, node_os_1.homedir)(), "node-pluginsmanager-plugins");
@@ -284,7 +285,10 @@ class PluginsManager extends node_events_1.default {
284
285
  }).then((directory) => {
285
286
  // download plugin
286
287
  return Promise.resolve().then(() => {
287
- return (0, gitInstall_1.default)(directory, user, repo);
288
+ this._logger?.("info", "Downloading plugin...", false, repo);
289
+ return (0, gitInstall_1.default)(directory, user, repo).then(() => {
290
+ this._logger?.("success", "Download success", false, repo);
291
+ });
288
292
  // check if plugin directory is created
289
293
  }).then(() => {
290
294
  return (0, isDirectory_1.default)(directory).then((isPluginADirectory) => {
@@ -306,25 +310,51 @@ class PluginsManager extends node_events_1.default {
306
310
  return JSON.parse(content);
307
311
  });
308
312
  }).then((packageData) => {
309
- const entryPoint = (0, node_path_1.join)(directory, packageData.main);
313
+ // check if the plugin has a valid name
314
+ if ("string" !== typeof packageData.name || "" === packageData.name.trim()) {
315
+ throw new Error("\"" + repo + "\" plugin has no valid name");
316
+ }
317
+ const pluginName = packageData.name;
310
318
  // check if the plugin has a valid entry point
311
- return (0, isFile_1.default)(entryPoint).then((hasPluginEntryPoint) => {
312
- if (!hasPluginEntryPoint) {
313
- throw new Error("\"" + repo + "\" plugin has no valid entry point");
319
+ if ("string" !== typeof packageData.main || "" === packageData.main.trim()) {
320
+ throw new Error("\"" + repo + "\" plugin has no valid entry point");
321
+ }
322
+ const entryPoint = (0, node_path_1.join)(directory, packageData.main);
323
+ // check if the plugin is builded (build it if needed)
324
+ return (0, isFile_1.default)(entryPoint).then((isEntryPointAFile) => {
325
+ // already built, no need to build it
326
+ if (isEntryPointAFile) {
327
+ return Promise.resolve();
314
328
  }
315
- // check if the plugin is builded
316
- // @TODO : "build installed plugin" feature to be implemented
317
- }).then(() => {
318
- return (0, isFile_1.default)(entryPoint).then((isEntryPointAFile) => {
319
- if (!isEntryPointAFile) {
320
- throw new Error("\"" + repo + "\" plugin entry point is not builded");
321
- }
329
+ // check if the plugin has a build script
330
+ if ("object" !== typeof packageData.scripts || null === packageData.scripts || 0 >= Object.keys(packageData.scripts).length) {
331
+ throw new Error("\"" + repo + "\" plugin has no scripts registered");
332
+ }
333
+ const scripts = packageData.scripts;
334
+ if ("string" !== typeof scripts.build || "" === scripts.build.trim()) {
335
+ throw new Error("\"" + repo + "\" plugin has no build script registered");
336
+ }
337
+ this._logger?.("info", "Installing dev dependencies...", false, pluginName);
338
+ // install plugin with dependencies
339
+ return (0, npmInstall_1.default)(directory, true).then(() => {
340
+ this._logger?.("success", "Plugin installed successfully", false, pluginName);
341
+ this._logger?.("info", "Building plugin...", false, pluginName);
342
+ return (0, npmBuild_1.default)(directory);
343
+ // remove dev dependencies
344
+ }).then(() => {
345
+ this._logger?.("debug", "Removing dev dependencies...", false, pluginName);
346
+ return (0, rmdirp_1.default)((0, node_path_1.join)(directory, "node_modules")).then(() => {
347
+ this._logger?.("success", "Dev dependencies removed successfully", false, pluginName);
348
+ });
322
349
  });
323
350
  }).then(() => {
324
351
  if ("object" !== typeof packageData.dependencies || null === packageData.dependencies || 0 >= Object.keys(packageData.dependencies).length) {
325
352
  return Promise.resolve();
326
353
  }
327
- return (0, npmInstall_1.default)(directory);
354
+ this._logger?.("debug", "Installing dependencies...", false, pluginName);
355
+ return (0, npmInstall_1.default)(directory).then(() => {
356
+ this._logger?.("success", "Dependencies installed successfully", false, pluginName);
357
+ });
328
358
  });
329
359
  });
330
360
  // create plugin
@@ -0,0 +1 @@
1
+ export default function npmBuild(directory: string): Promise<void>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ // deps
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.default = npmBuild;
8
+ // locals
9
+ const cmd_1 = __importDefault(require("../cmd"));
10
+ // module
11
+ function npmBuild(directory) {
12
+ return (0, cmd_1.default)(directory, "npm", ["run", "build"]);
13
+ }
@@ -1 +1 @@
1
- export default function npmInstall(directory: string): Promise<void>;
1
+ export default function npmInstall(directory: string, isBuildMode?: boolean): Promise<void>;
@@ -8,10 +8,9 @@ exports.default = npmInstall;
8
8
  // locals
9
9
  const cmd_1 = __importDefault(require("../cmd"));
10
10
  // module
11
- function npmInstall(directory) {
11
+ function npmInstall(directory, isBuildMode = false) {
12
12
  return (0, cmd_1.default)(directory, "npm", [
13
13
  "install",
14
- "--omit=dev",
15
- "--no-optional"
14
+ ...(isBuildMode ? ["--no-optional"] : ["--omit=dev", "--no-optional"])
16
15
  ]);
17
16
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "node-pluginsmanager",
4
- "version": "3.4.1",
4
+ "version": "3.5.1",
5
5
  "description": "A plugins manager.",
6
6
 
7
7
  "type": "commonjs",