@learnpack/learnpack 2.0.21 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -21,7 +21,7 @@ $ npm install -g @learnpack/learnpack
21
21
  $ learnpack COMMAND
22
22
  running command...
23
23
  $ learnpack (-v|--version|version)
24
- @learnpack/learnpack/2.0.21 win32-x64 node-v16.14.0
24
+ @learnpack/learnpack/2.1.0 win32-x64 node-v16.14.0
25
25
  $ learnpack --help [COMMAND]
26
26
  USAGE
27
27
  $ learnpack COMMAND
@@ -74,7 +74,7 @@ DESCRIPTION
74
74
  12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)
75
75
  ```
76
76
 
77
- _See code: [src\commands\audit.ts](https://github.com/learnpack/learnpack-cli/blob/v2.0.21/src\commands\audit.ts)_
77
+ _See code: [src\commands\audit.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.0/src\commands\audit.ts)_
78
78
 
79
79
  ## `learnpack clean`
80
80
 
@@ -89,7 +89,7 @@ DESCRIPTION
89
89
  Extra documentation goes here
90
90
  ```
91
91
 
92
- _See code: [src\commands\clean.ts](https://github.com/learnpack/learnpack-cli/blob/v2.0.21/src\commands\clean.ts)_
92
+ _See code: [src\commands\clean.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.0/src\commands\clean.ts)_
93
93
 
94
94
  ## `learnpack download [PACKAGE]`
95
95
 
@@ -107,7 +107,7 @@ DESCRIPTION
107
107
  Extra documentation goes here
108
108
  ```
109
109
 
110
- _See code: [src\commands\download.ts](https://github.com/learnpack/learnpack-cli/blob/v2.0.21/src\commands\download.ts)_
110
+ _See code: [src\commands\download.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.0/src\commands\download.ts)_
111
111
 
112
112
  ## `learnpack help [COMMAND]`
113
113
 
@@ -138,7 +138,7 @@ OPTIONS
138
138
  -h, --grading show CLI help
139
139
  ```
140
140
 
141
- _See code: [src\commands\init.ts](https://github.com/learnpack/learnpack-cli/blob/v2.0.21/src\commands\init.ts)_
141
+ _See code: [src\commands\init.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.0/src\commands\init.ts)_
142
142
 
143
143
  ## `learnpack login [PACKAGE]`
144
144
 
@@ -156,7 +156,7 @@ DESCRIPTION
156
156
  Extra documentation goes here
157
157
  ```
158
158
 
159
- _See code: [src\commands\login.ts](https://github.com/learnpack/learnpack-cli/blob/v2.0.21/src\commands\login.ts)_
159
+ _See code: [src\commands\login.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.0/src\commands\login.ts)_
160
160
 
161
161
  ## `learnpack logout [PACKAGE]`
162
162
 
@@ -174,7 +174,7 @@ DESCRIPTION
174
174
  Extra documentation goes here
175
175
  ```
176
176
 
177
- _See code: [src\commands\logout.ts](https://github.com/learnpack/learnpack-cli/blob/v2.0.21/src\commands\logout.ts)_
177
+ _See code: [src\commands\logout.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.0/src\commands\logout.ts)_
178
178
 
179
179
  ## `learnpack plugins`
180
180
 
@@ -309,7 +309,7 @@ DESCRIPTION
309
309
  Extra documentation goes here
310
310
  ```
311
311
 
312
- _See code: [src\commands\publish.ts](https://github.com/learnpack/learnpack-cli/blob/v2.0.21/src\commands\publish.ts)_
312
+ _See code: [src\commands\publish.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.0/src\commands\publish.ts)_
313
313
 
314
314
  ## `learnpack start`
315
315
 
@@ -330,7 +330,7 @@ OPTIONS
330
330
  -w, --watch Watch for file changes
331
331
  ```
332
332
 
333
- _See code: [src\commands\start.ts](https://github.com/learnpack/learnpack-cli/blob/v2.0.21/src\commands\start.ts)_
333
+ _See code: [src\commands\start.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.0/src\commands\start.ts)_
334
334
 
335
335
  ## `learnpack test [EXERCISESLUG]`
336
336
 
@@ -344,5 +344,5 @@ ARGUMENTS
344
344
  EXERCISESLUG The name of the exercise to test
345
345
  ```
346
346
 
347
- _See code: [src\commands\test.ts](https://github.com/learnpack/learnpack-cli/blob/v2.0.21/src\commands\test.ts)_
347
+ _See code: [src\commands\test.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.0/src\commands\test.ts)_
348
348
  <!-- commandsstop -->
@@ -76,7 +76,7 @@ class InitComand extends BaseCommand_1.default {
76
76
  .replace(/[^\w-]+/g, "") });
77
77
  cli_ux_1.default.action.start("Initializing package");
78
78
  const languages = ["en", "es"];
79
- const templatesDir = path.resolve(__dirname, "../utils/templates/" + choices.grading || "no-grading");
79
+ const templatesDir = path.resolve(__dirname, "../../src/utils/templates/" + choices.grading || "no-grading");
80
80
  if (!fs.existsSync(templatesDir))
81
81
  throw errors_1.ValidationError(`Template ${templatesDir} does not exists`);
82
82
  await fs.copySync(templatesDir, "./");
@@ -89,7 +89,7 @@ class InitComand extends BaseCommand_1.default {
89
89
  fs.removeSync(`./${readmeFilename}.ejs`);
90
90
  });
91
91
  if (!fs.existsSync("./.gitignore"))
92
- fs.copyFile(path.resolve(__dirname, "../utils/templates/gitignore.txt"), "./.gitignore");
92
+ fs.copyFile(path.resolve(__dirname, "../../src/utils/templates/gitignore.txt"), "./.gitignore");
93
93
  fs.writeFileSync("./learn.json", JSON.stringify(packageInfo, null, 2));
94
94
  cli_ux_1.default.action.stop();
95
95
  console_1.default.success(`😋 Package initialized successfully`);
@@ -259,7 +259,7 @@ exports.default = async ({ grading, mode, disableGrading, version, }) => {
259
259
  if (configObj.config && !configObj.config.exercisesPath)
260
260
  throw errors_1.ValidationError("No exercises directory to watch: " + configObj.config.exercisesPath);
261
261
  this.buildIndex();
262
- watcher_1.default(((_a = configObj === null || configObj === void 0 ? void 0 : configObj.config) === null || _a === void 0 ? void 0 : _a.exercisesPath) || "")
262
+ watcher_1.default(((_a = configObj === null || configObj === void 0 ? void 0 : configObj.config) === null || _a === void 0 ? void 0 : _a.exercisesPath) || "", onChange)
263
263
  .then(( /* eventname, filename */) => {
264
264
  console_1.default.debug("Changes detected on your exercises");
265
265
  this.buildIndex();
@@ -123,7 +123,7 @@ const onPull = (callback) => {
123
123
  loadFile(options.path || "");
124
124
  }
125
125
  catch (_a) {
126
- console_1.default.debug("No previeues queue file, waiting for it to be created...");
126
+ console_1.default.debug("No previoues queue file, waiting for it to be created...");
127
127
  }
128
128
  if (!watcher) {
129
129
  console_1.default.debug(`Watching ${options.path}`);
@@ -1,2 +1,2 @@
1
- declare const _default: (path: string) => Promise<unknown>;
1
+ declare const _default: (path: string, reloadSocket: () => void) => Promise<unknown>;
2
2
  export default _default;
@@ -2,18 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const chokidar = require("chokidar");
4
4
  const debounce = require("debounce");
5
- exports.default = (path) => new Promise((resolve /* , reject */) => {
5
+ exports.default = (path, reloadSocket) => new Promise((resolve /* , reject */) => {
6
6
  const watcher = chokidar.watch(path, {
7
7
  // TODO: This watcher is not ready yet
8
8
  // ignored: (_path: string, _stats: any) => {
9
9
  // return new RegExp(_path)
10
10
  // },
11
- persistent: true,
12
- depth: 1,
13
11
  ignoreInitial: true,
14
12
  });
15
13
  const onChange = (eventname, _filename) => {
16
14
  resolve(eventname /* , filename */);
15
+ reloadSocket();
17
16
  };
18
17
  watcher.on("all", debounce(onChange, 500, true));
19
18
  // watcher.on('all', onChange)
@@ -1 +1 @@
1
- {"version":"2.0.21","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":"[standalone, gitpod]","options":["standalone","gitpod"]},"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.0","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":"[standalone, gitpod]","options":["standalone","gitpod"]},"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.0.21",
4
+ "version": "2.1.0",
5
5
  "author": "Alejandro Sanchez @alesanchezr",
6
6
  "bin": {
7
7
  "learnpack": "bin/run"
@@ -1,172 +1,172 @@
1
- import { flags } from "@oclif/command";
2
- import BaseCommand from "../utils/BaseCommand";
3
-
4
- // eslint-disable-next-line
5
- import * as fs from "fs-extra";
6
- import * as prompts from "prompts";
7
- import cli from "cli-ux";
8
- import * as eta from "eta";
9
-
10
- import Console from "../utils/console";
11
- import { ValidationError } from "../utils/errors";
12
- import defaults from "../managers/config/defaults";
13
-
14
- import * as path from "path";
15
-
16
- class InitComand extends BaseCommand {
17
- static description =
18
- "Create a new learning package: Book, Tutorial or Exercise";
19
-
20
- static flags = {
21
- ...BaseCommand.flags,
22
- grading: flags.help({ char: "h" }),
23
- };
24
-
25
- async run() {
26
- const { flags } = this.parse(InitComand);
27
-
28
- // if the folder/file .learn or .breathecode aleady exists
29
- await alreadyInitialized();
30
-
31
- const choices = await prompts([
32
- {
33
- type: "select",
34
- name: "grading",
35
- message: "Is the auto-grading going to be isolated or incremental?",
36
- choices: [
37
- {
38
- title: "Incremental: Build on top of each other like a tutorial",
39
- value: "incremental",
40
- },
41
- { title: "Isolated: Small separated exercises", value: "isolated" },
42
- {
43
- title: "No grading: No feedback or testing whatsoever",
44
- value: null,
45
- },
46
- ],
47
- },
48
- {
49
- type: "text",
50
- name: "title",
51
- initial: "My Interactive Tutorial",
52
- message: "Title for your tutorial? Press enter to leave as it is",
53
- },
54
- {
55
- type: "text",
56
- name: "description",
57
- initial: "",
58
- message: "Description for your tutorial? Press enter to leave blank",
59
- },
60
- {
61
- type: "select",
62
- name: "difficulty",
63
- message: "How difficulty will be to complete the tutorial?",
64
- choices: [
65
- { title: "Begginer (no previous experience)", value: "beginner" },
66
- { title: "Easy (just a bit of experience required)", value: "easy" },
67
- {
68
- title: "Intermediate (you need experience)",
69
- value: "intermediate",
70
- },
71
- { title: "Hard (master the topic)", value: "hard" },
72
- ],
73
- },
74
- {
75
- type: "text",
76
- name: "duration",
77
- initial: "1",
78
- message: "How many hours avg it takes to complete (number)?",
79
- validate: (value: string) => {
80
- const n = Math.floor(Number(value));
81
- return (
82
- n !== Number.POSITIVE_INFINITY && String(n) === value && n >= 0
83
- );
84
- },
85
- },
86
- ]);
87
-
88
- const packageInfo = {
89
- ...defaults.config,
90
- grading: choices.grading,
91
- difficulty: choices.difficulty,
92
- duration: parseInt(choices.duration),
93
- description: choices.description,
94
- title: choices.title,
95
- slug: choices.title
96
- .toLowerCase()
97
- .replace(/ /g, "-")
98
- .replace(/[^\w-]+/g, ""),
99
- };
100
-
101
- cli.action.start("Initializing package");
102
-
103
- const languages = ["en", "es"];
104
-
105
- const templatesDir = path.resolve(
106
- __dirname,
107
- "../utils/templates/" + choices.grading || "no-grading"
108
- );
109
- if (!fs.existsSync(templatesDir))
110
- throw ValidationError(`Template ${templatesDir} does not exists`);
111
- await fs.copySync(templatesDir, "./");
112
-
113
- // Creating README files
114
- // eslint-disable-next-line
115
- languages.forEach((language) => {
116
- const readmeFilename = `README${language !== "en" ? `.${language}` : ""}`;
117
- fs.writeFileSync(
118
- `./${readmeFilename}.md`,
119
- eta.render(
120
- fs.readFileSync(
121
- path.resolve(__dirname, `${templatesDir}/${readmeFilename}.ejs`),
122
- "utf-8"
123
- ),
124
- packageInfo
125
- )
126
- );
127
- if (fs.existsSync(`./${readmeFilename}.ejs`))
128
- fs.removeSync(`./${readmeFilename}.ejs`);
129
- });
130
-
131
- if (!fs.existsSync("./.gitignore"))
132
- fs.copyFile(
133
- path.resolve(__dirname, "../utils/templates/gitignore.txt"),
134
- "./.gitignore"
135
- );
136
- fs.writeFileSync("./learn.json", JSON.stringify(packageInfo, null, 2));
137
-
138
- cli.action.stop();
139
- Console.success(`😋 Package initialized successfully`);
140
- Console.help(
141
- `Start the exercises by running the following command on your terminal: $ learnpack start`
142
- );
143
- }
144
- }
145
-
146
- const alreadyInitialized = () =>
147
- new Promise((resolve, reject) => {
148
- fs.readdir("./", function (err: any, files: any) {
149
- files = files.filter((f: any) =>
150
- [".learn", "learn.json", "bc.json", ".breathecode"].includes(f)
151
- );
152
- if (err) {
153
- reject(ValidationError(err.message));
154
- throw ValidationError(err.message);
155
- } else if (files.length > 0) {
156
- reject(
157
- ValidationError(
158
- "It seems the package is already initialized because we've found the following files: " +
159
- files.join(",")
160
- )
161
- );
162
- throw ValidationError(
163
- "It seems the package is already initialized because we've found the following files: " +
164
- files.join(",")
165
- );
166
- }
167
-
168
- resolve(false);
169
- });
170
- });
171
-
172
- export default InitComand;
1
+ import { flags } from "@oclif/command";
2
+ import BaseCommand from "../utils/BaseCommand";
3
+
4
+ // eslint-disable-next-line
5
+ import * as fs from "fs-extra";
6
+ import * as prompts from "prompts";
7
+ import cli from "cli-ux";
8
+ import * as eta from "eta";
9
+
10
+ import Console from "../utils/console";
11
+ import { ValidationError } from "../utils/errors";
12
+ import defaults from "../managers/config/defaults";
13
+
14
+ import * as path from "path";
15
+
16
+ class InitComand extends BaseCommand {
17
+ static description =
18
+ "Create a new learning package: Book, Tutorial or Exercise";
19
+
20
+ static flags = {
21
+ ...BaseCommand.flags,
22
+ grading: flags.help({ char: "h" }),
23
+ };
24
+
25
+ async run() {
26
+ const { flags } = this.parse(InitComand);
27
+
28
+ // if the folder/file .learn or .breathecode aleady exists
29
+ await alreadyInitialized();
30
+
31
+ const choices = await prompts([
32
+ {
33
+ type: "select",
34
+ name: "grading",
35
+ message: "Is the auto-grading going to be isolated or incremental?",
36
+ choices: [
37
+ {
38
+ title: "Incremental: Build on top of each other like a tutorial",
39
+ value: "incremental",
40
+ },
41
+ { title: "Isolated: Small separated exercises", value: "isolated" },
42
+ {
43
+ title: "No grading: No feedback or testing whatsoever",
44
+ value: null,
45
+ },
46
+ ],
47
+ },
48
+ {
49
+ type: "text",
50
+ name: "title",
51
+ initial: "My Interactive Tutorial",
52
+ message: "Title for your tutorial? Press enter to leave as it is",
53
+ },
54
+ {
55
+ type: "text",
56
+ name: "description",
57
+ initial: "",
58
+ message: "Description for your tutorial? Press enter to leave blank",
59
+ },
60
+ {
61
+ type: "select",
62
+ name: "difficulty",
63
+ message: "How difficulty will be to complete the tutorial?",
64
+ choices: [
65
+ { title: "Begginer (no previous experience)", value: "beginner" },
66
+ { title: "Easy (just a bit of experience required)", value: "easy" },
67
+ {
68
+ title: "Intermediate (you need experience)",
69
+ value: "intermediate",
70
+ },
71
+ { title: "Hard (master the topic)", value: "hard" },
72
+ ],
73
+ },
74
+ {
75
+ type: "text",
76
+ name: "duration",
77
+ initial: "1",
78
+ message: "How many hours avg it takes to complete (number)?",
79
+ validate: (value: string) => {
80
+ const n = Math.floor(Number(value));
81
+ return (
82
+ n !== Number.POSITIVE_INFINITY && String(n) === value && n >= 0
83
+ );
84
+ },
85
+ },
86
+ ]);
87
+
88
+ const packageInfo = {
89
+ ...defaults.config,
90
+ grading: choices.grading,
91
+ difficulty: choices.difficulty,
92
+ duration: parseInt(choices.duration),
93
+ description: choices.description,
94
+ title: choices.title,
95
+ slug: choices.title
96
+ .toLowerCase()
97
+ .replace(/ /g, "-")
98
+ .replace(/[^\w-]+/g, ""),
99
+ };
100
+
101
+ cli.action.start("Initializing package");
102
+
103
+ const languages = ["en", "es"];
104
+
105
+ const templatesDir = path.resolve(
106
+ __dirname,
107
+ "../../src/utils/templates/" + choices.grading || "no-grading"
108
+ );
109
+ if (!fs.existsSync(templatesDir))
110
+ throw ValidationError(`Template ${templatesDir} does not exists`);
111
+ await fs.copySync(templatesDir, "./");
112
+
113
+ // Creating README files
114
+ // eslint-disable-next-line
115
+ languages.forEach((language) => {
116
+ const readmeFilename = `README${language !== "en" ? `.${language}` : ""}`;
117
+ fs.writeFileSync(
118
+ `./${readmeFilename}.md`,
119
+ eta.render(
120
+ fs.readFileSync(
121
+ path.resolve(__dirname, `${templatesDir}/${readmeFilename}.ejs`),
122
+ "utf-8"
123
+ ),
124
+ packageInfo
125
+ )
126
+ );
127
+ if (fs.existsSync(`./${readmeFilename}.ejs`))
128
+ fs.removeSync(`./${readmeFilename}.ejs`);
129
+ });
130
+
131
+ if (!fs.existsSync("./.gitignore"))
132
+ fs.copyFile(
133
+ path.resolve(__dirname, "../../src/utils/templates/gitignore.txt"),
134
+ "./.gitignore"
135
+ );
136
+ fs.writeFileSync("./learn.json", JSON.stringify(packageInfo, null, 2));
137
+
138
+ cli.action.stop();
139
+ Console.success(`😋 Package initialized successfully`);
140
+ Console.help(
141
+ `Start the exercises by running the following command on your terminal: $ learnpack start`
142
+ );
143
+ }
144
+ }
145
+
146
+ const alreadyInitialized = () =>
147
+ new Promise((resolve, reject) => {
148
+ fs.readdir("./", function (err: any, files: any) {
149
+ files = files.filter((f: any) =>
150
+ [".learn", "learn.json", "bc.json", ".breathecode"].includes(f)
151
+ );
152
+ if (err) {
153
+ reject(ValidationError(err.message));
154
+ throw ValidationError(err.message);
155
+ } else if (files.length > 0) {
156
+ reject(
157
+ ValidationError(
158
+ "It seems the package is already initialized because we've found the following files: " +
159
+ files.join(",")
160
+ )
161
+ );
162
+ throw ValidationError(
163
+ "It seems the package is already initialized because we've found the following files: " +
164
+ files.join(",")
165
+ );
166
+ }
167
+
168
+ resolve(false);
169
+ });
170
+ });
171
+
172
+ export default InitComand;