@learnpack/learnpack 5.0.9 → 5.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. package/README.md +17 -17
  2. package/bin/run +17 -17
  3. package/bin/run.cmd +3 -3
  4. package/lib/commands/audit.js +24 -27
  5. package/lib/commands/clean.js +3 -3
  6. package/lib/commands/download.js +3 -3
  7. package/lib/commands/login.js +3 -3
  8. package/lib/commands/logout.js +3 -3
  9. package/lib/commands/publish.js +8 -7
  10. package/lib/managers/config/index.d.ts +0 -10
  11. package/lib/managers/config/index.js +11 -3
  12. package/lib/managers/session.js +1 -1
  13. package/lib/utils/checkNotInstalled.js +3 -5
  14. package/oclif.manifest.json +1 -1
  15. package/package.json +152 -152
  16. package/src/commands/audit.ts +449 -449
  17. package/src/commands/clean.ts +29 -29
  18. package/src/commands/download.ts +61 -61
  19. package/src/commands/login.ts +42 -42
  20. package/src/commands/logout.ts +43 -43
  21. package/src/commands/publish.ts +9 -7
  22. package/src/commands/test.ts +85 -85
  23. package/src/index.ts +1 -1
  24. package/src/managers/config/allowed_files.ts +29 -29
  25. package/src/managers/config/index.ts +16 -6
  26. package/src/managers/gitpod.ts +84 -84
  27. package/src/managers/server/index.ts +78 -78
  28. package/src/managers/session.ts +2 -1
  29. package/src/managers/telemetry.ts +353 -353
  30. package/src/managers/test.ts +83 -83
  31. package/src/models/audit.ts +16 -16
  32. package/src/models/config-manager.ts +23 -23
  33. package/src/models/counter.ts +11 -11
  34. package/src/models/errors.ts +22 -22
  35. package/src/models/exercise-obj.ts +29 -29
  36. package/src/models/file.ts +5 -5
  37. package/src/models/findings.ts +18 -18
  38. package/src/models/flags.ts +10 -10
  39. package/src/models/front-matter.ts +11 -11
  40. package/src/models/gitpod-data.ts +19 -19
  41. package/src/models/language.ts +4 -4
  42. package/src/models/package.ts +7 -7
  43. package/src/models/plugin-config.ts +17 -17
  44. package/src/models/success-types.ts +1 -1
  45. package/src/plugin/command/compile.ts +17 -17
  46. package/src/plugin/command/test.ts +30 -30
  47. package/src/plugin/index.ts +6 -6
  48. package/src/plugin/plugin.ts +94 -94
  49. package/src/plugin/utils.ts +87 -87
  50. package/src/types/node-fetch.d.ts +1 -1
  51. package/src/ui/download.ts +71 -71
  52. package/src/utils/BaseCommand.ts +48 -48
  53. package/src/utils/SessionCommand.ts +43 -43
  54. package/src/utils/audit.ts +393 -393
  55. package/src/utils/checkNotInstalled.ts +10 -12
  56. package/src/utils/errors.ts +117 -117
  57. package/src/utils/exercisesQueue.ts +51 -51
  58. package/src/utils/fileQueue.ts +199 -199
  59. package/src/utils/misc.ts +23 -23
  60. package/src/utils/osOperations.ts +79 -79
  61. package/src/utils/templates/gitignore.txt +19 -19
  62. package/src/utils/templates/incremental/.learn/exercises/01-hello-world/README.es.md +24 -24
  63. package/src/utils/templates/incremental/.learn/exercises/01-hello-world/README.md +24 -24
  64. package/src/utils/templates/incremental/.vscode/schema.json +121 -121
  65. package/src/utils/templates/incremental/.vscode/settings.json +13 -13
  66. package/src/utils/templates/incremental/README.ejs +4 -4
  67. package/src/utils/templates/incremental/README.es.ejs +4 -4
  68. package/src/utils/templates/isolated/.vscode/schema.json +121 -121
  69. package/src/utils/templates/isolated/.vscode/settings.json +13 -13
  70. package/src/utils/templates/isolated/README.ejs +4 -4
  71. package/src/utils/templates/isolated/README.es.ejs +4 -4
  72. package/src/utils/templates/no-grading/README.ejs +4 -4
  73. package/src/utils/templates/no-grading/README.es.ejs +4 -4
  74. package/src/utils/validators.ts +18 -18
  75. package/src/utils/watcher.ts +27 -27
