@learnpack/learnpack 2.1.23 → 2.1.24
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/audit.js +15 -15
- package/lib/commands/init.js +9 -3
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/src/commands/audit.ts +418 -418
- package/src/commands/init.ts +170 -172
package/src/commands/init.ts
CHANGED
@@ -1,172 +1,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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
},
|
41
|
-
{
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
{ title: "
|
66
|
-
{
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
},
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
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
|
+
|
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: choices.description,
|
92
|
+
title: choices.title,
|
93
|
+
slug: choices.title
|
94
|
+
.toLowerCase()
|
95
|
+
.replace(/ /g, "-")
|
96
|
+
.replace(/[^\w-]+/g, ""),
|
97
|
+
};
|
98
|
+
|
99
|
+
cli.action.start("Initializing package");
|
100
|
+
|
101
|
+
const languages = ["en", "es"];
|
102
|
+
|
103
|
+
const templatesDir = path.resolve(
|
104
|
+
__dirname,
|
105
|
+
"../../src/utils/templates/" + choices.grading || "no-grading"
|
106
|
+
);
|
107
|
+
if (!fs.existsSync(templatesDir))
|
108
|
+
throw ValidationError(`Template ${templatesDir} does not exists`);
|
109
|
+
await fs.copySync(templatesDir, "./");
|
110
|
+
|
111
|
+
// Creating README files
|
112
|
+
// eslint-disable-next-line
|
113
|
+
languages.forEach((language) => {
|
114
|
+
const readmeFilename = `README${language !== "en" ? `.${language}` : ""}`;
|
115
|
+
fs.writeFileSync(
|
116
|
+
`./${readmeFilename}.md`,
|
117
|
+
eta.render(
|
118
|
+
fs.readFileSync(
|
119
|
+
path.resolve(__dirname, `${templatesDir}/${readmeFilename}.ejs`),
|
120
|
+
"utf-8"
|
121
|
+
),
|
122
|
+
packageInfo
|
123
|
+
)
|
124
|
+
);
|
125
|
+
if (fs.existsSync(`./${readmeFilename}.ejs`))
|
126
|
+
fs.removeSync(`./${readmeFilename}.ejs`);
|
127
|
+
});
|
128
|
+
|
129
|
+
if (!fs.existsSync("./.gitignore"))
|
130
|
+
fs.copyFile(
|
131
|
+
path.resolve(__dirname, "../../src/utils/templates/gitignore.txt"),
|
132
|
+
"./.gitignore"
|
133
|
+
);
|
134
|
+
fs.writeFileSync("./learn.json", JSON.stringify(packageInfo, null, 2));
|
135
|
+
|
136
|
+
cli.action.stop();
|
137
|
+
Console.success(`😋 Package initialized successfully`);
|
138
|
+
Console.help(
|
139
|
+
`Start the exercises by running the following command on your terminal: $ learnpack start`
|
140
|
+
);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
const alreadyInitialized = () =>
|
145
|
+
new Promise((resolve, reject) => {
|
146
|
+
fs.readdir("./", function (err: any, files: any) {
|
147
|
+
files = files.filter((f: any) =>
|
148
|
+
[".learn", "learn.json", "bc.json", ".breathecode"].includes(f)
|
149
|
+
);
|
150
|
+
if (err) {
|
151
|
+
reject(ValidationError(err.message));
|
152
|
+
throw ValidationError(err.message);
|
153
|
+
} else if (files.length > 0) {
|
154
|
+
reject(
|
155
|
+
ValidationError(
|
156
|
+
"It seems the package is already initialized because we've found the following files: " +
|
157
|
+
files.join(",")
|
158
|
+
)
|
159
|
+
);
|
160
|
+
throw ValidationError(
|
161
|
+
"It seems the package is already initialized because we've found the following files: " +
|
162
|
+
files.join(",")
|
163
|
+
);
|
164
|
+
}
|
165
|
+
|
166
|
+
resolve(false);
|
167
|
+
});
|
168
|
+
});
|
169
|
+
|
170
|
+
export default InitComand;
|