@isardsat/editorial-cli 6.15.0 → 6.17.0

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,70 +1,25 @@
1
1
  import { Command } from "@commander-js/extra-typings";
2
- import { existsSync } from "node:fs";
3
- import { mkdir, writeFile } from "node:fs/promises";
2
+ import { mkdir } from "node:fs/promises";
4
3
  import * as path from "node:path";
4
+ import { configData, dataJson, schemaData, } from "../constants/editorialFiles.js";
5
+ import { createFileIfNotExists } from "../lib/files.js";
5
6
  export const initCommand = new Command()
6
7
  .name("init")
7
- .description("initialize files required for Editorial to function")
8
+ .description("Initialize files required for Editorial to function")
8
9
  .action(async () => {
9
10
  console.log("Initializing editorial...");
10
- // Check if the editorial directory already exists
11
- if (existsSync("./editorial")) {
12
- console.log("Editorial directory already exists!");
13
- return process.exit(1);
14
- }
15
11
  try {
16
12
  await mkdir("./editorial", { recursive: true });
17
13
  console.log("Created Editorial directory");
18
- // Create config.json with basic configuration
19
- const configData = JSON.stringify({
20
- name: "Editorial",
21
- publicUrl: "http://localhost:3001/",
22
- previewUrl: "http://localhost:3001/preview/",
23
- }, null, 2);
24
- await writeFile(path.join("editorial", "config.json"), configData);
25
- console.log("Created config.json");
26
- // Create schema.yaml with a dummy schema
27
- const schemaData = `
28
- # ----------------------------------- Editorial Meta Schema YAML File ------------------------------------
29
- # If you are using an editor that supports JSON Schema, you can use the following URL
30
- # to get validation and autocompletion based on the Editorial meta-schema.
31
- # For example, VSCode with redhat.vscode-yaml extension should work out of the box.
32
- # Make sure to replace "localhost:3001" with the actual address of your Editorial if it's different.
33
- # allowedExtraFields parameter can be used to allow additional fields in the schema that are not defined in the meta-schema.
34
- # Don't uncomment the yaml-language-server line below, it is required for the editor to recognize the schema.
35
- #----------------------------------------------------------------------------------------------------------
36
-
37
- # yaml-language-server: $schema=http://localhost:3001/api/v1/meta-schema
38
-
39
-
40
- # Editorial Schema
41
- dummy:
42
- displayName: Dummy Object
43
- fields:
44
- title:
45
- type: string
46
- displayName: Title
47
- showInSummary: true
48
- body:
49
- type: markdown
50
- displayName: Body
51
- displayExtra: "Write anything you want!"
52
- `;
53
- await writeFile(path.join("editorial", "schema.yaml"), schemaData);
54
- console.log("Created schema.yaml");
55
- // Create data.json with test object
56
- const dataJson = JSON.stringify({
57
- dummy: {
58
- "test-1": {
59
- id: "test-1",
60
- title: "Test Object",
61
- body: "This is a **test** object",
62
- },
63
- },
64
- }, null, 2);
65
- await writeFile(path.join("editorial", "data.json"), dataJson);
66
- console.log("Created data.json");
67
- await mkdir(path.join("public"), { recursive: true });
14
+ const files = [
15
+ { path: "editorial/config.json", content: configData },
16
+ { path: "editorial/schema.yaml", content: schemaData },
17
+ { path: "editorial/data.json", content: dataJson },
18
+ ];
19
+ for (const file of files) {
20
+ await createFileIfNotExists(file.path, file.content);
21
+ }
22
+ await mkdir(path.join("public", "editorialFiles"), { recursive: true });
68
23
  console.log("Created files directory");
69
24
  console.log("Editorial initialized successfully!");
70
25
  }
@@ -0,0 +1,3 @@
1
+ export declare const configData: string;
2
+ export declare const schemaData = "\n# ----------------------------------- Editorial Meta Schema YAML File ------------------------------------\n# If you are using an editor that supports JSON Schema, you can use the following URL\n# to get validation and autocompletion based on the Editorial meta-schema.\n# For example, VSCode with redhat.vscode-yaml extension should work out of the box.\n# Make sure to replace \"localhost:3001\" with the actual address of your Editorial if it's different.\n# allowedExtraFields parameter can be used to allow additional fields in the schema that are not defined in the meta-schema.\n# Don't uncomment the yaml-language-server line below, it is required for the editor to recognize the schema.\n#----------------------------------------------------------------------------------------------------------\n\n# yaml-language-server: $schema=http://localhost:3001/api/v1/meta-schema\n\n# Editorial Schema\ndummy:\n displayName: Dummy Object\n fields:\ntitle:\n type: string\n displayName: Title\n showInSummary: true\nbody:\n type: markdown\n displayName: Body\n displayExtra: \"Write anything you want!\"\n";
3
+ export declare const dataJson: string;
@@ -0,0 +1,52 @@
1
+ export const configData = JSON.stringify({
2
+ name: "Editorial",
3
+ publicUrl: "http://localhost:3001/",
4
+ previewUrl: "http://localhost:3001/preview/",
5
+ publicDir: "public/editorialFiles",
6
+ filesUrl: "",
7
+ largeFilesUrl: "",
8
+ firebase: {
9
+ apiKey: "",
10
+ authDomain: "",
11
+ databaseURL: "",
12
+ projectId: "",
13
+ storageBucket: "",
14
+ messagingSenderId: "",
15
+ appId: "",
16
+ dbUsersPath: "",
17
+ },
18
+ }, null, 2);
19
+ export const schemaData = `
20
+ # ----------------------------------- Editorial Meta Schema YAML File ------------------------------------
21
+ # If you are using an editor that supports JSON Schema, you can use the following URL
22
+ # to get validation and autocompletion based on the Editorial meta-schema.
23
+ # For example, VSCode with redhat.vscode-yaml extension should work out of the box.
24
+ # Make sure to replace "localhost:3001" with the actual address of your Editorial if it's different.
25
+ # allowedExtraFields parameter can be used to allow additional fields in the schema that are not defined in the meta-schema.
26
+ # Don't uncomment the yaml-language-server line below, it is required for the editor to recognize the schema.
27
+ #----------------------------------------------------------------------------------------------------------
28
+
29
+ # yaml-language-server: $schema=http://localhost:3001/api/v1/meta-schema
30
+
31
+ # Editorial Schema
32
+ dummy:
33
+ displayName: Dummy Object
34
+ fields:
35
+ title:
36
+ type: string
37
+ displayName: Title
38
+ showInSummary: true
39
+ body:
40
+ type: markdown
41
+ displayName: Body
42
+ displayExtra: "Write anything you want!"
43
+ `;
44
+ export const dataJson = JSON.stringify({
45
+ dummy: {
46
+ "test-1": {
47
+ id: "test-1",
48
+ title: "Test Object",
49
+ body: "This is a **test** object",
50
+ },
51
+ },
52
+ }, null, 2);
@@ -0,0 +1 @@
1
+ export declare function createFileIfNotExists(filePath: string, content: string): Promise<void>;
@@ -0,0 +1,15 @@
1
+ import { writeFile } from "node:fs/promises";
2
+ export async function createFileIfNotExists(filePath, content) {
3
+ try {
4
+ await writeFile(filePath, content, { flag: "wx" });
5
+ console.log(`Created ${filePath}`);
6
+ }
7
+ catch (err) {
8
+ if (err.code === "EEXIST") {
9
+ console.log(`${filePath} already exists, skipping`);
10
+ }
11
+ else {
12
+ throw err;
13
+ }
14
+ }
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isardsat/editorial-cli",
3
- "version": "6.15.0",
3
+ "version": "6.17.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "@commander-js/extra-typings": "^13.0.0",
15
15
  "@hono/node-server": "^1.13.8",
16
16
  "commander": "^13.1.0",
17
- "@isardsat/editorial-server": "^6.15.0"
17
+ "@isardsat/editorial-server": "^6.17.0"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@tsconfig/node22": "^22.0.0",