@learnpack/learnpack 2.1.25 → 2.1.26
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +16 -16
- package/bin/run +17 -17
- package/bin/run.cmd +3 -3
- package/lib/commands/audit.d.ts +6 -6
- package/lib/commands/audit.js +327 -302
- package/lib/commands/clean.d.ts +8 -8
- package/lib/commands/clean.js +25 -25
- package/lib/commands/download.d.ts +13 -13
- package/lib/commands/download.js +55 -55
- package/lib/commands/init.d.ts +9 -9
- package/lib/commands/init.js +123 -123
- package/lib/commands/login.d.ts +14 -14
- package/lib/commands/login.js +37 -37
- package/lib/commands/logout.d.ts +14 -14
- package/lib/commands/logout.js +37 -37
- package/lib/commands/publish.d.ts +14 -14
- package/lib/commands/publish.js +82 -82
- package/lib/commands/start.d.ts +7 -7
- package/lib/commands/start.js +165 -165
- package/lib/commands/test.d.ts +6 -6
- package/lib/commands/test.js +62 -62
- package/lib/index.d.ts +1 -1
- package/lib/index.js +4 -4
- package/lib/managers/config/allowed_files.d.ts +5 -5
- package/lib/managers/config/allowed_files.js +30 -30
- package/lib/managers/config/defaults.d.ts +39 -37
- package/lib/managers/config/defaults.js +40 -38
- package/lib/managers/config/exercise.d.ts +36 -36
- package/lib/managers/config/exercise.js +233 -230
- package/lib/managers/config/index.d.ts +3 -3
- package/lib/managers/config/index.js +320 -302
- package/lib/managers/file.d.ts +13 -13
- package/lib/managers/file.js +134 -134
- package/lib/managers/gitpod.d.ts +3 -3
- package/lib/managers/gitpod.js +67 -67
- package/lib/managers/server/index.d.ts +6 -6
- package/lib/managers/server/index.js +58 -51
- package/lib/managers/server/routes.d.ts +4 -4
- package/lib/managers/server/routes.js +167 -167
- package/lib/managers/session.d.ts +3 -3
- package/lib/managers/session.js +104 -104
- package/lib/managers/socket.d.ts +3 -3
- package/lib/managers/socket.js +164 -164
- package/lib/managers/test.js +84 -84
- package/lib/models/action.d.ts +2 -2
- package/lib/models/action.js +2 -2
- package/lib/models/audit.d.ts +15 -15
- package/lib/models/audit.js +2 -2
- package/lib/models/config-manager.d.ts +21 -21
- package/lib/models/config-manager.js +2 -2
- package/lib/models/config.d.ts +62 -60
- package/lib/models/config.js +2 -2
- package/lib/models/counter.d.ts +11 -11
- package/lib/models/counter.js +2 -2
- package/lib/models/errors.d.ts +15 -15
- package/lib/models/errors.js +2 -2
- package/lib/models/exercise-obj.d.ts +27 -27
- package/lib/models/exercise-obj.js +2 -2
- package/lib/models/file.d.ts +5 -5
- package/lib/models/file.js +2 -2
- package/lib/models/findings.d.ts +17 -17
- package/lib/models/findings.js +2 -2
- package/lib/models/flags.d.ts +10 -10
- package/lib/models/flags.js +2 -2
- package/lib/models/front-matter.d.ts +11 -11
- package/lib/models/front-matter.js +2 -2
- package/lib/models/gitpod-data.d.ts +16 -16
- package/lib/models/gitpod-data.js +2 -2
- package/lib/models/language.d.ts +4 -4
- package/lib/models/language.js +2 -2
- package/lib/models/package.d.ts +7 -7
- package/lib/models/package.js +2 -2
- package/lib/models/plugin-config.d.ts +16 -16
- package/lib/models/plugin-config.js +2 -2
- package/lib/models/session.d.ts +23 -23
- package/lib/models/session.js +2 -2
- package/lib/models/socket.d.ts +31 -31
- package/lib/models/socket.js +2 -2
- package/lib/models/status.d.ts +1 -1
- package/lib/models/status.js +2 -2
- package/lib/models/success-types.d.ts +1 -1
- package/lib/models/success-types.js +2 -2
- package/lib/plugin/command/compile.d.ts +6 -6
- package/lib/plugin/command/compile.js +18 -18
- package/lib/plugin/command/test.d.ts +6 -6
- package/lib/plugin/command/test.js +25 -25
- package/lib/plugin/index.d.ts +27 -27
- package/lib/plugin/index.js +7 -7
- package/lib/plugin/plugin.d.ts +8 -8
- package/lib/plugin/plugin.js +68 -68
- package/lib/plugin/utils.d.ts +16 -16
- package/lib/plugin/utils.js +58 -58
- package/lib/ui/download.d.ts +5 -5
- package/lib/ui/download.js +61 -61
- package/lib/utils/BaseCommand.d.ts +8 -8
- package/lib/utils/BaseCommand.js +41 -41
- package/lib/utils/SessionCommand.d.ts +10 -10
- package/lib/utils/SessionCommand.js +47 -47
- package/lib/utils/api.d.ts +12 -12
- package/lib/utils/api.js +173 -173
- package/lib/utils/audit.d.ts +16 -16
- package/lib/utils/audit.js +302 -302
- package/lib/utils/console.d.ts +12 -12
- package/lib/utils/console.js +19 -19
- package/lib/utils/errors.d.ts +17 -17
- package/lib/utils/errors.js +100 -100
- package/lib/utils/exercisesQueue.d.ts +9 -9
- package/lib/utils/exercisesQueue.js +38 -38
- package/lib/utils/fileQueue.d.ts +40 -40
- package/lib/utils/fileQueue.js +168 -168
- package/lib/utils/misc.d.ts +1 -1
- package/lib/utils/misc.js +23 -23
- package/lib/utils/validators.d.ts +5 -5
- package/lib/utils/validators.js +17 -17
- package/lib/utils/watcher.d.ts +2 -2
- package/lib/utils/watcher.js +23 -23
- package/oclif.manifest.json +1 -1
- package/package.json +138 -138
- package/src/commands/audit.ts +25 -0
- package/src/commands/clean.ts +29 -29
- package/src/commands/download.ts +62 -62
- package/src/commands/login.ts +42 -42
- package/src/commands/logout.ts +43 -43
- package/src/commands/publish.ts +107 -107
- package/src/commands/start.ts +238 -234
- package/src/commands/test.ts +85 -85
- package/src/index.ts +1 -1
- package/src/managers/config/allowed_files.ts +29 -29
- package/src/managers/config/defaults.ts +2 -0
- package/src/managers/config/exercise.ts +309 -302
- package/src/managers/config/index.ts +22 -1
- package/src/managers/file.ts +169 -169
- package/src/managers/gitpod.ts +84 -84
- package/src/managers/server/index.ts +77 -69
- package/src/managers/session.ts +118 -118
- package/src/managers/socket.ts +239 -239
- package/src/managers/test.ts +83 -83
- package/src/models/action.ts +3 -3
- package/src/models/config-manager.ts +23 -23
- package/src/models/config.ts +2 -0
- package/src/models/counter.ts +11 -11
- package/src/models/errors.ts +22 -22
- package/src/models/file.ts +5 -5
- package/src/models/findings.ts +18 -18
- package/src/models/flags.ts +10 -10
- package/src/models/front-matter.ts +11 -11
- package/src/models/gitpod-data.ts +19 -19
- package/src/models/language.ts +4 -4
- package/src/models/package.ts +7 -7
- package/src/models/plugin-config.ts +17 -17
- package/src/models/session.ts +26 -26
- package/src/models/socket.ts +48 -48
- package/src/models/status.ts +15 -15
- package/src/models/success-types.ts +1 -1
- package/src/plugin/command/compile.ts +17 -17
- package/src/plugin/command/test.ts +30 -30
- package/src/plugin/index.ts +6 -6
- package/src/plugin/plugin.ts +94 -94
- package/src/plugin/utils.ts +87 -87
- package/src/types/node-fetch.d.ts +1 -1
- package/src/ui/download.ts +71 -71
- package/src/utils/BaseCommand.ts +48 -48
- package/src/utils/SessionCommand.ts +48 -48
- package/src/utils/api.ts +194 -194
- package/src/utils/audit.ts +395 -395
- package/src/utils/console.ts +24 -24
- package/src/utils/errors.ts +117 -117
- package/src/utils/exercisesQueue.ts +51 -51
- package/src/utils/fileQueue.ts +198 -198
- package/src/utils/misc.ts +23 -23
- package/src/utils/templates/gitignore.txt +19 -19
- package/src/utils/templates/incremental/.learn/exercises/01-hello-world/README.es.md +24 -24
- package/src/utils/templates/incremental/.learn/exercises/01-hello-world/README.md +24 -24
- package/src/utils/templates/incremental/README.ejs +4 -4
- package/src/utils/templates/incremental/README.es.ejs +4 -4
- package/src/utils/templates/isolated/01-hello-world/README.es.md +26 -26
- package/src/utils/templates/isolated/01-hello-world/README.md +26 -26
- package/src/utils/templates/isolated/README.ejs +4 -4
- package/src/utils/templates/isolated/README.es.ejs +4 -4
- package/src/utils/templates/no-grading/README.ejs +4 -4
- package/src/utils/templates/no-grading/README.es.ejs +4 -4
- package/src/utils/validators.ts +18 -18
package/lib/utils/BaseCommand.js
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const command_1 = require("@oclif/command");
|
4
|
-
const console_1 = require("./console");
|
5
|
-
const readline_1 = require("readline");
|
6
|
-
// import SessionManager from '../managers/session'
|
7
|
-
class BaseCommand extends command_1.Command {
|
8
|
-
async catch(err) {
|
9
|
-
console_1.default.debug("COMMAND CATCH", err);
|
10
|
-
throw err;
|
11
|
-
}
|
12
|
-
async init() {
|
13
|
-
const { flags, args } = this.parse(BaseCommand);
|
14
|
-
console_1.default.debug("COMMAND INIT");
|
15
|
-
console_1.default.debug("These are your flags: ", flags);
|
16
|
-
console_1.default.debug("These are your args: ", args);
|
17
|
-
// quick fix for listening to the process termination on windows
|
18
|
-
if (process.platform === "win32") {
|
19
|
-
const rl = readline_1.createInterface({
|
20
|
-
input: process.stdin,
|
21
|
-
output: process.stdout,
|
22
|
-
});
|
23
|
-
rl.on("SIGINT", function () {
|
24
|
-
// process.emit('SIGINT')
|
25
|
-
// process.emit('SIGINT')
|
26
|
-
});
|
27
|
-
}
|
28
|
-
process.on("SIGINT", function () {
|
29
|
-
console_1.default.debug("Terminated (SIGINT)");
|
30
|
-
process.exit();
|
31
|
-
});
|
32
|
-
}
|
33
|
-
async finally() {
|
34
|
-
console_1.default.debug("COMMAND FINALLY");
|
35
|
-
// called after run and catch regardless of whether or not the command errored
|
36
|
-
}
|
37
|
-
async run() {
|
38
|
-
// console.log('running my command')
|
39
|
-
}
|
40
|
-
}
|
41
|
-
exports.default = BaseCommand;
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const command_1 = require("@oclif/command");
|
4
|
+
const console_1 = require("./console");
|
5
|
+
const readline_1 = require("readline");
|
6
|
+
// import SessionManager from '../managers/session'
|
7
|
+
class BaseCommand extends command_1.Command {
|
8
|
+
async catch(err) {
|
9
|
+
console_1.default.debug("COMMAND CATCH", err);
|
10
|
+
throw err;
|
11
|
+
}
|
12
|
+
async init() {
|
13
|
+
const { flags, args } = this.parse(BaseCommand);
|
14
|
+
console_1.default.debug("COMMAND INIT");
|
15
|
+
console_1.default.debug("These are your flags: ", flags);
|
16
|
+
console_1.default.debug("These are your args: ", args);
|
17
|
+
// quick fix for listening to the process termination on windows
|
18
|
+
if (process.platform === "win32") {
|
19
|
+
const rl = readline_1.createInterface({
|
20
|
+
input: process.stdin,
|
21
|
+
output: process.stdout,
|
22
|
+
});
|
23
|
+
rl.on("SIGINT", function () {
|
24
|
+
// process.emit('SIGINT')
|
25
|
+
// process.emit('SIGINT')
|
26
|
+
});
|
27
|
+
}
|
28
|
+
process.on("SIGINT", function () {
|
29
|
+
console_1.default.debug("Terminated (SIGINT)");
|
30
|
+
process.exit();
|
31
|
+
});
|
32
|
+
}
|
33
|
+
async finally() {
|
34
|
+
console_1.default.debug("COMMAND FINALLY");
|
35
|
+
// called after run and catch regardless of whether or not the command errored
|
36
|
+
}
|
37
|
+
async run() {
|
38
|
+
// console.log('running my command')
|
39
|
+
}
|
40
|
+
}
|
41
|
+
exports.default = BaseCommand;
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import BaseCommand from './BaseCommand';
|
2
|
-
import { IConfigManager } from '../models/config-manager';
|
3
|
-
export default class SessionCommand extends BaseCommand {
|
4
|
-
session: any;
|
5
|
-
configManager: IConfigManager | null;
|
6
|
-
static flags: any;
|
7
|
-
initSession(flags: any, _private?: boolean): Promise<void>;
|
8
|
-
buildConfig(flags: any): Promise<void>;
|
9
|
-
catch(err: any): Promise<void>;
|
10
|
-
}
|
1
|
+
import BaseCommand from './BaseCommand';
|
2
|
+
import { IConfigManager } from '../models/config-manager';
|
3
|
+
export default class SessionCommand extends BaseCommand {
|
4
|
+
session: any;
|
5
|
+
configManager: IConfigManager | null;
|
6
|
+
static flags: any;
|
7
|
+
initSession(flags: any, _private?: boolean): Promise<void>;
|
8
|
+
buildConfig(flags: any): Promise<void>;
|
9
|
+
catch(err: any): Promise<void>;
|
10
|
+
}
|
@@ -1,47 +1,47 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
// import { flags } from "@oclif/command";
|
4
|
-
const BaseCommand_1 = require("./BaseCommand");
|
5
|
-
const console_1 = require("./console");
|
6
|
-
const session_1 = require("../managers/session");
|
7
|
-
const index_1 = require("../managers/config/index");
|
8
|
-
const errors_1 = require("./errors");
|
9
|
-
class SessionCommand extends BaseCommand_1.default {
|
10
|
-
constructor() {
|
11
|
-
super(...arguments);
|
12
|
-
this.session = null;
|
13
|
-
this.configManager = null;
|
14
|
-
}
|
15
|
-
async initSession(flags, _private = false) {
|
16
|
-
var _a;
|
17
|
-
try {
|
18
|
-
if (!this.configManager) {
|
19
|
-
await this.buildConfig(flags);
|
20
|
-
}
|
21
|
-
this.session = await session_1.default.get((_a = this.configManager) === null || _a === void 0 ? void 0 : _a.get());
|
22
|
-
if (this.session) {
|
23
|
-
console_1.default.debug(`Session open for ${this.session.payload.email}.`);
|
24
|
-
}
|
25
|
-
else {
|
26
|
-
if (_private)
|
27
|
-
throw errors_1.AuthError('You need to log in, run the following command to continue: $ learnpack login');
|
28
|
-
console_1.default.debug('No active session available', _private);
|
29
|
-
}
|
30
|
-
}
|
31
|
-
catch (error) {
|
32
|
-
console_1.default.error(error.message);
|
33
|
-
}
|
34
|
-
}
|
35
|
-
async buildConfig(flags) {
|
36
|
-
this.configManager = await index_1.default(flags);
|
37
|
-
}
|
38
|
-
async catch(err) {
|
39
|
-
console_1.default.debug('COMMAND CATCH', err);
|
40
|
-
throw err;
|
41
|
-
}
|
42
|
-
}
|
43
|
-
exports.default = SessionCommand;
|
44
|
-
// SessionCommand.description = `Describe the command here
|
45
|
-
// ...
|
46
|
-
// Extra documentation goes here
|
47
|
-
// `
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
// import { flags } from "@oclif/command";
|
4
|
+
const BaseCommand_1 = require("./BaseCommand");
|
5
|
+
const console_1 = require("./console");
|
6
|
+
const session_1 = require("../managers/session");
|
7
|
+
const index_1 = require("../managers/config/index");
|
8
|
+
const errors_1 = require("./errors");
|
9
|
+
class SessionCommand extends BaseCommand_1.default {
|
10
|
+
constructor() {
|
11
|
+
super(...arguments);
|
12
|
+
this.session = null;
|
13
|
+
this.configManager = null;
|
14
|
+
}
|
15
|
+
async initSession(flags, _private = false) {
|
16
|
+
var _a;
|
17
|
+
try {
|
18
|
+
if (!this.configManager) {
|
19
|
+
await this.buildConfig(flags);
|
20
|
+
}
|
21
|
+
this.session = await session_1.default.get((_a = this.configManager) === null || _a === void 0 ? void 0 : _a.get());
|
22
|
+
if (this.session) {
|
23
|
+
console_1.default.debug(`Session open for ${this.session.payload.email}.`);
|
24
|
+
}
|
25
|
+
else {
|
26
|
+
if (_private)
|
27
|
+
throw errors_1.AuthError('You need to log in, run the following command to continue: $ learnpack login');
|
28
|
+
console_1.default.debug('No active session available', _private);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
catch (error) {
|
32
|
+
console_1.default.error(error.message);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
async buildConfig(flags) {
|
36
|
+
this.configManager = await index_1.default(flags);
|
37
|
+
}
|
38
|
+
async catch(err) {
|
39
|
+
console_1.default.debug('COMMAND CATCH', err);
|
40
|
+
throw err;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
exports.default = SessionCommand;
|
44
|
+
// SessionCommand.description = `Describe the command here
|
45
|
+
// ...
|
46
|
+
// Extra documentation goes here
|
47
|
+
// `
|
package/lib/utils/api.d.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
declare const _default: {
|
2
|
-
login: (identification: string, password: string) => Promise<any>;
|
3
|
-
publish: (config: any) => Promise<any>;
|
4
|
-
update: (config: any) => Promise<any>;
|
5
|
-
getPackage: (slug: string) => Promise<any>;
|
6
|
-
getLangs: () => Promise<any>;
|
7
|
-
getAllPackages: ({ lang, slug, }: {
|
8
|
-
lang?: string | undefined;
|
9
|
-
slug?: string | undefined;
|
10
|
-
}) => Promise<any>;
|
11
|
-
};
|
12
|
-
export default _default;
|
1
|
+
declare const _default: {
|
2
|
+
login: (identification: string, password: string) => Promise<any>;
|
3
|
+
publish: (config: any) => Promise<any>;
|
4
|
+
update: (config: any) => Promise<any>;
|
5
|
+
getPackage: (slug: string) => Promise<any>;
|
6
|
+
getLangs: () => Promise<any>;
|
7
|
+
getAllPackages: ({ lang, slug, }: {
|
8
|
+
lang?: string | undefined;
|
9
|
+
slug?: string | undefined;
|
10
|
+
}) => Promise<any>;
|
11
|
+
};
|
12
|
+
export default _default;
|
package/lib/utils/api.js
CHANGED
@@ -1,173 +1,173 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const console_1 = require("../utils/console");
|
4
|
-
const storage = require("node-persist");
|
5
|
-
const cli_ux_1 = require("cli-ux");
|
6
|
-
const HOST = "https://learnpack.herokuapp.com";
|
7
|
-
// eslint-disable-next-line
|
8
|
-
const _fetch = require("node-fetch");
|
9
|
-
const fetch = async (url, options = {}) => {
|
10
|
-
const headers = { "Content-Type": "application/json" };
|
11
|
-
let session = null;
|
12
|
-
try {
|
13
|
-
session = await storage.getItem("bc-payload");
|
14
|
-
if (session.token && session.token !== "" && !url.includes("/token"))
|
15
|
-
headers.Authorization = "Token " + session.token;
|
16
|
-
}
|
17
|
-
catch (_a) { }
|
18
|
-
try {
|
19
|
-
const resp = await _fetch(url, Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, headers), options.headers) }));
|
20
|
-
if (resp.status >= 200 && resp.status < 300)
|
21
|
-
return await resp.json();
|
22
|
-
if (resp.status === 401)
|
23
|
-
throw APIError("Invalid authentication credentials", 401);
|
24
|
-
else if (resp.status === 404)
|
25
|
-
throw APIError("Package not found", 404);
|
26
|
-
else if (resp.status >= 500)
|
27
|
-
throw APIError("Impossible to connect with the server", 500);
|
28
|
-
else if (resp.status >= 400) {
|
29
|
-
const error = await resp.json();
|
30
|
-
if (error.detail || error.error) {
|
31
|
-
throw APIError(error.detail || error.error);
|
32
|
-
}
|
33
|
-
else if (error.nonFieldErrors) {
|
34
|
-
throw APIError(error.nonFieldErrors[0], error);
|
35
|
-
}
|
36
|
-
else if (typeof error === "object") {
|
37
|
-
if (Object.keys(error).length > 0) {
|
38
|
-
const key = error[Object.keys(error)[0]];
|
39
|
-
throw APIError(`${key}: ${error[key][0]}`, error);
|
40
|
-
}
|
41
|
-
}
|
42
|
-
else {
|
43
|
-
throw APIError("Uknown error");
|
44
|
-
}
|
45
|
-
}
|
46
|
-
else
|
47
|
-
throw APIError("Uknown error");
|
48
|
-
}
|
49
|
-
catch (error) {
|
50
|
-
console_1.default.error(error.message);
|
51
|
-
throw error;
|
52
|
-
}
|
53
|
-
};
|
54
|
-
const login = async (identification, password) => {
|
55
|
-
try {
|
56
|
-
cli_ux_1.default.action.start("Looking for credentials...");
|
57
|
-
await cli_ux_1.default.wait(1000);
|
58
|
-
const data = await fetch(`${HOST}/v1/auth/token/`, {
|
59
|
-
body: JSON.stringify({ identification, password }),
|
60
|
-
method: "post",
|
61
|
-
});
|
62
|
-
cli_ux_1.default.action.stop("ready");
|
63
|
-
return data;
|
64
|
-
}
|
65
|
-
catch (error) {
|
66
|
-
console_1.default.error(error.message);
|
67
|
-
console_1.default.debug(error);
|
68
|
-
}
|
69
|
-
};
|
70
|
-
const publish = async (config) => {
|
71
|
-
const keys = [
|
72
|
-
"difficulty",
|
73
|
-
"language",
|
74
|
-
"skills",
|
75
|
-
"technologies",
|
76
|
-
"slug",
|
77
|
-
"repository",
|
78
|
-
"author",
|
79
|
-
"title",
|
80
|
-
];
|
81
|
-
const payload = {};
|
82
|
-
for (const k of keys)
|
83
|
-
config[k] ? (payload[k] = config[k]) : null;
|
84
|
-
try {
|
85
|
-
console.log("Package to publish:", payload);
|
86
|
-
cli_ux_1.default.action.start("Updating package information...");
|
87
|
-
await cli_ux_1.default.wait(1000);
|
88
|
-
const data = await fetch(`${HOST}/v1/package/${config.slug}`, {
|
89
|
-
method: "PUT",
|
90
|
-
body: JSON.stringify(payload),
|
91
|
-
});
|
92
|
-
cli_ux_1.default.action.stop("ready");
|
93
|
-
return data;
|
94
|
-
}
|
95
|
-
catch (error) {
|
96
|
-
console.log("payload", payload);
|
97
|
-
console_1.default.error(error.message);
|
98
|
-
console_1.default.debug(error);
|
99
|
-
throw error;
|
100
|
-
}
|
101
|
-
};
|
102
|
-
const update = async (config) => {
|
103
|
-
try {
|
104
|
-
cli_ux_1.default.action.start("Updating package information...");
|
105
|
-
await cli_ux_1.default.wait(1000);
|
106
|
-
const data = await fetch(`${HOST}/v1/package/`, {
|
107
|
-
method: "POST",
|
108
|
-
body: JSON.stringify(config),
|
109
|
-
});
|
110
|
-
cli_ux_1.default.action.stop("ready");
|
111
|
-
return data;
|
112
|
-
}
|
113
|
-
catch (error) {
|
114
|
-
console_1.default.error(error.message);
|
115
|
-
console_1.default.debug(error);
|
116
|
-
throw error;
|
117
|
-
}
|
118
|
-
};
|
119
|
-
const getPackage = async (slug) => {
|
120
|
-
try {
|
121
|
-
cli_ux_1.default.action.start("Downloading package information...");
|
122
|
-
await cli_ux_1.default.wait(1000);
|
123
|
-
const data = await fetch(`${HOST}/v1/package/${slug}`);
|
124
|
-
cli_ux_1.default.action.stop("ready");
|
125
|
-
return data;
|
126
|
-
}
|
127
|
-
catch (error) {
|
128
|
-
if (error.status === 404)
|
129
|
-
console_1.default.error(`Package ${slug} does not exist`);
|
130
|
-
else
|
131
|
-
console_1.default.error(`Package ${slug} does not exist`);
|
132
|
-
console_1.default.debug(error);
|
133
|
-
throw error;
|
134
|
-
}
|
135
|
-
};
|
136
|
-
const getLangs = async () => {
|
137
|
-
try {
|
138
|
-
cli_ux_1.default.action.start("Downloading language options...");
|
139
|
-
await cli_ux_1.default.wait(1000);
|
140
|
-
const data = await fetch(`${HOST}/v1/package/language`);
|
141
|
-
cli_ux_1.default.action.stop("ready");
|
142
|
-
return data;
|
143
|
-
}
|
144
|
-
catch (error) {
|
145
|
-
if (error.status === 404)
|
146
|
-
console_1.default.error("Package slug does not exist");
|
147
|
-
else
|
148
|
-
console_1.default.error("Package slug does not exist");
|
149
|
-
console_1.default.debug(error);
|
150
|
-
throw error;
|
151
|
-
}
|
152
|
-
};
|
153
|
-
const getAllPackages = async ({ lang = "", slug = "", }) => {
|
154
|
-
try {
|
155
|
-
cli_ux_1.default.action.start("Downloading packages...");
|
156
|
-
await cli_ux_1.default.wait(1000);
|
157
|
-
const data = await fetch(`${HOST}/v1/package/all?limit=100&language=${lang}&slug=${slug}`);
|
158
|
-
cli_ux_1.default.action.stop("ready");
|
159
|
-
return data;
|
160
|
-
}
|
161
|
-
catch (error) {
|
162
|
-
console_1.default.error(`Package ${slug} does not exist`);
|
163
|
-
console_1.default.debug(error);
|
164
|
-
throw error;
|
165
|
-
}
|
166
|
-
};
|
167
|
-
const APIError = (error, code) => {
|
168
|
-
const message = error.message || error;
|
169
|
-
const _err = new Error(message);
|
170
|
-
_err.status = code || 400;
|
171
|
-
return _err;
|
172
|
-
};
|
173
|
-
exports.default = { login, publish, update, getPackage, getLangs, getAllPackages };
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const console_1 = require("../utils/console");
|
4
|
+
const storage = require("node-persist");
|
5
|
+
const cli_ux_1 = require("cli-ux");
|
6
|
+
const HOST = "https://learnpack.herokuapp.com";
|
7
|
+
// eslint-disable-next-line
|
8
|
+
const _fetch = require("node-fetch");
|
9
|
+
const fetch = async (url, options = {}) => {
|
10
|
+
const headers = { "Content-Type": "application/json" };
|
11
|
+
let session = null;
|
12
|
+
try {
|
13
|
+
session = await storage.getItem("bc-payload");
|
14
|
+
if (session.token && session.token !== "" && !url.includes("/token"))
|
15
|
+
headers.Authorization = "Token " + session.token;
|
16
|
+
}
|
17
|
+
catch (_a) { }
|
18
|
+
try {
|
19
|
+
const resp = await _fetch(url, Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, headers), options.headers) }));
|
20
|
+
if (resp.status >= 200 && resp.status < 300)
|
21
|
+
return await resp.json();
|
22
|
+
if (resp.status === 401)
|
23
|
+
throw APIError("Invalid authentication credentials", 401);
|
24
|
+
else if (resp.status === 404)
|
25
|
+
throw APIError("Package not found", 404);
|
26
|
+
else if (resp.status >= 500)
|
27
|
+
throw APIError("Impossible to connect with the server", 500);
|
28
|
+
else if (resp.status >= 400) {
|
29
|
+
const error = await resp.json();
|
30
|
+
if (error.detail || error.error) {
|
31
|
+
throw APIError(error.detail || error.error);
|
32
|
+
}
|
33
|
+
else if (error.nonFieldErrors) {
|
34
|
+
throw APIError(error.nonFieldErrors[0], error);
|
35
|
+
}
|
36
|
+
else if (typeof error === "object") {
|
37
|
+
if (Object.keys(error).length > 0) {
|
38
|
+
const key = error[Object.keys(error)[0]];
|
39
|
+
throw APIError(`${key}: ${error[key][0]}`, error);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
else {
|
43
|
+
throw APIError("Uknown error");
|
44
|
+
}
|
45
|
+
}
|
46
|
+
else
|
47
|
+
throw APIError("Uknown error");
|
48
|
+
}
|
49
|
+
catch (error) {
|
50
|
+
console_1.default.error(error.message);
|
51
|
+
throw error;
|
52
|
+
}
|
53
|
+
};
|
54
|
+
const login = async (identification, password) => {
|
55
|
+
try {
|
56
|
+
cli_ux_1.default.action.start("Looking for credentials...");
|
57
|
+
await cli_ux_1.default.wait(1000);
|
58
|
+
const data = await fetch(`${HOST}/v1/auth/token/`, {
|
59
|
+
body: JSON.stringify({ identification, password }),
|
60
|
+
method: "post",
|
61
|
+
});
|
62
|
+
cli_ux_1.default.action.stop("ready");
|
63
|
+
return data;
|
64
|
+
}
|
65
|
+
catch (error) {
|
66
|
+
console_1.default.error(error.message);
|
67
|
+
console_1.default.debug(error);
|
68
|
+
}
|
69
|
+
};
|
70
|
+
const publish = async (config) => {
|
71
|
+
const keys = [
|
72
|
+
"difficulty",
|
73
|
+
"language",
|
74
|
+
"skills",
|
75
|
+
"technologies",
|
76
|
+
"slug",
|
77
|
+
"repository",
|
78
|
+
"author",
|
79
|
+
"title",
|
80
|
+
];
|
81
|
+
const payload = {};
|
82
|
+
for (const k of keys)
|
83
|
+
config[k] ? (payload[k] = config[k]) : null;
|
84
|
+
try {
|
85
|
+
console.log("Package to publish:", payload);
|
86
|
+
cli_ux_1.default.action.start("Updating package information...");
|
87
|
+
await cli_ux_1.default.wait(1000);
|
88
|
+
const data = await fetch(`${HOST}/v1/package/${config.slug}`, {
|
89
|
+
method: "PUT",
|
90
|
+
body: JSON.stringify(payload),
|
91
|
+
});
|
92
|
+
cli_ux_1.default.action.stop("ready");
|
93
|
+
return data;
|
94
|
+
}
|
95
|
+
catch (error) {
|
96
|
+
console.log("payload", payload);
|
97
|
+
console_1.default.error(error.message);
|
98
|
+
console_1.default.debug(error);
|
99
|
+
throw error;
|
100
|
+
}
|
101
|
+
};
|
102
|
+
const update = async (config) => {
|
103
|
+
try {
|
104
|
+
cli_ux_1.default.action.start("Updating package information...");
|
105
|
+
await cli_ux_1.default.wait(1000);
|
106
|
+
const data = await fetch(`${HOST}/v1/package/`, {
|
107
|
+
method: "POST",
|
108
|
+
body: JSON.stringify(config),
|
109
|
+
});
|
110
|
+
cli_ux_1.default.action.stop("ready");
|
111
|
+
return data;
|
112
|
+
}
|
113
|
+
catch (error) {
|
114
|
+
console_1.default.error(error.message);
|
115
|
+
console_1.default.debug(error);
|
116
|
+
throw error;
|
117
|
+
}
|
118
|
+
};
|
119
|
+
const getPackage = async (slug) => {
|
120
|
+
try {
|
121
|
+
cli_ux_1.default.action.start("Downloading package information...");
|
122
|
+
await cli_ux_1.default.wait(1000);
|
123
|
+
const data = await fetch(`${HOST}/v1/package/${slug}`);
|
124
|
+
cli_ux_1.default.action.stop("ready");
|
125
|
+
return data;
|
126
|
+
}
|
127
|
+
catch (error) {
|
128
|
+
if (error.status === 404)
|
129
|
+
console_1.default.error(`Package ${slug} does not exist`);
|
130
|
+
else
|
131
|
+
console_1.default.error(`Package ${slug} does not exist`);
|
132
|
+
console_1.default.debug(error);
|
133
|
+
throw error;
|
134
|
+
}
|
135
|
+
};
|
136
|
+
const getLangs = async () => {
|
137
|
+
try {
|
138
|
+
cli_ux_1.default.action.start("Downloading language options...");
|
139
|
+
await cli_ux_1.default.wait(1000);
|
140
|
+
const data = await fetch(`${HOST}/v1/package/language`);
|
141
|
+
cli_ux_1.default.action.stop("ready");
|
142
|
+
return data;
|
143
|
+
}
|
144
|
+
catch (error) {
|
145
|
+
if (error.status === 404)
|
146
|
+
console_1.default.error("Package slug does not exist");
|
147
|
+
else
|
148
|
+
console_1.default.error("Package slug does not exist");
|
149
|
+
console_1.default.debug(error);
|
150
|
+
throw error;
|
151
|
+
}
|
152
|
+
};
|
153
|
+
const getAllPackages = async ({ lang = "", slug = "", }) => {
|
154
|
+
try {
|
155
|
+
cli_ux_1.default.action.start("Downloading packages...");
|
156
|
+
await cli_ux_1.default.wait(1000);
|
157
|
+
const data = await fetch(`${HOST}/v1/package/all?limit=100&language=${lang}&slug=${slug}`);
|
158
|
+
cli_ux_1.default.action.stop("ready");
|
159
|
+
return data;
|
160
|
+
}
|
161
|
+
catch (error) {
|
162
|
+
console_1.default.error(`Package ${slug} does not exist`);
|
163
|
+
console_1.default.debug(error);
|
164
|
+
throw error;
|
165
|
+
}
|
166
|
+
};
|
167
|
+
const APIError = (error, code) => {
|
168
|
+
const message = error.message || error;
|
169
|
+
const _err = new Error(message);
|
170
|
+
_err.status = code || 400;
|
171
|
+
return _err;
|
172
|
+
};
|
173
|
+
exports.default = { login, publish, update, getPackage, getLangs, getAllPackages };
|
package/lib/utils/audit.d.ts
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
import { IAuditErrors } from "../models/audit";
|
2
|
-
import { IConfigObj } from "../models/config";
|
3
|
-
import { ICounter } from "../models/counter";
|
4
|
-
import { IFindings } from "../models/findings";
|
5
|
-
import { IExercise } from "../models/exercise-obj";
|
6
|
-
declare const _default: {
|
7
|
-
isUrl: (url: string, errors: IAuditErrors[], counter: ICounter) => Promise<boolean>;
|
8
|
-
checkForEmptySpaces: (str: string) => boolean;
|
9
|
-
checkLearnpackClean: (configObj: IConfigObj, errors: IAuditErrors[]) => void;
|
10
|
-
findInFile: (types: string[], content: string) => IFindings;
|
11
|
-
checkUrl: (config: IConfigObj, filePath: string, fileName: string, exercise: IExercise | undefined, errors: IAuditErrors[], warnings: IAuditErrors[], counter: ICounter | undefined) => Promise<boolean>;
|
12
|
-
writeFile: (content: string, filePath: string) => Promise<void>;
|
13
|
-
showErrors: (errors: IAuditErrors[], counter: ICounter | undefined) => Promise<unknown>;
|
14
|
-
showWarnings: (warnings: IAuditErrors[]) => Promise<unknown>;
|
15
|
-
};
|
16
|
-
export default _default;
|
1
|
+
import { IAuditErrors } from "../models/audit";
|
2
|
+
import { IConfigObj } from "../models/config";
|
3
|
+
import { ICounter } from "../models/counter";
|
4
|
+
import { IFindings } from "../models/findings";
|
5
|
+
import { IExercise } from "../models/exercise-obj";
|
6
|
+
declare const _default: {
|
7
|
+
isUrl: (url: string, errors: IAuditErrors[], counter: ICounter) => Promise<boolean>;
|
8
|
+
checkForEmptySpaces: (str: string) => boolean;
|
9
|
+
checkLearnpackClean: (configObj: IConfigObj, errors: IAuditErrors[]) => void;
|
10
|
+
findInFile: (types: string[], content: string) => IFindings;
|
11
|
+
checkUrl: (config: IConfigObj, filePath: string, fileName: string, exercise: IExercise | undefined, errors: IAuditErrors[], warnings: IAuditErrors[], counter: ICounter | undefined) => Promise<boolean>;
|
12
|
+
writeFile: (content: string, filePath: string) => Promise<void>;
|
13
|
+
showErrors: (errors: IAuditErrors[], counter: ICounter | undefined) => Promise<unknown>;
|
14
|
+
showWarnings: (warnings: IAuditErrors[]) => Promise<unknown>;
|
15
|
+
};
|
16
|
+
export default _default;
|