@learnpack/learnpack 2.1.50 → 2.1.52
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +10 -10
- package/lib/commands/init.js +20 -14
- package/oclif.manifest.json +1 -1
- package/package.json +8 -1
- package/src/commands/init.ts +182 -170
- package/src/commands/start.ts +320 -320
- package/src/managers/socket.ts +250 -250
- package/src/utils/fileQueue.ts +199 -199
- package/src/utils/templates/incremental/.vscode/schema.json +121 -0
- package/src/utils/templates/incremental/.vscode/settings.json +14 -0
- package/src/utils/templates/isolated/.vscode/schema.json +122 -0
- package/src/utils/templates/isolated/.vscode/settings.json +14 -0
- package/src/utils/templates/isolated/{01-hello-world → exercises/01-hello-world}/README.es.md +26 -26
- package/src/utils/templates/isolated/{01-hello-world → exercises/01-hello-world}/README.md +26 -26
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.1.
|
24
|
+
@learnpack/learnpack/2.1.52 win32-x64 node-v20.10.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.1.
|
77
|
+
_See code: [src\commands\audit.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.52/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.1.
|
92
|
+
_See code: [src\commands\clean.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.52/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.1.
|
110
|
+
_See code: [src\commands\download.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.52/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.1.
|
141
|
+
_See code: [src\commands\init.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.52/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.1.
|
159
|
+
_See code: [src\commands\login.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.52/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.1.
|
177
|
+
_See code: [src\commands\logout.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.52/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.1.
|
312
|
+
_See code: [src\commands\publish.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.52/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.1.
|
333
|
+
_See code: [src\commands\start.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.52/src\commands\start.ts)_
|
334
334
|
|
335
335
|
## `learnpack test [EXERCISESLUG]`
|
336
336
|
|
@@ -344,7 +344,7 @@ 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.1.
|
347
|
+
_See code: [src\commands\test.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.52/src\commands\test.ts)_
|
348
348
|
<!-- commandsstop -->
|
349
349
|
|
350
350
|
> > > > > > > 0cb3e56d84c197f9d008836bb573eade212b7e57
|
package/lib/commands/init.js
CHANGED
@@ -73,32 +73,38 @@ class InitComand extends BaseCommand_1.default {
|
|
73
73
|
grading: choices.grading,
|
74
74
|
difficulty: choices.difficulty,
|
75
75
|
duration: parseInt(choices.duration),
|
76
|
-
description:
|
77
|
-
|
76
|
+
description: {
|
77
|
+
us: choices.description,
|
78
|
+
},
|
79
|
+
title: {
|
80
|
+
us: choices.title,
|
81
|
+
},
|
78
82
|
slug: choices.title
|
79
83
|
.toLowerCase()
|
80
84
|
.replace(/ /g, "-")
|
81
85
|
.replace(/[^\w-]+/g, ""),
|
82
86
|
};
|
87
|
+
const tutorialDir = `./${packageInfo.slug}`;
|
88
|
+
fs.ensureDirSync(tutorialDir); // Ensure the directory exists
|
83
89
|
cli_ux_1.default.action.start("Initializing package");
|
84
90
|
const languages = ["en", "es"];
|
85
|
-
const templatesDir = path.resolve(__dirname, "../../src/utils/templates/" + choices.grading || "no-grading");
|
91
|
+
const templatesDir = path.resolve(__dirname, "../../src/utils/templates/" + (choices.grading || "no-grading"));
|
86
92
|
if (!fs.existsSync(templatesDir))
|
87
93
|
throw errors_1.ValidationError(`Template ${templatesDir} does not exists`);
|
88
|
-
await fs.copySync(templatesDir,
|
94
|
+
await fs.copySync(templatesDir, tutorialDir);
|
89
95
|
// Creating README files
|
90
|
-
|
91
|
-
languages.forEach((language) => {
|
96
|
+
for (const language of languages) {
|
92
97
|
const readmeFilename = `README${language !== "en" ? `.${language}` : ""}`;
|
93
|
-
fs.writeFileSync(
|
94
|
-
if (fs.existsSync(
|
95
|
-
fs.removeSync(
|
96
|
-
}
|
97
|
-
if (!fs.existsSync("
|
98
|
-
fs.copyFile(path.resolve(__dirname, "../../src/utils/templates/gitignore.txt"), "
|
99
|
-
fs.writeFileSync("
|
98
|
+
fs.writeFileSync(path.join(tutorialDir, `${readmeFilename}.md`), eta.render(fs.readFileSync(path.resolve(__dirname, `${templatesDir}/${readmeFilename}.ejs`), "utf-8"), packageInfo));
|
99
|
+
if (fs.existsSync(path.join(tutorialDir, `${readmeFilename}.ejs`)))
|
100
|
+
fs.removeSync(path.join(tutorialDir, `${readmeFilename}.ejs`));
|
101
|
+
}
|
102
|
+
if (!fs.existsSync(path.join(tutorialDir, ".gitignore")))
|
103
|
+
fs.copyFile(path.resolve(__dirname, "../../src/utils/templates/gitignore.txt"), path.join(tutorialDir, ".gitignore"));
|
104
|
+
fs.writeFileSync(path.join(tutorialDir, "learn.json"), JSON.stringify(packageInfo, null, 2));
|
100
105
|
cli_ux_1.default.action.stop();
|
101
|
-
console_1.default.success(`😋 Package initialized successfully`);
|
106
|
+
console_1.default.success(`😋 Package initialized successfully in ${tutorialDir}`);
|
107
|
+
console_1.default.help(`Get inside the tutorial with the command: $ cd ${tutorialDir}`);
|
102
108
|
console_1.default.help(`Start the exercises by running the following command on your terminal: $ learnpack start`);
|
103
109
|
}
|
104
110
|
}
|
package/oclif.manifest.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":"2.1.
|
1
|
+
{"version":"2.1.52","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,8 +1,15 @@
|
|
1
1
|
{
|
2
2
|
"name": "@learnpack/learnpack",
|
3
3
|
"description": "Create, sell or download and take learning amazing learning packages",
|
4
|
-
"version": "2.1.
|
4
|
+
"version": "2.1.52",
|
5
5
|
"author": "Alejandro Sanchez @alesanchezr",
|
6
|
+
"contributors": [
|
7
|
+
{
|
8
|
+
"name": "Charly Chacón",
|
9
|
+
"email": "charlyjchaconc@gmail.com",
|
10
|
+
"url": "https://www.linkedin.com/in/charlytoc/"
|
11
|
+
}
|
12
|
+
],
|
6
13
|
"bin": {
|
7
14
|
"learnpack": "bin/run"
|
8
15
|
},
|
package/src/commands/init.ts
CHANGED
@@ -1,170 +1,182 @@
|
|
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
|
-
|
13
|
-
import * as path from "path"
|
14
|
-
|
15
|
-
class InitComand extends BaseCommand {
|
16
|
-
static description =
|
17
|
-
"Create a new learning package: Book, Tutorial or Exercise"
|
18
|
-
|
19
|
-
static flags = {
|
20
|
-
...BaseCommand.flags,
|
21
|
-
grading: flags.help({ char: "h" }),
|
22
|
-
}
|
23
|
-
|
24
|
-
async run() {
|
25
|
-
const { flags } = this.parse(InitComand)
|
26
|
-
|
27
|
-
// if the folder/file .learn or .breathecode aleady exists
|
28
|
-
await alreadyInitialized()
|
29
|
-
|
30
|
-
const choices = await prompts([
|
31
|
-
{
|
32
|
-
type: "select",
|
33
|
-
name: "grading",
|
34
|
-
message: "Is the auto-grading going to be isolated or incremental?",
|
35
|
-
choices: [
|
36
|
-
{
|
37
|
-
title: "Incremental: Build on top of each other like a tutorial",
|
38
|
-
value: "incremental",
|
39
|
-
},
|
40
|
-
{ title: "Isolated: Small separated exercises", value: "isolated" },
|
41
|
-
{
|
42
|
-
title: "No grading: No feedback or testing whatsoever",
|
43
|
-
value: null,
|
44
|
-
},
|
45
|
-
],
|
46
|
-
},
|
47
|
-
{
|
48
|
-
type: "text",
|
49
|
-
name: "title",
|
50
|
-
initial: "My Interactive Tutorial",
|
51
|
-
message: "Title for your tutorial? Press enter to leave as it is",
|
52
|
-
},
|
53
|
-
{
|
54
|
-
type: "text",
|
55
|
-
name: "description",
|
56
|
-
initial: "",
|
57
|
-
message: "Description for your tutorial? Press enter to leave blank",
|
58
|
-
},
|
59
|
-
{
|
60
|
-
type: "select",
|
61
|
-
name: "difficulty",
|
62
|
-
message: "How difficulty will be to complete the tutorial?",
|
63
|
-
choices: [
|
64
|
-
{ title: "Begginer (no previous experience)", value: "beginner" },
|
65
|
-
{ title: "Easy (just a bit of experience required)", value: "easy" },
|
66
|
-
{
|
67
|
-
title: "Intermediate (you need experience)",
|
68
|
-
value: "intermediate",
|
69
|
-
},
|
70
|
-
{ title: "Hard (master the topic)", value: "hard" },
|
71
|
-
],
|
72
|
-
},
|
73
|
-
{
|
74
|
-
type: "text",
|
75
|
-
name: "duration",
|
76
|
-
initial: "1",
|
77
|
-
message: "How many hours avg it takes to complete (number)?",
|
78
|
-
validate: (value: string) => {
|
79
|
-
const n = Math.floor(Number(value))
|
80
|
-
return (
|
81
|
-
n !== Number.POSITIVE_INFINITY && String(n) === value && n >= 0
|
82
|
-
)
|
83
|
-
},
|
84
|
-
},
|
85
|
-
])
|
86
|
-
|
87
|
-
const packageInfo = {
|
88
|
-
grading: choices.grading,
|
89
|
-
difficulty: choices.difficulty,
|
90
|
-
duration: parseInt(choices.duration),
|
91
|
-
description:
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
.
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
const
|
104
|
-
|
105
|
-
|
106
|
-
)
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
)
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
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
|
+
|
13
|
+
import * as path from "path"
|
14
|
+
|
15
|
+
class InitComand extends BaseCommand {
|
16
|
+
static description =
|
17
|
+
"Create a new learning package: Book, Tutorial or Exercise"
|
18
|
+
|
19
|
+
static flags = {
|
20
|
+
...BaseCommand.flags,
|
21
|
+
grading: flags.help({ char: "h" }),
|
22
|
+
}
|
23
|
+
|
24
|
+
async run() {
|
25
|
+
const { flags } = this.parse(InitComand)
|
26
|
+
|
27
|
+
// if the folder/file .learn or .breathecode aleady exists
|
28
|
+
await alreadyInitialized()
|
29
|
+
|
30
|
+
const choices = await prompts([
|
31
|
+
{
|
32
|
+
type: "select",
|
33
|
+
name: "grading",
|
34
|
+
message: "Is the auto-grading going to be isolated or incremental?",
|
35
|
+
choices: [
|
36
|
+
{
|
37
|
+
title: "Incremental: Build on top of each other like a tutorial",
|
38
|
+
value: "incremental",
|
39
|
+
},
|
40
|
+
{ title: "Isolated: Small separated exercises", value: "isolated" },
|
41
|
+
{
|
42
|
+
title: "No grading: No feedback or testing whatsoever",
|
43
|
+
value: null,
|
44
|
+
},
|
45
|
+
],
|
46
|
+
},
|
47
|
+
{
|
48
|
+
type: "text",
|
49
|
+
name: "title",
|
50
|
+
initial: "My Interactive Tutorial",
|
51
|
+
message: "Title for your tutorial? Press enter to leave as it is",
|
52
|
+
},
|
53
|
+
{
|
54
|
+
type: "text",
|
55
|
+
name: "description",
|
56
|
+
initial: "",
|
57
|
+
message: "Description for your tutorial? Press enter to leave blank",
|
58
|
+
},
|
59
|
+
{
|
60
|
+
type: "select",
|
61
|
+
name: "difficulty",
|
62
|
+
message: "How difficulty will be to complete the tutorial?",
|
63
|
+
choices: [
|
64
|
+
{ title: "Begginer (no previous experience)", value: "beginner" },
|
65
|
+
{ title: "Easy (just a bit of experience required)", value: "easy" },
|
66
|
+
{
|
67
|
+
title: "Intermediate (you need experience)",
|
68
|
+
value: "intermediate",
|
69
|
+
},
|
70
|
+
{ title: "Hard (master the topic)", value: "hard" },
|
71
|
+
],
|
72
|
+
},
|
73
|
+
{
|
74
|
+
type: "text",
|
75
|
+
name: "duration",
|
76
|
+
initial: "1",
|
77
|
+
message: "How many hours avg it takes to complete (number)?",
|
78
|
+
validate: (value: string) => {
|
79
|
+
const n = Math.floor(Number(value))
|
80
|
+
return (
|
81
|
+
n !== Number.POSITIVE_INFINITY && String(n) === value && n >= 0
|
82
|
+
)
|
83
|
+
},
|
84
|
+
},
|
85
|
+
])
|
86
|
+
|
87
|
+
const packageInfo = {
|
88
|
+
grading: choices.grading,
|
89
|
+
difficulty: choices.difficulty,
|
90
|
+
duration: parseInt(choices.duration),
|
91
|
+
description: {
|
92
|
+
us: choices.description,
|
93
|
+
},
|
94
|
+
title: {
|
95
|
+
us: choices.title,
|
96
|
+
},
|
97
|
+
slug: choices.title
|
98
|
+
.toLowerCase()
|
99
|
+
.replace(/ /g, "-")
|
100
|
+
.replace(/[^\w-]+/g, ""),
|
101
|
+
}
|
102
|
+
|
103
|
+
const tutorialDir = `./${packageInfo.slug}`
|
104
|
+
fs.ensureDirSync(tutorialDir) // Ensure the directory exists
|
105
|
+
|
106
|
+
cli.action.start("Initializing package")
|
107
|
+
|
108
|
+
const languages = ["en", "es"]
|
109
|
+
|
110
|
+
const templatesDir = path.resolve(
|
111
|
+
__dirname,
|
112
|
+
"../../src/utils/templates/" + (choices.grading || "no-grading")
|
113
|
+
)
|
114
|
+
if (!fs.existsSync(templatesDir))
|
115
|
+
throw ValidationError(`Template ${templatesDir} does not exists`)
|
116
|
+
await fs.copySync(templatesDir, tutorialDir)
|
117
|
+
|
118
|
+
// Creating README files
|
119
|
+
for (const language of languages) {
|
120
|
+
const readmeFilename = `README${language !== "en" ? `.${language}` : ""}`
|
121
|
+
fs.writeFileSync(
|
122
|
+
path.join(tutorialDir, `${readmeFilename}.md`),
|
123
|
+
eta.render(
|
124
|
+
fs.readFileSync(
|
125
|
+
path.resolve(__dirname, `${templatesDir}/${readmeFilename}.ejs`),
|
126
|
+
"utf-8"
|
127
|
+
),
|
128
|
+
packageInfo
|
129
|
+
)
|
130
|
+
)
|
131
|
+
if (fs.existsSync(path.join(tutorialDir, `${readmeFilename}.ejs`)))
|
132
|
+
fs.removeSync(path.join(tutorialDir, `${readmeFilename}.ejs`))
|
133
|
+
}
|
134
|
+
|
135
|
+
if (!fs.existsSync(path.join(tutorialDir, ".gitignore")))
|
136
|
+
fs.copyFile(
|
137
|
+
path.resolve(__dirname, "../../src/utils/templates/gitignore.txt"),
|
138
|
+
path.join(tutorialDir, ".gitignore")
|
139
|
+
)
|
140
|
+
fs.writeFileSync(
|
141
|
+
path.join(tutorialDir, "learn.json"),
|
142
|
+
JSON.stringify(packageInfo, null, 2)
|
143
|
+
)
|
144
|
+
|
145
|
+
cli.action.stop()
|
146
|
+
Console.success(`😋 Package initialized successfully in ${tutorialDir}`)
|
147
|
+
Console.help(
|
148
|
+
`Get inside the tutorial with the command: $ cd ${tutorialDir}`
|
149
|
+
)
|
150
|
+
Console.help(
|
151
|
+
`Start the exercises by running the following command on your terminal: $ learnpack start`
|
152
|
+
)
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
const alreadyInitialized = () =>
|
157
|
+
new Promise((resolve, reject) => {
|
158
|
+
fs.readdir("./", function (err: any, files: any) {
|
159
|
+
files = files.filter((f: any) =>
|
160
|
+
[".learn", "learn.json", "bc.json", ".breathecode"].includes(f)
|
161
|
+
)
|
162
|
+
if (err) {
|
163
|
+
reject(ValidationError(err.message))
|
164
|
+
throw ValidationError(err.message)
|
165
|
+
} else if (files.length > 0) {
|
166
|
+
reject(
|
167
|
+
ValidationError(
|
168
|
+
"It seems the package is already initialized because we've found the following files: " +
|
169
|
+
files.join(",")
|
170
|
+
)
|
171
|
+
)
|
172
|
+
throw ValidationError(
|
173
|
+
"It seems the package is already initialized because we've found the following files: " +
|
174
|
+
files.join(",")
|
175
|
+
)
|
176
|
+
}
|
177
|
+
|
178
|
+
resolve(false)
|
179
|
+
})
|
180
|
+
})
|
181
|
+
|
182
|
+
export default InitComand
|