@learnpack/learnpack 2.1.38 → 2.1.39

Sign up to get free protection for your applications and to get access to all the features.
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.38 darwin-arm64 node-v16.20.0
24
+ @learnpack/learnpack/2.1.39 linux-x64 node-v20.11.1
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.38/src/commands/audit.ts)_
77
+ _See code: [src/commands/audit.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.39/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.38/src/commands/clean.ts)_
92
+ _See code: [src/commands/clean.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.39/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.38/src/commands/download.ts)_
110
+ _See code: [src/commands/download.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.39/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.38/src/commands/init.ts)_
141
+ _See code: [src/commands/init.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.39/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.38/src/commands/login.ts)_
159
+ _See code: [src/commands/login.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.39/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.38/src/commands/logout.ts)_
177
+ _See code: [src/commands/logout.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.39/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.38/src/commands/publish.ts)_
312
+ _See code: [src/commands/publish.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.39/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.38/src/commands/start.ts)_
333
+ _See code: [src/commands/start.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.39/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.38/src/commands/test.ts)_
347
+ _See code: [src/commands/test.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.39/src/commands/test.ts)_
348
348
  <!-- commandsstop -->
349
349
 
350
350
  > > > > > > > 0cb3e56d84c197f9d008836bb573eade212b7e57
@@ -23,6 +23,7 @@ class StartCommand extends SessionCommand_1.default {
23
23
  // get configuration object
24
24
  const configObject = (_a = this.configManager) === null || _a === void 0 ? void 0 : _a.get();
25
25
  const config = configObject === null || configObject === void 0 ? void 0 : configObject.config;
26
+ const hasXDG = await osOperations_1.eventManager.checkXDGInstalled();
26
27
  if (configObject) {
27
28
  const { config } = configObject;
28
29
  // build exerises
@@ -80,11 +81,13 @@ class StartCommand extends SessionCommand_1.default {
80
81
  });
81
82
  socket_1.default.on("open_window", (data) => {
82
83
  console_1.default.debug("Opening window: ", data);
83
- // if (config.editor.agent === "os") {
84
- // } else {
85
- // dispatcher.enqueue(dispatcher.events.OPEN_WINDOW, data);
86
- // }
87
- osOperations_1.eventManager.enqueue(dispatcher.events.OPEN_WINDOW, data);
84
+ if (config.editor.agent === "os" &&
85
+ ((config.os === "linux" && hasXDG) || config.os !== "linux")) {
86
+ osOperations_1.eventManager.enqueue(dispatcher.events.OPEN_WINDOW, data);
87
+ }
88
+ else {
89
+ dispatcher.enqueue(dispatcher.events.OPEN_WINDOW, data);
90
+ }
88
91
  socket_1.default.ready("Ready to compile...");
89
92
  });
90
93
  socket_1.default.on("reset", (exercise) => {
@@ -111,12 +111,13 @@ exports.default = async ({ grading, mode, disableGrading, version, }) => {
111
111
  console_1.default.debug("Gitpod detected");
112
112
  configObj.address = getGitpodAddress();
113
113
  configObj.config.publicUrl = `https://${configObj.config.port}-${(_d = configObj.address) === null || _d === void 0 ? void 0 : _d.slice(8)}`;
114
+ configObj.config.editor.agent = "vscode";
114
115
  }
115
116
  else if (configObj.config && Boolean(codespaces_workspace)) {
116
117
  console_1.default.debug("Codespaces detected: ", codespaces_workspace);
117
118
  configObj.address = `https://${codespaces_workspace}.github.dev`;
118
119
  configObj.config.publicUrl = `https://${codespaces_workspace}-${configObj.config.port}.app.github.dev`;
119
- // TODO: Why is needed to have an agent?
120
+ configObj.config.editor.agent = "vscode";
120
121
  }
121
122
  else {
122
123
  console_1.default.debug("Neither Gitpod nor Codespaces detected, using localhost.");
@@ -124,9 +125,9 @@ exports.default = async ({ grading, mode, disableGrading, version, }) => {
124
125
  configObj.config.publicUrl = `http://localhost:${configObj.config.port}`;
125
126
  }
126
127
  if (!configObj.config.editor.agent) {
127
- configObj.config.editor.agent = shell.which("code") ? "vscode" : "os";
128
+ configObj.config.editor.agent =
129
+ process.env.TERM_PROGRAM === "vscode" ? "vscode" : "os";
128
130
  }
129
- // TODO: We need to set the correct EventListener if the agent is not vscode
130
131
  if (configObj.config && !configObj.config.publicUrl)
131
132
  configObj.config.publicUrl = `${configObj.address}:${configObj.config.port}`;
132
133
  if (configObj.config && !configObj.config.editor.mode && mode) {
@@ -1,4 +1,5 @@
1
1
  declare const eventManager: {
2
2
  enqueue: (event: string, data: any) => void;
3
+ checkXDGInstalled: () => Promise<boolean>;
3
4
  };
4
5
  export { eventManager };
@@ -5,6 +5,21 @@ const child_process_1 = require("child_process");
5
5
  const os = require("os");
6
6
  const path = require("path");
7
7
  const cli_ux_1 = require("cli-ux");
8
+ const checkXDGInstalled = () => {
9
+ return new Promise((resolve, reject) => {
10
+ child_process_1.exec("which xdg-open", (error, stdout, stderr) => {
11
+ if (error) {
12
+ resolve(false);
13
+ }
14
+ if (stdout) {
15
+ resolve(true);
16
+ }
17
+ else {
18
+ resolve(false);
19
+ }
20
+ });
21
+ });
22
+ };
8
23
  const openFile = (filePath) => {
9
24
  const fullPath = path.join(process.cwd(), filePath);
10
25
  let command;
@@ -52,5 +67,6 @@ const eventManager = {
52
67
  cli_ux_1.default.open(url);
53
68
  }
54
69
  },
70
+ checkXDGInstalled,
55
71
  };
56
72
  exports.eventManager = eventManager;
@@ -1 +1 @@
1
- {"version":"2.1.38","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}]}}}
1
+ {"version":"2.1.39","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,7 +1,7 @@
1
1
  {
2
2
  "name": "@learnpack/learnpack",
3
3
  "description": "Create, sell or download and take learning amazing learning packages",
4
- "version": "2.1.38",
4
+ "version": "2.1.39",
5
5
  "author": "Alejandro Sanchez @alesanchezr",
6
6
  "bin": {
7
7
  "learnpack": "bin/run"
@@ -67,7 +67,6 @@
67
67
  "fs-extra": "^10.0.1",
68
68
  "globby": "^10.0.2",
69
69
  "husky": ">=6",
70
- "learnpack-node": "^0.0.21",
71
70
  "lint-staged": ">=10",
72
71
  "mocha": "^5.2.0",
73
72
  "mock-fs": "^5.1.2",
@@ -70,6 +70,8 @@ export default class StartCommand extends SessionCommand {
70
70
  const configObject = this.configManager?.get()
71
71
  const config = configObject?.config
72
72
 
73
+ const hasXDG = await eventManager.checkXDGInstalled()
74
+
73
75
  if (configObject) {
74
76
  const { config } = configObject
75
77
 
@@ -164,11 +166,16 @@ export default class StartCommand extends SessionCommand {
164
166
 
165
167
  socket.on("open_window", (data: IGitpodData) => {
166
168
  Console.debug("Opening window: ", data)
167
- // if (config.editor.agent === "os") {
168
- // } else {
169
- // dispatcher.enqueue(dispatcher.events.OPEN_WINDOW, data);
170
- // }
171
- eventManager.enqueue(dispatcher.events.OPEN_WINDOW, data)
169
+
170
+ if (
171
+ config.editor.agent === "os" &&
172
+ ((config.os === "linux" && hasXDG) || config.os !== "linux")
173
+ ) {
174
+ eventManager.enqueue(dispatcher.events.OPEN_WINDOW, data)
175
+ } else {
176
+ dispatcher.enqueue(dispatcher.events.OPEN_WINDOW, data)
177
+ }
178
+
172
179
  socket.ready("Ready to compile...")
173
180
  })
174
181
 
@@ -7,7 +7,7 @@ export default {
7
7
  })(),
8
8
  editor: {
9
9
  mode: null, // [extension, preview]
10
- agent: null, // [vscode, null]
10
+ agent: null, // ["vscode", "os"] ("os" is the agent when running outside a coding editor
11
11
  version: null, // By default downloads the latest version
12
12
  },
13
13
  dirPath: "./.learn",
@@ -164,11 +164,12 @@ throw InternalError("Config object not found")
164
164
  configObj.config.publicUrl = `https://${
165
165
  configObj.config.port
166
166
  }-${configObj.address?.slice(8)}`
167
+ configObj.config.editor.agent = "vscode"
167
168
  } else if (configObj.config && Boolean(codespaces_workspace)) {
168
169
  Console.debug("Codespaces detected: ", codespaces_workspace)
169
170
  configObj.address = `https://${codespaces_workspace}.github.dev`
170
171
  configObj.config.publicUrl = `https://${codespaces_workspace}-${configObj.config.port}.app.github.dev`
171
- // TODO: Why is needed to have an agent?
172
+ configObj.config.editor.agent = "vscode"
172
173
  } else {
173
174
  Console.debug("Neither Gitpod nor Codespaces detected, using localhost.")
174
175
  configObj.address = `http://localhost:${configObj.config.port}`
@@ -176,11 +177,10 @@ throw InternalError("Config object not found")
176
177
  }
177
178
 
178
179
  if (!configObj.config.editor.agent) {
179
- configObj.config.editor.agent = shell.which("code") ? "vscode" : "os"
180
+ configObj.config.editor.agent =
181
+ process.env.TERM_PROGRAM === "vscode" ? "vscode" : "os"
180
182
  }
181
183
 
182
- // TODO: We need to set the correct EventListener if the agent is not vscode
183
-
184
184
  if (configObj.config && !configObj.config.publicUrl)
185
185
  configObj.config.publicUrl = `${configObj.address}:${configObj.config.port}`
186
186
 
@@ -3,6 +3,22 @@ import * as os from "os"
3
3
  import * as path from "path"
4
4
  import cli from "cli-ux"
5
5
 
6
+ const checkXDGInstalled = (): Promise<boolean> => {
7
+ return new Promise((resolve, reject) => {
8
+ exec("which xdg-open", (error, stdout, stderr) => {
9
+ if (error) {
10
+ resolve(false)
11
+ }
12
+
13
+ if (stdout) {
14
+ resolve(true)
15
+ } else {
16
+ resolve(false)
17
+ }
18
+ })
19
+ })
20
+ }
21
+
6
22
  const openFile = (filePath: string): void => {
7
23
  const fullPath = path.join(process.cwd(), filePath)
8
24
  let command: string
@@ -24,7 +40,6 @@ const openFile = (filePath: string): void => {
24
40
  exec(command, (error, stdout, stderr) => {
25
41
  if (error) {
26
42
  console.error(`exec error: ${error}`)
27
-
28
43
  }
29
44
  })
30
45
  }
@@ -58,6 +73,7 @@ const eventManager = {
58
73
  cli.open(url)
59
74
  }
60
75
  },
76
+ checkXDGInstalled,
61
77
  }
62
78
 
63
79
  export { eventManager }