@@ -1,84 +1,84 @@
1
- import Console from '../utils/console'
2
- import * as shell from 'shelljs'
3
- import socket from './socket'
4
- import * as fs from 'fs'
5
-
6
- import {TFile, IGitpod} from '../models/gitpod-data'
7
- import {IConfigObj} from '../models/config'
8
-
9
- const Gitpod: IGitpod = {
10
- socket: null,
11
- config: null,
12
- initialized: false,
13
- hasGPCommand: false,
14
- init: function (config?: IConfigObj) {
15
- if (this.initialized) {
16
- return
17
- }
18
-
19
- this.initialized = true
20
-
21
- if (config) {
22
- this.config = config
23
- }
24
-
25
- if (shell.exec('gp -h', {silent: true}).code === 0) {
26
- this.hasGPCommand = true
27
- if (config) {
28
- config.address = shell
29
- .exec('gp url', {silent: true})
30
- .stdout.replace(/(\r\n|\n|\r)/gm, '')
31
- }
32
- } else {
33
- Console.debug('Gitpod command line tool not found')
34
- }
35
- },
36
- openFiles: async function (files: Array<TFile>) {
37
- Console.debug('Attempting to open files in gitpod mode', files)
38
- this.init() // initilize gitpod config
39
-
40
- // gitpod will open files only on isolated mode
41
- if (!this.config || this.config.config?.grading !== 'isolated') {
42
- Console.debug(
43
- 'Files cannot be automatically opened because we are not on isolated grading (only for isolated)',
44
- )
45
- socket.log('ready', ['Ready to compile or test...'])
46
- return true
47
- }
48
-
49
- if (this.hasGPCommand)
50
- for (const f of files.reverse()) {
51
- if (shell.exec(`gp open ${f}`).code > 0) {
52
- Console.debug(`Error opening file ${f} on gitpod`)
53
- }
54
- }
55
-
56
- socket.log('ready', ['Ready to compile or test...'])
57
- },
58
- setup(config?: IConfigObj) {
59
- this.init(config) // initilize gitpod config
60
- this.autosave('on')
61
- },
62
- autosave: async function (value = 'on') {
63
- this.init() // initilize gitpod config
64
-
65
- if (this.hasGPCommand) {
66
- if (!fs.existsSync('./.theia'))
67
- fs.mkdirSync('./.theia')
68
- if (!fs.existsSync('./.theia/settings.json')) {
69
- fs.writeFileSync(
70
- './.theia/settings.json',
71
- JSON.stringify(
72
- {
73
- 'editor.autoSave': value,
74
- },
75
- null,
76
- 4,
77
- ),
78
- )
79
- }
80
- }
81
- },
82
- }
83
-
84
- export default Gitpod
1
+ import Console from '../utils/console'
2
+ import * as shell from 'shelljs'
3
+ import socket from './socket'
4
+ import * as fs from 'fs'
5
+
6
+ import {TFile, IGitpod} from '../models/gitpod-data'
7
+ import {IConfigObj} from '../models/config'
8
+
9
+ const Gitpod: IGitpod = {
10
+ socket: null,
11
+ config: null,
12
+ initialized: false,
13
+ hasGPCommand: false,
14
+ init: function (config?: IConfigObj) {
15
+ if (this.initialized) {
16
+ return
17
+ }
18
+
19
+ this.initialized = true
20
+
21
+ if (config) {
22
+ this.config = config
23
+ }
24
+
25
+ if (shell.exec('gp -h', {silent: true}).code === 0) {
26
+ this.hasGPCommand = true
27
+ if (config) {
28
+ config.address = shell
29
+ .exec('gp url', {silent: true})
30
+ .stdout.replace(/(\r\n|\n|\r)/gm, '')
31
+ }
32
+ } else {
33
+ Console.debug('Gitpod command line tool not found')
34
+ }
35
+ },
36
+ openFiles: async function (files: Array<TFile>) {
37
+ Console.debug('Attempting to open files in gitpod mode', files)
38
+ this.init() // initilize gitpod config
39
+
40
+ // gitpod will open files only on isolated mode
41
+ if (!this.config || this.config.config?.grading !== 'isolated') {
42
+ Console.debug(
43
+ 'Files cannot be automatically opened because we are not on isolated grading (only for isolated)',
44
+ )
45
+ socket.log('ready', ['Ready to compile or test...'])
46
+ return true
47
+ }
48
+
49
+ if (this.hasGPCommand)
50
+ for (const f of files.reverse()) {
51
+ if (shell.exec(`gp open ${f}`).code > 0) {
52
+ Console.debug(`Error opening file ${f} on gitpod`)
53
+ }
54
+ }
55
+
56
+ socket.log('ready', ['Ready to compile or test...'])
57
+ },
58
+ setup(config?: IConfigObj) {
59
+ this.init(config) // initilize gitpod config
60
+ this.autosave('on')
61
+ },
62
+ autosave: async function (value = 'on') {
63
+ this.init() // initilize gitpod config
64
+
65
+ if (this.hasGPCommand) {
66
+ if (!fs.existsSync('./.theia'))
67
+ fs.mkdirSync('./.theia')
68
+ if (!fs.existsSync('./.theia/settings.json')) {
69
+ fs.writeFileSync(
70
+ './.theia/settings.json',
71
+ JSON.stringify(
72
+ {
73
+ 'editor.autoSave': value,
74
+ },
75
+ null,
76
+ 4,
77
+ ),
78
+ )
79
+ }
80
+ }
81
+ },
82
+ }
83
+
84
+ export default Gitpod
@@ -1,78 +1,78 @@
1
- import * as express from "express"
2
- // eslint-disable-next-line
3
- import * as cors from "cors";
4
- import * as http from "http"
5
- import Console from "../../utils/console"
6
- import addRoutes from "./routes"
7
- import cli from "cli-ux"
8
- import { IConfigObj } from "../../models/config"
9
- import { IConfigManager } from "../../models/config-manager"
10
-
11
- export let TEST_SERVER: http.Server
12
-
13
- export default async function (
14
- configObj: IConfigObj,
15
- configManager: IConfigManager,
16
- isTestingEnvironment = false
17
- ) {
18
- const { config } = configObj
19
- const app = express()
20
- let server: any
21
-
22
- if (isTestingEnvironment) {
23
- if (TEST_SERVER === undefined)
24
- TEST_SERVER = require("http").Server(app)
25
- server = TEST_SERVER
26
- } else
27
- server = require("http").Server(app)
28
-
29
- app.use(cors())
30
-
31
- // app.use(function(req, res, next) {
32
- // res.header("Access-Control-Allow-Origin", "*")
33
- // res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
34
- // res.header("Access-Control-Allow-Methods", "GET,PUT")
35
- // next()
36
- // })
37
-
38
- // add all needed endpoints
39
-
40
- await addRoutes(app, configObj, configManager)
41
-
42
- server.listen(isTestingEnvironment ? 5000 : config?.port, function () {
43
- if (!isTestingEnvironment) {
44
- Console.success(
45
- `Exercises are running 😃 Open your browser to start practicing!`
46
- )
47
- Console.success(`\n Open the exercise on this link:`)
48
- Console.log(` ${config?.publicUrl}`)
49
-
50
- if (config?.editor.mode === "preview")
51
- cli.open(`${config.publicUrl}`)
52
- }
53
- })
54
-
55
- const sockets: any = new Set()
56
-
57
- server.on("connection", (socket: any) => {
58
- sockets.add(socket)
59
-
60
- server.once("close", () => {
61
- sockets.delete(socket)
62
- })
63
- })
64
-
65
- /**
66
- * Forcefully terminates HTTP server.
67
- */
68
- server.terminate = (callback: void) => {
69
- for (const socket of sockets) {
70
- socket.destroy()
71
- sockets.delete(socket)
72
- }
73
-
74
- server.close(callback)
75
- }
76
-
77
- return server
78
- }
1
+ import * as express from "express"
2
+ // eslint-disable-next-line
3
+ import * as cors from "cors";
4
+ import * as http from "http"
5
+ import Console from "../../utils/console"
6
+ import addRoutes from "./routes"
7
+ import cli from "cli-ux"
8
+ import { IConfigObj } from "../../models/config"
9
+ import { IConfigManager } from "../../models/config-manager"
10
+
11
+ export let TEST_SERVER: http.Server
12
+
13
+ export default async function (
14
+ configObj: IConfigObj,
15
+ configManager: IConfigManager,
16
+ isTestingEnvironment = false
17
+ ) {
18
+ const { config } = configObj
19
+ const app = express()
20
+ let server: any
21
+
22
+ if (isTestingEnvironment) {
23
+ if (TEST_SERVER === undefined)
24
+ TEST_SERVER = require("http").Server(app)
25
+ server = TEST_SERVER
26
+ } else
27
+ server = require("http").Server(app)
28
+
29
+ app.use(cors())
30
+
31
+ // app.use(function(req, res, next) {
32
+ // res.header("Access-Control-Allow-Origin", "*")
33
+ // res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
34
+ // res.header("Access-Control-Allow-Methods", "GET,PUT")
35
+ // next()
36
+ // })
37
+
38
+ // add all needed endpoints
39
+
40
+ await addRoutes(app, configObj, configManager)
41
+
42
+ server.listen(isTestingEnvironment ? 5000 : config?.port, function () {
43
+ if (!isTestingEnvironment) {
44
+ Console.success(
45
+ `Exercises are running 😃 Open your browser to start practicing!`
46
+ )
47
+ Console.success(`\n Open the exercise on this link:`)
48
+ Console.log(` ${config?.publicUrl}`)
49
+
50
+ if (config?.editor.mode === "preview")
51
+ cli.open(`${config.publicUrl}`)
52
+ }
53
+ })
54
+
55
+ const sockets: any = new Set()
56
+
57
+ server.on("connection", (socket: any) => {
58
+ sockets.add(socket)
59
+
60
+ server.once("close", () => {
61
+ sockets.delete(socket)
62
+ })
63
+ })
64
+
65
+ /**
66
+ * Forcefully terminates HTTP server.
67
+ */
68
+ server.terminate = (callback: void) => {
69
+ for (const socket of sockets) {
70
+ socket.destroy()
71
+ sockets.delete(socket)
72
+ }
73
+
74
+ server.close(callback)
75
+ }
76
+
77
+ return server
78
+ }
@@ -112,10 +112,11 @@ const Session: ISession = {
112
112
  })
113
113
 
114
114
  const data = await api.login(email, password)
115
+
115
116
  if (data) {
116
117
  Console.debug("Login successfull")
117
118
  // cli.log(data)
118
- this.start({ token: data.token, payload: data })
119
+ await this.start({ token: data.token, payload: data })
119
120
  return data
120
121
  }
121
122
  },