@sleetch/cli 1.0.7 → 1.0.9

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.
package/dist/bin/index.js CHANGED
@@ -1,19 +1,19 @@
1
1
  #!/usr/bin/env node
2
- import { t as create_command } from "../create-DWUgFzD_.js";
2
+ import { t as create_command } from "../create-BB8-C6ly.js";
3
3
  import { parseArgs, styleText } from "node:util";
4
+ import { WebsocketServer } from "@sleetch/websockets/server";
4
5
  //#endregion
5
6
  //#region src/bin/index.ts
6
7
  new class sleetch_cli {
7
8
  commands = [];
8
9
  fallback;
9
- constructor() {}
10
10
  add(command) {
11
11
  this.commands.push(command);
12
- if (command.active == true && command.fallback == true) this.fallback = command;
12
+ if (command.active === true && command.fallback === true) this.fallback = command;
13
13
  return this;
14
14
  }
15
15
  resolve(args) {
16
- if (args.length == 0) {
16
+ if (args.length === 0) {
17
17
  if (this.fallback) return {
18
18
  found: true,
19
19
  command: this.fallback,
@@ -26,8 +26,8 @@ new class sleetch_cli {
26
26
  };
27
27
  }
28
28
  const [command_name, ...command_args] = args;
29
- for (const command of this.commands) if (command_name == command.name) {
30
- if (!command.subcommands || command.subcommands.length == 0) {
29
+ for (const command of this.commands) if (command_name === command.name) {
30
+ if (!command.subcommands || command.subcommands.length === 0) {
31
31
  if (command.active) return {
32
32
  found: true,
33
33
  command,
@@ -36,7 +36,7 @@ new class sleetch_cli {
36
36
  else return {
37
37
  found: false,
38
38
  type: "bad option",
39
- error: "inactive command: " + command_name
39
+ error: `inactive command: ${command_name}`
40
40
  };
41
41
  } else {
42
42
  const sub_cli = new sleetch_cli();
@@ -62,7 +62,7 @@ new class sleetch_cli {
62
62
  }
63
63
  run(args) {
64
64
  const resolve = this.resolve(args);
65
- if (resolve.found == true) {
65
+ if (resolve.found === true) {
66
66
  const { command, args } = resolve;
67
67
  const parsed = parseArgs({
68
68
  args,
@@ -97,8 +97,8 @@ new class sleetch_cli {
97
97
  active: true,
98
98
  options: {},
99
99
  fallback: true,
100
- action: (options, cli) => {
101
- let lines = [
100
+ action: (_options, cli) => {
101
+ const lines = [
102
102
  `${styleText("cyan", "sleetch") + styleText("cyanBright", ".dev")} is a powerful documentation framework.`,
103
103
  "",
104
104
  `Usage: ${styleText("cyan", "sleetch")} ${styleText("gray", "<command>")} ${styleText("cyanBright", "[...args]")}`,
@@ -152,6 +152,97 @@ new class sleetch_cli {
152
152
  if (error instanceof Error) cli.error("error", error.message);
153
153
  }
154
154
  }
155
+ }).add({
156
+ name: "studio",
157
+ description: "Start content studio.",
158
+ active: true,
159
+ options: {},
160
+ action: async (options, cli) => {
161
+ try {
162
+ const { studio_events } = await import("@sleetch/core/studio");
163
+ const { sleetch_runtime } = await import("@sleetch/core/compiler");
164
+ const { get_languages, get_tree } = await import("@sleetch/server");
165
+ const token = crypto.randomUUID();
166
+ const server = new WebsocketServer({
167
+ events: studio_events,
168
+ port: 2008,
169
+ path: `/${token}`
170
+ });
171
+ const runtime = new sleetch_runtime();
172
+ await runtime.sources.load();
173
+ await runtime.builder.build();
174
+ await runtime.sources.watch();
175
+ console.log(`Open ${`https://studio.sleetch.dev/?token=${token}`}`);
176
+ server.on("connect", (socket) => {
177
+ server.call({
178
+ id: "get-languages",
179
+ data: {}
180
+ }, socket);
181
+ server.call({
182
+ id: "get-trees",
183
+ data: {}
184
+ }, socket);
185
+ server.call({
186
+ id: "get-sources",
187
+ data: void 0
188
+ }, socket);
189
+ });
190
+ server.on("get-languages", async (_, socket) => {
191
+ await socket.send({
192
+ id: "update-languages",
193
+ data: { languages: await get_languages() }
194
+ });
195
+ });
196
+ server.on("get-trees", async (_, socket) => {
197
+ const languages = await get_languages();
198
+ for (const language of languages) {
199
+ const { tree } = await get_tree(language);
200
+ await socket.send({
201
+ id: "update-tree",
202
+ data: {
203
+ language,
204
+ tree
205
+ }
206
+ });
207
+ }
208
+ });
209
+ server.on("get-tree", async (data, socket) => {
210
+ const { tree, language } = await get_tree(data.language);
211
+ await socket.send({
212
+ id: "update-tree",
213
+ data: {
214
+ language,
215
+ tree
216
+ }
217
+ });
218
+ });
219
+ server.on("get-sources", async (data, socket) => {
220
+ await socket.send({
221
+ id: "update-sources",
222
+ data: { sources: runtime.sources.details() }
223
+ });
224
+ });
225
+ runtime.watcher.on("updated-manifest", async () => {
226
+ const languages = await get_languages();
227
+ server.broadcast({
228
+ id: "update-languages",
229
+ data: { languages }
230
+ });
231
+ });
232
+ runtime.watcher.on("updated-tree", async (language) => {
233
+ const { tree } = await get_tree(language);
234
+ server.broadcast({
235
+ id: "update-tree",
236
+ data: {
237
+ language,
238
+ tree
239
+ }
240
+ });
241
+ });
242
+ } catch (error) {
243
+ if (error instanceof Error) cli.error("error", error.message);
244
+ }
245
+ }
155
246
  }).add(create_command).run(process.argv.slice(2));
156
247
  //#endregion
157
248
  export {};
@@ -3,7 +3,6 @@ import { ParseArgsConfig } from "node:util";
3
3
  declare class sleetch_cli {
4
4
  commands: command[];
5
5
  private fallback?;
6
- constructor();
7
6
  add(command: command): this;
8
7
  resolve(args: string[]): {
9
8
  found: true;
@@ -1,2 +1,2 @@
1
- import { t as create_command } from "../../create-DWUgFzD_.js";
1
+ import { t as create_command } from "../../create-BB8-C6ly.js";
2
2
  export { create_command };
@@ -1,13 +1,13 @@
1
1
  import { createReadStream, createWriteStream, existsSync } from "node:fs";
2
+ import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import path from "node:path";
2
5
  import { pipeline } from "node:stream";
3
6
  import { promisify, styleText } from "node:util";
4
7
  import zlib from "node:zlib";
5
8
  import tar from "tar-fs";
6
- import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
7
- import path from "node:path";
8
- import { tmpdir } from "node:os";
9
9
  //#region package.json
10
- var version = "1.0.7";
10
+ var version = "1.0.9";
11
11
  //#endregion
12
12
  //#region src/commands/create/index.ts
13
13
  const create_command = {
@@ -15,7 +15,7 @@ const create_command = {
15
15
  description: "Create.",
16
16
  options: {},
17
17
  active: false,
18
- action: (options, cli) => {
18
+ action: (options, _cli) => {
19
19
  console.log("create", options);
20
20
  },
21
21
  subcommands: [{
@@ -46,11 +46,11 @@ const create_command = {
46
46
  };
47
47
  const name = options.get_string_option("name");
48
48
  const framework = options.get_string_option("framework");
49
- if (name == void 0) return cli.error("missing arg", "name is missing.");
50
- if (framework == void 0) return cli.error("missing arg", "framework is missing.");
51
- if (!Object.keys(templates).includes(framework)) return cli.error("bad option", "framework must be : " + Object.keys(templates).join(" / "));
49
+ if (name === void 0) return cli.error("missing arg", "name is missing.");
50
+ if (framework === void 0) return cli.error("missing arg", "framework is missing.");
51
+ if (!Object.keys(templates).includes(framework)) return cli.error("bad option", `framework must be : ${Object.keys(templates).join(" / ")}`);
52
52
  const final_template_directory = path.join(cwd, name);
53
- if (existsSync(final_template_directory)) return cli.error("error", final_template_directory + " already exist on your filesystem.");
53
+ if (existsSync(final_template_directory)) return cli.error("error", `${final_template_directory} already exist on your filesystem.`);
54
54
  await mkdir(final_template_directory, { recursive: true });
55
55
  const response = await fetch(source_code_tarball_url);
56
56
  if (response.ok && response.body) {
@@ -72,6 +72,7 @@ const create_command = {
72
72
  lines.push("");
73
73
  lines.push(`Check your project: cd ./${name} `);
74
74
  lines.push(`Install the dependencies: ${styleText("cyan", "bun") + styleText("dim", "/") + styleText("white", "npm") + styleText("dim", "/") + styleText("white", "pnpm")} install`);
75
+ lines.push(`Note: we also have templates for: ${Object.keys(templates).filter((t) => t !== framework).join(", ")} `);
75
76
  lines.push("");
76
77
  lines.push(`Learn more: ${styleText("gray", "https://") + styleText("cyan", "sleetch") + styleText("cyanBright", ".dev")} `);
77
78
  lines.push(` ${styleText("gray", "https://github.com/tornado-softwares/") + styleText("cyan", "sleetch")}`);
package/package.json CHANGED
@@ -1,34 +1,36 @@
1
1
  {
2
- "name": "@sleetch/cli",
3
- "version": "1.0.7",
4
- "type": "module",
5
- "files": [
6
- "dist"
7
- ],
8
- "publishConfig": {
9
- "access": "public"
10
- },
11
- "scripts": {
12
- "build": "tsdown",
13
- "dev": "tsdown --watch"
14
- },
15
- "dependencies": {
16
- "@sleetch/core": "1.0.7",
17
- "tar-fs": "^3.1.3",
18
- "zod": "^4.4.3"
19
- },
20
- "devDependencies": {
21
- "@types/tar-fs": "^2.0.4"
22
- },
23
- "exports": {
24
- "./bin": "./dist/bin/index.js",
25
- "./commands/create": "./dist/commands/create/index.js",
26
- "./package.json": "./package.json"
27
- },
28
- "bin": {
29
- "sleetch": "./dist/bin/index.js"
30
- },
31
- "types": "./dist/index.d.ts",
32
- "main": "./dist/index.js",
33
- "module": "./dist/index.js"
2
+ "name": "@sleetch/cli",
3
+ "version": "1.0.9",
4
+ "type": "module",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "scripts": {
12
+ "build": "tsdown",
13
+ "dev": "tsdown --watch"
14
+ },
15
+ "dependencies": {
16
+ "@sleetch/core": "1.0.9",
17
+ "@sleetch/server": "1.0.9",
18
+ "@sleetch/websockets": "0.0.2",
19
+ "tar-fs": "^3.1.3",
20
+ "zod": "^4.4.3"
21
+ },
22
+ "devDependencies": {
23
+ "@types/tar-fs": "^2.0.4"
24
+ },
25
+ "exports": {
26
+ "./bin": "./dist/bin/index.js",
27
+ "./commands/create": "./dist/commands/create/index.js",
28
+ "./package.json": "./package.json"
29
+ },
30
+ "bin": {
31
+ "sleetch": "./dist/bin/index.js"
32
+ },
33
+ "types": "./dist/index.d.ts",
34
+ "main": "./dist/index.js",
35
+ "module": "./dist/index.js"
34
36
  }