@learnpack/learnpack 2.1.44 → 2.1.46

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,34 +1,174 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkNotInstalledPlugins = void 0;
4
- exports.checkNotInstalledPlugins = (exercises, installedPlugins) => {
3
+ exports.checkNotInstalledDependencies = exports.checkNotInstalledPlugins = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const util_1 = require("util");
6
+ const child_process_1 = require("child_process");
7
+ const exec = util_1.promisify(child_process_1.exec);
8
+ const cli_ux_1 = require("cli-ux");
9
+ const console_1 = require("./console");
10
+ exports.checkNotInstalledPlugins = async (exercises, installedPlugins, command) => {
11
+ var e_1, _a;
12
+ console_1.default.info("Checking needed plugins...");
5
13
  const usefulExtensions = new Set(["py", "js", "jsx", "html"]);
6
14
  const foundExtensions = [];
15
+ const testingExtensions = [];
16
+ const neededPlugins = [];
17
+ let someExerciseWithOnlyTestFile = false; // I will suppose that there are not exercises with only readme and test files
18
+ // See the extensions of the files that are not tests files
7
19
  for (const e of exercises) {
8
- for (const f of e.files) {
20
+ const notReadmeFiles = e.files.filter(f => !f.name.toLowerCase().includes("readme"));
21
+ if (!someExerciseWithOnlyTestFile) {
22
+ someExerciseWithOnlyTestFile = notReadmeFiles.every(f => f.name.includes("test"));
23
+ }
24
+ for (const f of notReadmeFiles) {
25
+ // There are some courses with only test files in js and grading: incremental
26
+ // TODO: We should know in the incremental exercises which compilers are needed
9
27
  const ext = f.name.split(".").pop();
28
+ if (f.name.includes("test")) {
29
+ testingExtensions.push(ext);
30
+ continue;
31
+ }
10
32
  if (ext && usefulExtensions.has(ext) && !foundExtensions.includes(ext)) {
11
33
  foundExtensions.push(ext);
12
34
  }
13
35
  }
14
36
  }
15
- const neededPlugins = [];
16
- if (foundExtensions.length > 0) {
17
- if (foundExtensions.includes("html") && foundExtensions.includes("js")) {
18
- neededPlugins.push("@learnpack/dom");
37
+ if (foundExtensions.length === 0)
38
+ return {
39
+ needed: [],
40
+ notInstalled: [],
41
+ };
42
+ if (foundExtensions.includes("html") && foundExtensions.includes("js")) {
43
+ neededPlugins.push("@learnpack/dom");
44
+ }
45
+ if (foundExtensions.includes("html") && !foundExtensions.includes("js")) {
46
+ neededPlugins.push("@learnpack/html");
47
+ }
48
+ if (foundExtensions.includes("jsx")) {
49
+ neededPlugins.push("@learnpack/react");
50
+ }
51
+ if (foundExtensions.includes("py") || testingExtensions.includes("py")) {
52
+ neededPlugins.push("@learnpack/python");
53
+ }
54
+ if ((foundExtensions.includes("js") && !foundExtensions.includes("html")) ||
55
+ (testingExtensions.includes("js") && someExerciseWithOnlyTestFile)) {
56
+ neededPlugins.push("@learnpack/node");
57
+ }
58
+ const notInstalled = neededPlugins.filter(item => !installedPlugins.includes(item));
59
+ if (notInstalled.length > 0) {
60
+ console_1.default.error("These plugins are not installed but required: ", notInstalled);
61
+ const confirmInstall = await cli_ux_1.cli.confirm("Do you want to install the needed plugins? (y/n)");
62
+ if (confirmInstall) {
63
+ console_1.default.info("Installing the needed plugins...");
64
+ try {
65
+ for (var notInstalled_1 = tslib_1.__asyncValues(notInstalled), notInstalled_1_1; notInstalled_1_1 = await notInstalled_1.next(), !notInstalled_1_1.done;) {
66
+ const p = notInstalled_1_1.value;
67
+ await command.config.runCommand(`plugins:install`, [p]);
68
+ console_1.default.log(`Plugin ${p} installed`);
69
+ }
70
+ }
71
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
72
+ finally {
73
+ try {
74
+ if (notInstalled_1_1 && !notInstalled_1_1.done && (_a = notInstalled_1.return)) await _a.call(notInstalled_1);
75
+ }
76
+ finally { if (e_1) throw e_1.error; }
77
+ }
78
+ console_1.default.log("All needed plugins installed, please restart LearnPack to load them.");
79
+ console_1.default.info("Run: $ learnpack start");
80
+ command.exit(0);
19
81
  }
20
- if (foundExtensions.includes("html") && !foundExtensions.includes("js")) {
21
- neededPlugins.push("@learnpack/html");
82
+ else {
83
+ console_1.default.error("You need to install the plugins to complete this exercise");
84
+ console_1.default.info("To install the plugins run each of the following commands: ");
85
+ for (const p of notInstalled) {
86
+ console_1.default.log(`learnpack plugins:install ${p}`);
87
+ }
88
+ command.exit(1);
22
89
  }
23
- if (foundExtensions.includes("jsx")) {
24
- neededPlugins.push("@learnpack/react");
90
+ }
91
+ return {
92
+ needed: neededPlugins,
93
+ notInstalled,
94
+ };
95
+ };
96
+ function includesAll(baseString, elementsArray) {
97
+ return elementsArray.every(element => baseString.includes(element));
98
+ }
99
+ const installDependencies = async (deps, packageManager) => {
100
+ let command = "";
101
+ if (packageManager === "npm") {
102
+ command = `npm install -g ${deps.join(" ")}`;
103
+ }
104
+ else if (packageManager === "pip") {
105
+ command = `pip install ${deps.join(" ")}`;
106
+ }
107
+ const { stdout, stderr } = await exec(command);
108
+ if (stderr && (stderr.includes("npm ERR!") || stderr.includes("Traceback"))) {
109
+ console_1.default.error(`Error executing ${command}.`);
110
+ console_1.default.error(stderr);
111
+ return;
112
+ }
113
+ console_1.default.info(`Dependencies ${deps.join(" ")} installed...`);
114
+ return true;
115
+ };
116
+ exports.checkNotInstalledDependencies = async (neededPlugins) => {
117
+ console_1.default.info("Checking needed dependencies...");
118
+ const jsPluginsDependencies = [
119
+ "jest@29.7.0",
120
+ "jest-environment-jsdom@29.7.0",
121
+ ];
122
+ const pyPluginsDependencies = ["pytest==6.2.5", "pytest-testdox", "mock"];
123
+ const npmLsCommand = "npm ls jest jest-environment-jsdom -g";
124
+ let pytestNeeded = false;
125
+ let jestNeeded = false;
126
+ if (neededPlugins.includes("@learnpack/dom") ||
127
+ neededPlugins.includes("@learnpack/html") ||
128
+ neededPlugins.includes("@learnpack/react") ||
129
+ neededPlugins.includes("@learnpack/node")) {
130
+ jestNeeded = true;
131
+ }
132
+ if ("@learnpack/python" in neededPlugins) {
133
+ pytestNeeded = true;
134
+ }
135
+ if (jestNeeded) {
136
+ const { stdout, stderr } = await exec("npm ls jest jest-environment-jsdom -g");
137
+ if (stderr) {
138
+ console_1.default.error(`Error executing ${npmLsCommand}. Use debug for more info`);
139
+ console_1.default.debug(stderr);
140
+ return false;
25
141
  }
26
- if (foundExtensions.includes("py")) {
27
- neededPlugins.push("@learnpack/python");
142
+ if (includesAll(stdout, jsPluginsDependencies))
143
+ return true;
144
+ console_1.default.error("The jest dependencies are not installed");
145
+ const confirmInstall = await cli_ux_1.cli.confirm("Do you want to install the needed dependencies? (y/n)");
146
+ if (!confirmInstall) {
147
+ console_1.default.error(`The exercises can't be tested without the following dependencies: ${jsPluginsDependencies.join(", ")}`);
148
+ console_1.default.info(`Please install them and try again. Run the following command to install them: \nnpm install -g ${jsPluginsDependencies.join(" ")}`);
149
+ return false;
150
+ }
151
+ console_1.default.log("Installing jest dependencies...");
152
+ await installDependencies(jsPluginsDependencies, "npm");
153
+ }
154
+ if (pytestNeeded) {
155
+ const { stdout, stderr } = await exec("pip list");
156
+ if (stderr) {
157
+ console_1.default.error(`Error executing pip list. Use debug for more info`);
158
+ console_1.default.debug(stderr);
159
+ return;
28
160
  }
29
- if (foundExtensions.includes("js")) {
30
- neededPlugins.push("@learnpack/node");
161
+ if (includesAll(stdout, pyPluginsDependencies))
162
+ return true;
163
+ console_1.default.error("The pytest dependencies are not installed");
164
+ const confirmInstall = await cli_ux_1.cli.confirm("Do you want to install the needed dependencies? (y/n)");
165
+ if (!confirmInstall) {
166
+ console_1.default.error(`The exercises can't be tested without the following dependencies: ${pyPluginsDependencies.join(", ")}`);
167
+ console_1.default.info(`Please install them and try again. Run the following command to install them: \npip install ${pyPluginsDependencies.join(" ")}`);
168
+ return false;
31
169
  }
170
+ console_1.default.log("Installing pytest dependencies...");
171
+ await installDependencies(pyPluginsDependencies, "pip");
32
172
  }
33
- return neededPlugins.filter(item => !installedPlugins.includes(item));
173
+ return true;
34
174
  };
@@ -4,7 +4,7 @@ declare const _default: {
4
4
  log: (msg: string | Array<string>, ...args: Array<any>) => void;
5
5
  error: (msg: string, ...args: Array<any>) => void;
6
6
  success: (msg: string, ...args: Array<any>) => void;
7
- info: (msg: string, ...args: Array<any>) => void;
7
+ info: (msg: any, ...args: Array<any>) => void;
8
8
  help: (msg: string) => void;
9
9
  debug(...args: Array<any>): void;
10
10
  warning: (msg: string) => void;
@@ -3,17 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const chalk = require("chalk");
4
4
  exports.default = {
5
5
  // _debug: true,
6
- _debug: process.env.DEBUG === 'true',
6
+ _debug: process.env.DEBUG === "true",
7
7
  startDebug: function () {
8
8
  this._debug = true;
9
9
  },
10
10
  log: (msg, ...args) => console.log(chalk.gray(msg), ...args),
11
- error: (msg, ...args) => console.log(chalk.red('' + msg), ...args),
12
- success: (msg, ...args) => console.log(chalk.green('' + msg), ...args),
13
- info: (msg, ...args) => console.log(chalk.blue('' + msg), ...args),
14
- help: (msg) => console.log(`${chalk.white.bold('⚠ help:')} ${chalk.white(msg)}`),
11
+ error: (msg, ...args) => console.log(chalk.red("" + msg), ...args),
12
+ success: (msg, ...args) => console.log(chalk.green("" + msg), ...args),
13
+ info: (msg, ...args) => console.log(chalk.blue("" + msg), ...args),
14
+ help: (msg) => console.log(`${chalk.white.bold("⚠ help:")} ${chalk.white(msg)}`),
15
15
  debug(...args) {
16
- this._debug && console.log(chalk.magentaBright('⚠ debug: '), args);
16
+ this._debug && console.log(chalk.magentaBright("⚠ debug: "), args);
17
17
  },
18
- warning: (msg) => console.log(`${chalk.yellow('⚠ warning:')} ${chalk.yellow(msg)}`),
18
+ warning: (msg) => console.log(`${chalk.yellow("⚠ warning:")} ${chalk.yellow(msg)}`),
19
19
  };
@@ -1 +1 @@
1
- {"version":"2.1.44","commands":{"audit":{"id":"audit","description":"learnpack audit is the command in charge of creating an auditory of the repository\n...\nlearnpack audit checks for the following information in a repository:\n 1. The configuration object has slug, repository and description. (Error)\n 2. The command learnpack clean has been run. (Error)\n 3. If a markdown or test file doesn't have any content. (Error)\n 4. The links are accessing to valid servers. (Error)\n 5. The relative images are working (If they have the shortest path to the image or if the images exists in the assets). (Error)\n 6. The external images are working (If they are pointing to a valid server). (Error)\n 7. The exercises directory names are valid. (Error)\n 8. If an exercise doesn't have a README file. (Error)\n 9. The exercises array (Of the config file) has content. (Error)\n 10. The exercses have the same translations. (Warning)\n 11. The .gitignore file exists. (Warning)\n 12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)\n","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[]},"clean":{"id":"clean","description":"Clean the configuration object\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[]},"download":{"id":"download","description":"Describe the command here\n...\nExtra documentation goes here\n","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"init":{"id":"init","description":"Create a new learning package: Book, Tutorial or Exercise","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"grading":{"name":"grading","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"login":{"id":"login","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"logout":{"id":"logout","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"publish":{"id":"publish","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"start":{"id":"start","description":"Runs a small server with all the exercise instructions","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"port":{"name":"port","type":"option","char":"p","description":"server port"},"host":{"name":"host","type":"option","char":"h","description":"server host"},"disableGrading":{"name":"disableGrading","type":"boolean","char":"D","description":"disble grading functionality","allowNo":false},"watch":{"name":"watch","type":"boolean","char":"w","description":"Watch for file changes","allowNo":false},"editor":{"name":"editor","type":"option","char":"e","description":"[preview, extension]","options":["extension","preview"]},"version":{"name":"version","type":"option","char":"v","description":"E.g: 1.0.1"},"grading":{"name":"grading","type":"option","char":"g","description":"[isolated, incremental]","options":["isolated","incremental"]},"debug":{"name":"debug","type":"boolean","char":"d","description":"debugger mode for more verbage","allowNo":false}},"args":[]},"test":{"id":"test","description":"Test exercises","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"exerciseSlug","description":"The name of the exercise to test","required":false,"hidden":false}]}}}
1
+ {"version":"2.1.46","commands":{"audit":{"id":"audit","description":"learnpack audit is the command in charge of creating an auditory of the repository\n...\nlearnpack audit checks for the following information in a repository:\n 1. The configuration object has slug, repository and description. (Error)\n 2. The command learnpack clean has been run. (Error)\n 3. If a markdown or test file doesn't have any content. (Error)\n 4. The links are accessing to valid servers. (Error)\n 5. The relative images are working (If they have the shortest path to the image or if the images exists in the assets). (Error)\n 6. The external images are working (If they are pointing to a valid server). (Error)\n 7. The exercises directory names are valid. (Error)\n 8. If an exercise doesn't have a README file. (Error)\n 9. The exercises array (Of the config file) has content. (Error)\n 10. The exercses have the same translations. (Warning)\n 11. The .gitignore file exists. (Warning)\n 12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)\n","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[]},"clean":{"id":"clean","description":"Clean the configuration object\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[]},"download":{"id":"download","description":"Describe the command here\n...\nExtra documentation goes here\n","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"init":{"id":"init","description":"Create a new learning package: Book, Tutorial or Exercise","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"grading":{"name":"grading","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"login":{"id":"login","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"logout":{"id":"logout","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"publish":{"id":"publish","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"start":{"id":"start","description":"Runs a small server with all the exercise instructions","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"port":{"name":"port","type":"option","char":"p","description":"server port"},"host":{"name":"host","type":"option","char":"h","description":"server host"},"disableGrading":{"name":"disableGrading","type":"boolean","char":"D","description":"disble grading functionality","allowNo":false},"watch":{"name":"watch","type":"boolean","char":"w","description":"Watch for file changes","allowNo":false},"editor":{"name":"editor","type":"option","char":"e","description":"[preview, extension]","options":["extension","preview"]},"version":{"name":"version","type":"option","char":"v","description":"E.g: 1.0.1"},"grading":{"name":"grading","type":"option","char":"g","description":"[isolated, incremental]","options":["isolated","incremental"]},"debug":{"name":"debug","type":"boolean","char":"d","description":"debugger mode for more verbage","allowNo":false}},"args":[]},"test":{"id":"test","description":"Test exercises","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"exerciseSlug","description":"The name of the exercise to test","required":false,"hidden":false}]}}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@learnpack/learnpack",
3
3
  "description": "Create, sell or download and take learning amazing learning packages",
4
- "version": "2.1.44",
4
+ "version": "2.1.46",
5
5
  "author": "Alejandro Sanchez @alesanchezr",
6
6
  "bin": {
7
7
  "learnpack": "bin/run"