@learnpack/learnpack 2.0.2 → 2.0.3

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.
@@ -1,62 +1,62 @@
1
- import { Command /* , flags */ } from "@oclif/command";
2
- // import fetch from 'node-fetch'
3
- import { clone } from "../managers/file";
4
- import Console from "../utils/console";
5
- import api from "../utils/api";
6
- import { askPackage } from "../ui/download";
7
- // const BaseCommand = require('../utils/BaseCommand');
8
-
9
- class DownloadCommand extends Command {
10
- static description = `Describe the command here
11
- ...
12
- Extra documentation goes here
13
- `;
14
-
15
- static flags: any = {
16
- // name: flags.string({char: 'n', description: 'name to print'}),
17
- };
18
-
19
- static args = [
20
- {
21
- name: "package", // name of arg to show in help and reference with args[name]
22
- required: false, // make the arg required with `required: true`
23
- description:
24
- "The unique string that identifies this package on learnpack", // help description
25
- hidden: false, // hide this arg from help
26
- },
27
- ];
28
- // async init() {
29
- // const {flags} = this.parse(DownloadCommand)
30
- // await this.initSession(flags)
31
- // }
32
-
33
- async run() {
34
- const { /* flags, */ args } = this.parse(DownloadCommand);
35
- // start watching for file changes
36
- let _package: string = args.package;
37
- if (!_package) {
38
- _package = (await askPackage()) as string;
39
- }
40
-
41
- if (!_package) {
42
- return null;
43
- }
44
-
45
- try {
46
- const packageInfo = await api.getAllPackages({ slug: _package });
47
- if (packageInfo.results.length === 0)
48
- Console.error(`Package ${_package} not found`);
49
- else
50
- clone(packageInfo.results[0].repository)
51
- .then(_result => {
52
- Console.success("Successfully downloaded");
53
- Console.info(
54
- `You can now CD into the folder like this: $ cd ${_package}`
55
- );
56
- })
57
- .catch(error => Console.error(error.message || error));
58
- } catch {}
59
- }
60
- }
61
-
62
- export default DownloadCommand;
1
+ import { Command /* , flags */ } from "@oclif/command";
2
+ // import fetch from 'node-fetch'
3
+ import { clone } from "../managers/file";
4
+ import Console from "../utils/console";
5
+ import api from "../utils/api";
6
+ import { askPackage } from "../ui/download";
7
+ // const BaseCommand = require('../utils/BaseCommand');
8
+
9
+ class DownloadCommand extends Command {
10
+ static description = `Describe the command here
11
+ ...
12
+ Extra documentation goes here
13
+ `;
14
+
15
+ static flags: any = {
16
+ // name: flags.string({char: 'n', description: 'name to print'}),
17
+ };
18
+
19
+ static args = [
20
+ {
21
+ name: "package", // name of arg to show in help and reference with args[name]
22
+ required: false, // make the arg required with `required: true`
23
+ description:
24
+ "The unique string that identifies this package on learnpack", // help description
25
+ hidden: false, // hide this arg from help
26
+ },
27
+ ];
28
+ // async init() {
29
+ // const {flags} = this.parse(DownloadCommand)
30
+ // await this.initSession(flags)
31
+ // }
32
+
33
+ async run() {
34
+ const { /* flags, */ args } = this.parse(DownloadCommand);
35
+ // start watching for file changes
36
+ let _package: string = args.package;
37
+ if (!_package) {
38
+ _package = (await askPackage()) as string;
39
+ }
40
+
41
+ if (!_package) {
42
+ return null;
43
+ }
44
+
45
+ try {
46
+ const packageInfo = await api.getAllPackages({ slug: _package });
47
+ if (packageInfo.results.length === 0)
48
+ Console.error(`Package ${_package} not found`);
49
+ else
50
+ clone(packageInfo.results[0].repository)
51
+ .then(_result => {
52
+ Console.success("Successfully downloaded");
53
+ Console.info(
54
+ `You can now CD into the folder like this: $ cd ${_package}`
55
+ );
56
+ })
57
+ .catch(error => Console.error(error.message || error));
58
+ } catch {}
59
+ }
60
+ }
61
+
62
+ export default DownloadCommand;
@@ -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
+ "../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,42 +1,42 @@
1
- import SessionCommand from "../utils/SessionCommand";
2
- import SessionManager from "../managers/session";
3
- import Console from "../utils/console";
4
-
5
- class LoginCommand extends SessionCommand {
6
- static description = `Describe the command here
7
- ...
8
- Extra documentation goes here
9
- `;
10
-
11
- static flags: any = {
12
- // name: flags.string({char: 'n', description: 'name to print'}),
13
- };
14
-
15
- static args = [
16
- {
17
- name: "package", // name of arg to show in help and reference with args[name]
18
- required: false, // make the arg required with `required: true`
19
- description:
20
- "The unique string that identifies this package on learnpack", // help description
21
- hidden: false, // hide this arg from help
22
- },
23
- ];
24
-
25
- async init() {
26
- const { flags } = this.parse(LoginCommand);
27
- await this.initSession(flags);
28
- }
29
-
30
- async run() {
31
- /* const {flags, args} = */ this.parse(LoginCommand);
32
-
33
- try {
34
- await SessionManager.login();
35
- } catch (error) {
36
- Console.error("Error trying to authenticate");
37
- Console.error((error as TypeError).message || (error as string));
38
- }
39
- }
40
- }
41
-
42
- export default LoginCommand;
1
+ import SessionCommand from "../utils/SessionCommand";
2
+ import SessionManager from "../managers/session";
3
+ import Console from "../utils/console";
4
+
5
+ class LoginCommand extends SessionCommand {
6
+ static description = `Describe the command here
7
+ ...
8
+ Extra documentation goes here
9
+ `;
10
+
11
+ static flags: any = {
12
+ // name: flags.string({char: 'n', description: 'name to print'}),
13
+ };
14
+
15
+ static args = [
16
+ {
17
+ name: "package", // name of arg to show in help and reference with args[name]
18
+ required: false, // make the arg required with `required: true`
19
+ description:
20
+ "The unique string that identifies this package on learnpack", // help description
21
+ hidden: false, // hide this arg from help
22
+ },
23
+ ];
24
+
25
+ async init() {
26
+ const { flags } = this.parse(LoginCommand);
27
+ await this.initSession(flags);
28
+ }
29
+
30
+ async run() {
31
+ /* const {flags, args} = */ this.parse(LoginCommand);
32
+
33
+ try {
34
+ await SessionManager.login();
35
+ } catch (error) {
36
+ Console.error("Error trying to authenticate");
37
+ Console.error((error as TypeError).message || (error as string));
38
+ }
39
+ }
40
+ }
41
+
42
+ export default LoginCommand;
@@ -1,43 +1,43 @@
1
- // import {Command, flags} from '@oclif/command'
2
- // import { prompt } from "enquirer"
3
- // import fetch from 'node-fetch'
4
- import SessionCommand from "../utils/SessionCommand";
5
- import SessionManager from "../managers/session";
6
- // import Console from '../utils/console'
7
- // import { replace } from 'node-emoji'
8
- // import { validURL } from "../utils/validators"
9
- // const BaseCommand from '../utils/BaseCommand');
10
-
11
- class LogoutCommand extends SessionCommand {
12
- static description = `Describe the command here
13
- ...
14
- Extra documentation goes here
15
- `;
16
-
17
- static flags: any = {
18
- // name: flags.string({char: 'n', description: 'name to print'}),
19
- };
20
-
21
- static args = [
22
- {
23
- name: "package", // name of arg to show in help and reference with args[name]
24
- required: false, // make the arg required with `required: true`
25
- description:
26
- "The unique string that identifies this package on learnpack", // help description
27
- hidden: false, // hide this arg from help
28
- },
29
- ];
30
-
31
- async init() {
32
- const { flags } = this.parse(LogoutCommand);
33
- await this.initSession(flags);
34
- }
35
-
36
- async run() {
37
- // const {flags, args} = this.parse(LogoutCommand)
38
-
39
- SessionManager.destroy();
40
- }
41
- }
42
-
43
- export default LogoutCommand;
1
+ // import {Command, flags} from '@oclif/command'
2
+ // import { prompt } from "enquirer"
3
+ // import fetch from 'node-fetch'
4
+ import SessionCommand from "../utils/SessionCommand";
5
+ import SessionManager from "../managers/session";
6
+ // import Console from '../utils/console'
7
+ // import { replace } from 'node-emoji'
8
+ // import { validURL } from "../utils/validators"
9
+ // const BaseCommand from '../utils/BaseCommand');
10
+
11
+ class LogoutCommand extends SessionCommand {
12
+ static description = `Describe the command here
13
+ ...
14
+ Extra documentation goes here
15
+ `;
16
+
17
+ static flags: any = {
18
+ // name: flags.string({char: 'n', description: 'name to print'}),
19
+ };
20
+
21
+ static args = [
22
+ {
23
+ name: "package", // name of arg to show in help and reference with args[name]
24
+ required: false, // make the arg required with `required: true`
25
+ description:
26
+ "The unique string that identifies this package on learnpack", // help description
27
+ hidden: false, // hide this arg from help
28
+ },
29
+ ];
30
+
31
+ async init() {
32
+ const { flags } = this.parse(LogoutCommand);
33
+ await this.initSession(flags);
34
+ }
35
+
36
+ async run() {
37
+ // const {flags, args} = this.parse(LogoutCommand)
38
+
39
+ SessionManager.destroy();
40
+ }
41
+ }
42
+
43
+ export default LogoutCommand;