mechanica 1.0.16 → 1.0.17

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.
Files changed (3) hide show
  1. package/bin/bin.js +37 -37
  2. package/bin/compile.js +13 -17
  3. package/package.json +1 -1
package/bin/bin.js CHANGED
@@ -1,37 +1,37 @@
1
- #!/usr/bin/env node
2
- import buildClient from './build.js'
3
- import push from './push.js'
4
- import compile from './compile.js'
5
- import fs from 'fs'
6
- import { join } from 'path'
7
-
8
- const keys = {}
9
- for (let i = 0; i < process.argv.length; i++) {
10
- const key = process.argv[i].slice(2)
11
- if (key.includes("=")) {
12
- const [ newKey, value ] = key.split("=")
13
- keys[newKey] = value
14
- } else {
15
- keys[key] = process.argv[i+1]?.startsWith("--") === false? process.argv[i+1]: true
16
- }
17
- }
18
-
19
- if (process.argv[2] === "build") {
20
- buildClient()
21
- } else if (process.argv[2] === "push") {
22
- try {
23
- if (fs.existsSync(join(process.cwd(), ".env"))) {
24
- const env = fs.readFileSync(join(process.cwd(), ".env"), "utf-8")
25
- const data = Object.fromEntries(env.split("\n").map(item => item.split("=").map(str => str.trim())))
26
- Object.assign(process.env, data)
27
- }
28
- } catch(e) {
29
- console.warn("Failed to parse .env file. Use system env values")
30
- }
31
- push(keys.key ?? process.env.BUILDER_API_KEY, keys.host ?? process.env.BUILDER_HOST ?? "https://builder.jt3.ru", keys.folder)
32
- } else if (process.argv[2] === "export") {
33
- compile()
34
- } else {
35
- console.info(`Use "mechanica build" to build client files`)
36
- console.info(`Use "mechanica push --apiKey=<key> --host=<host> --dir=<dir> to push your builded client files`)
37
- }
1
+ #!/usr/bin/env node
2
+ import buildClient from './build.js'
3
+ import push from './push.js'
4
+ import compile from './compile.js'
5
+ import fs from 'fs'
6
+ import { join } from 'path'
7
+
8
+ const keys = {}
9
+ for (let i = 0; i < process.argv.length; i++) {
10
+ const key = process.argv[i].slice(2)
11
+ if (key.includes("=")) {
12
+ const [ newKey, value ] = key.split("=")
13
+ keys[newKey] = value
14
+ } else {
15
+ keys[key] = process.argv[i+1]?.startsWith("--") === false? process.argv[i+1]: true
16
+ }
17
+ }
18
+
19
+ if (process.argv[2] === "build") {
20
+ buildClient()
21
+ } else if (process.argv[2] === "push") {
22
+ try {
23
+ if (fs.existsSync(join(process.cwd(), ".env"))) {
24
+ const env = fs.readFileSync(join(process.cwd(), ".env"), "utf-8")
25
+ const data = Object.fromEntries(env.split("\n").map(item => item.split("=").map(str => str.trim())))
26
+ Object.assign(process.env, data)
27
+ }
28
+ } catch(e) {
29
+ console.warn("Failed to parse .env file. Use system env values")
30
+ }
31
+ push(keys.key ?? process.env.BUILDER_API_KEY, keys.host ?? process.env.BUILDER_HOST ?? "https://builder.jt3.ru", keys.folder)
32
+ } else if (process.argv[2] === "export") {
33
+ compile()
34
+ } else {
35
+ console.info(`Use "mechanica build" to build client files`)
36
+ console.info(`Use "mechanica push --apiKey=<key> --host=<host> --dir=<dir> to push your builded client files`)
37
+ }
package/bin/compile.js CHANGED
@@ -179,9 +179,9 @@ const getBlockName = (path) => {
179
179
  const str = path.split("/").at(-1);
180
180
  return (str == null ? void 0 : str.split(".", 1)[0].replace(/([A-Z])/g, " $1").trimStart()) ?? "Unnamed block";
181
181
  };
182
- const aliases$1 = {};
183
- const registerAlias$1 = (key, item) => {
184
- aliases$1[key] = item;
182
+ const aliases = {};
183
+ const registerAlias = (key, item) => {
184
+ aliases[key] = item;
185
185
  };
186
186
  const baseTypes = ["string", "boolean", "number", "integer", "bigint", "object", "array"];
187
187
  const isBaseType = (key) => {
@@ -233,11 +233,11 @@ const unfoldArray$1 = (schema2) => {
233
233
  const unfoldSchema = (schema2) => {
234
234
  if (typeof schema2 === "string") {
235
235
  const trimmedType = trimType(schema2);
236
- if (trimmedType in aliases$1) {
236
+ if (trimmedType in aliases) {
237
237
  if (schema2.endsWith("??")) {
238
- return { ...unfoldSchema(aliases$1[trimmedType]), nullable: true };
238
+ return { ...unfoldSchema(aliases[trimmedType]), nullable: true };
239
239
  }
240
- return unfoldSchema(aliases$1[trimmedType]);
240
+ return unfoldSchema(aliases[trimmedType]);
241
241
  }
242
242
  if (schema2.endsWith("??")) {
243
243
  return { type: trimmedType, nullable: true };
@@ -279,17 +279,13 @@ const unfoldSchema = (schema2) => {
279
279
  ...parseObjectFields(schema2, unfoldSchema)
280
280
  };
281
281
  };
282
- const aliases = {};
283
- const registerAlias = (key, item) => {
284
- aliases[key] = item;
285
- };
286
282
  const registerAliases = (registerCallback) => {
287
- const registerAlias$12 = registerCallback ?? registerAlias;
288
- registerAlias$12("image", { type: "object", format: "image", properties: { src: "string", previewSrc: "string?" } });
289
- registerAlias$12("file", { type: "object", format: "file", properties: { src: "string" } });
290
- registerAlias$12("color", { type: "string", format: "color" });
291
- registerAlias$12("smartLink", { type: "object", format: "smartLink", properties: { url: "string", title: "string", external: "boolean" } });
292
- registerAlias$12("richText", {
283
+ const registerAlias$1 = registerCallback ?? registerAlias;
284
+ registerAlias$1("image", { type: "object", format: "image", properties: { src: "string", previewSrc: "string?" } });
285
+ registerAlias$1("file", { type: "object", format: "file", properties: { src: "string" } });
286
+ registerAlias$1("color", { type: "string", format: "color" });
287
+ registerAlias$1("smartLink", { type: "object", format: "smartLink", properties: { url: "string", title: "string", external: "boolean" } });
288
+ registerAlias$1("richText", {
293
289
  type: "array",
294
290
  format: "richText",
295
291
  items: { type: "object", properties: { text: "string", type: "string?", styles: "object?" } }
@@ -361,7 +357,7 @@ const getAvailablePages = async (options) => {
361
357
  };
362
358
  const compile = async () => {
363
359
  console.info("Build client files...");
364
- registerAliases(registerAlias$1);
360
+ registerAliases(registerAlias);
365
361
  process.env.DISABLE_HTML_GENERATE = "true";
366
362
  let baseUrl = "/";
367
363
  let assetsUrl = void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mechanica",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "type": "module",