@kokimoki/kit 1.3.0 → 1.5.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.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from "./kokimoki-kit-plugin";
2
2
  export * from "./preprocess-style";
3
- export * from "./schema-builder";
package/dist/index.js CHANGED
@@ -16,4 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./kokimoki-kit-plugin"), exports);
18
18
  __exportStar(require("./preprocess-style"), exports);
19
- __exportStar(require("./schema-builder"), exports);
@@ -1,12 +1,14 @@
1
1
  import type { Plugin } from "vite";
2
- import type { Form } from "./schema-builder";
2
+ import { ZodTypeAny } from "zod";
3
3
  export interface KokimokiKitConfig {
4
4
  conceptId: string;
5
- form: Form<any, any>;
5
+ schema: ZodTypeAny;
6
6
  deployCodes: {
7
7
  name: string;
8
8
  description: string;
9
9
  clientContext: any;
10
10
  }[];
11
+ defaultProjectConfigPath?: string;
12
+ defaultProjectStylePath?: string;
11
13
  }
12
14
  export declare function kokimokiKitPlugin(config: KokimokiKitConfig): Plugin;
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
@@ -8,18 +31,21 @@ const bson_objectid_1 = __importDefault(require("bson-objectid"));
8
31
  const promises_1 = __importDefault(require("fs/promises"));
9
32
  const preprocess_style_1 = require("./preprocess-style");
10
33
  const version_1 = require("./version");
34
+ const yaml = __importStar(require("yaml"));
35
+ const zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema"));
11
36
  function kokimokiKitPlugin(config) {
12
37
  return {
13
38
  name: "kokimoki-kit",
14
39
  async transform(code, id) {
15
40
  if (id.endsWith("kokimoki.style.css")) {
41
+ console.warn(`[kokimoki-kit] importing kokimoki.style.css directly is deprecated, use defaultProjectStylePath instead`);
16
42
  return (0, preprocess_style_1.preprocessStyle)(code);
17
43
  }
18
44
  return code;
19
45
  },
20
46
  async transformIndexHtml(html) {
21
- // NOTE: Try https://github.com/jsdom/jsdom instead of regex parsing
22
47
  if (process.env.NODE_ENV !== "development") {
48
+ // NOTE: Try https://github.com/jsdom/jsdom instead of regex parsing
23
49
  return html
24
50
  .replace("<head>", `<head>
25
51
  <base href="%KM_BASE%">
@@ -79,6 +105,12 @@ function kokimokiKitPlugin(config) {
79
105
  appId = new bson_objectid_1.default().toHexString();
80
106
  await promises_1.default.writeFile(".kokimoki/app-id", appId);
81
107
  }
108
+ // Get default config
109
+ let defaultProjectConfig = config.schema.parse(undefined);
110
+ if (config.defaultProjectConfigPath) {
111
+ const defaultProjectConfigFile = await promises_1.default.readFile(config.defaultProjectConfigPath, "utf8");
112
+ defaultProjectConfig = yaml.parse(defaultProjectConfigFile);
113
+ }
82
114
  // Inject the app id into the index.html
83
115
  html = html.replace("<head>", `<head>
84
116
  <script id="kokimoki-env" type="application/json">
@@ -87,11 +119,16 @@ function kokimokiKitPlugin(config) {
87
119
  "test": true,
88
120
  "host": "y-wss.kokimoki.com",
89
121
  "appId": "${appId}",
90
- "configObject": ${JSON.stringify(config.form.value)},
122
+ "configObject": ${JSON.stringify(defaultProjectConfig)},
91
123
  "base": "/",
92
124
  "assets": "/"
93
125
  }
94
126
  </script>`);
127
+ // Inject default project style in development
128
+ if (config.defaultProjectStylePath) {
129
+ const defaultProjectStyle = await promises_1.default.readFile(config.defaultProjectStylePath, "utf8");
130
+ html = html.replace("</body>", `<style id="km-dev-style">${(0, preprocess_style_1.preprocessStyle)(defaultProjectStyle)}</style></body>`);
131
+ }
95
132
  return html;
96
133
  },
97
134
  // write kokimoki metadata to .kokimoki directory
@@ -102,13 +139,34 @@ function kokimokiKitPlugin(config) {
102
139
  conceptId: config.conceptId,
103
140
  deployCodes: config.deployCodes,
104
141
  build: "dist",
142
+ defaultProjectConfigPath: config.defaultProjectConfigPath,
143
+ defaultProjectStylePath: config.defaultProjectStylePath,
105
144
  }, null, 2));
106
145
  // write schema
107
- const schema = JSON.stringify(config.form.schema, null, 2);
108
- await promises_1.default.writeFile(".kokimoki/schema.json", schema);
109
- // write scheme defaults
110
- const defaultValue = JSON.stringify(config.form.value, null, 2);
111
- await promises_1.default.writeFile(".kokimoki/schema-defaults.json", defaultValue);
146
+ const jsonSchema = (0, zod_to_json_schema_1.default)(config.schema);
147
+ const defaultJsonSchemaValue = config.schema.parse(undefined);
148
+ await promises_1.default.writeFile(".kokimoki/schema.json", JSON.stringify(jsonSchema, null, 2));
149
+ // write schema defaults as json
150
+ await promises_1.default.writeFile(".kokimoki/schema-defaults.json", JSON.stringify(defaultJsonSchemaValue, null, 2));
151
+ // write schema defaults as yaml
152
+ await promises_1.default.writeFile(".kokimoki/schema-defaults.yaml", yaml.stringify(defaultJsonSchemaValue));
153
+ },
154
+ configureServer(server) {
155
+ // reload when defaultProjectConfigPath or defaultProjectStylePath changes
156
+ if (config.defaultProjectConfigPath) {
157
+ server.watcher.add(config.defaultProjectConfigPath);
158
+ }
159
+ if (config.defaultProjectStylePath) {
160
+ server.watcher.add(config.defaultProjectStylePath);
161
+ }
162
+ server.watcher.on("change", (file) => {
163
+ if (config.defaultProjectConfigPath?.match(file) ||
164
+ config.defaultProjectStylePath?.match(file)) {
165
+ server.ws.send({
166
+ type: "full-reload",
167
+ });
168
+ }
169
+ });
112
170
  },
113
171
  };
114
172
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const preprocess_style_1 = require("./preprocess-style");
7
+ const assert_1 = __importDefault(require("assert"));
8
+ describe("rgb-utils", () => {
9
+ // data-theme detection
10
+ describe("data-theme detection", () => {
11
+ it("should transform data-theme=gfc content", () => {
12
+ const result = (0, preprocess_style_1.preprocessStyle)(`[data-theme=gfc] { --on-primary: #aabbcc; }`);
13
+ assert_1.default.equal(result, `[data-theme="gfc"] { --on-primary: 170 187 204; }`);
14
+ });
15
+ it("should transform data-theme='gfc' content", () => {
16
+ const result = (0, preprocess_style_1.preprocessStyle)(`[data-theme='gfc'] { --on-primary: #aabbcc; }`);
17
+ assert_1.default.equal(result, `[data-theme="gfc"] { --on-primary: 170 187 204; }`);
18
+ });
19
+ it('should transform data-theme="gfc" content', () => {
20
+ const result = (0, preprocess_style_1.preprocessStyle)(`[data-theme="gfc"] { --on-primary: #aabbcc; }`);
21
+ assert_1.default.equal(result, `[data-theme="gfc"] { --on-primary: 170 187 204; }`);
22
+ });
23
+ });
24
+ // gfc skeleton theme system
25
+ describe("gfc", () => {
26
+ it("should transform --on-primary hex value to rgb tuple", () => {
27
+ const result = (0, preprocess_style_1.preprocessStyle)(`[data-theme="gfc"] { --on-primary: #aabbcc; }`);
28
+ assert_1.default.equal(result, `[data-theme="gfc"] { --on-primary: 170 187 204; }`);
29
+ });
30
+ it("should generate color palette for --color-primary", () => {
31
+ const result = (0, preprocess_style_1.preprocessStyle)(`[data-theme="gfc"] { --color-primary: #ff0000; }`);
32
+ (0, assert_1.default)(result.includes("--color-primary-50:"));
33
+ (0, assert_1.default)(result.includes("--color-primary-100:"));
34
+ (0, assert_1.default)(result.includes("--color-primary-200:"));
35
+ (0, assert_1.default)(result.includes("--color-primary-300:"));
36
+ (0, assert_1.default)(result.includes("--color-primary-400:"));
37
+ (0, assert_1.default)(result.includes("--color-primary-500:"));
38
+ (0, assert_1.default)(result.includes("--color-primary-600:"));
39
+ (0, assert_1.default)(result.includes("--color-primary-700:"));
40
+ (0, assert_1.default)(result.includes("--color-primary-800:"));
41
+ (0, assert_1.default)(result.includes("--color-primary-900:"));
42
+ });
43
+ it("should not transform --p variable", () => {
44
+ const result = (0, preprocess_style_1.preprocessStyle)(`[data-theme="gfc"] { --p: white; }`);
45
+ assert_1.default.equal(result, `[data-theme="gfc"] { --p: white; }`);
46
+ });
47
+ });
48
+ // daisy theme system
49
+ describe("daisy", () => {
50
+ for (const theme of ["light", "dark"]) {
51
+ describe(theme, () => {
52
+ it("should transform theme name", () => {
53
+ const result = (0, preprocess_style_1.preprocessStyle)(`[data-theme="daisy-${theme}"] {}`);
54
+ assert_1.default.equal(result, `[data-theme="${theme}"] {}`);
55
+ });
56
+ it("should transform variables from hex to oklch tuple", () => {
57
+ const result = (0, preprocess_style_1.preprocessStyle)(`[data-theme="daisy-${theme}"] {\n--p: #7480ff;\n--pc: #050617;\n--b1: #1d232a;\n--bc: #a6adbb;\n}`);
58
+ assert_1.default.equal(result, `[data-theme="${theme}"] {\n--p: 65.3% 0.186 275.9;\n--pc: 13.3% 0.038 276.4;\n--b1: 25.3% 0.016 252.4;\n--bc: 74.6% 0.022 264.4;\n}`);
59
+ });
60
+ it("should transform variables from color names to oklch tuple", () => {
61
+ const result = (0, preprocess_style_1.preprocessStyle)(`[data-theme="daisy-${theme}"] { --p: red; }`);
62
+ assert_1.default.equal(result, `[data-theme="${theme}"] { --p: 62.8% 0.258 29.2; }`);
63
+ });
64
+ it("should transform achromatic color to oklch tuple", () => {
65
+ const result = (0, preprocess_style_1.preprocessStyle)(`[data-theme="daisy-${theme}"] { --p: white; }`);
66
+ assert_1.default.equal(result, `[data-theme="${theme}"] { --p: 100.0% 0.000 0.0; }`);
67
+ });
68
+ it("should not transform --on-primary variable", () => {
69
+ const result = (0, preprocess_style_1.preprocessStyle)(`[data-theme="daisy-${theme}"] { --on-primary: black; }`);
70
+ assert_1.default.equal(result, `[data-theme="${theme}"] { --on-primary: black; }`);
71
+ });
72
+ });
73
+ }
74
+ });
75
+ });
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const KOKIMOKI_KIT_VERSION = "1.3.0";
1
+ export declare const KOKIMOKI_KIT_VERSION = "1.5.0";
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KOKIMOKI_KIT_VERSION = void 0;
4
- exports.KOKIMOKI_KIT_VERSION = "1.3.0";
4
+ exports.KOKIMOKI_KIT_VERSION = "1.5.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kokimoki/kit",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "dist"
9
9
  ],
10
10
  "scripts": {
11
- "test": "echo \"Error: no test specified\" && exit 1",
11
+ "test": "ts-mocha src/**/*.spec.ts --exit",
12
12
  "prebuild": "node -p \"'export const KOKIMOKI_KIT_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
13
13
  "build": "tsc"
14
14
  },
@@ -16,12 +16,18 @@
16
16
  "license": "Apache-2.0",
17
17
  "devDependencies": {
18
18
  "@types/colornames": "^1.1.4",
19
+ "@types/expect": "^24.3.2",
20
+ "mocha": "^11.1.0",
21
+ "ts-mocha": "^10.0.0",
19
22
  "vite": "^5.4.8"
20
23
  },
21
24
  "dependencies": {
22
25
  "bson-objectid": "^2.0.4",
23
26
  "colorjs.io": "^0.5.2",
24
- "colornames": "^1.1.1"
27
+ "colornames": "^1.1.1",
28
+ "yaml": "^2.7.0",
29
+ "zod": "^3.24.2",
30
+ "zod-to-json-schema": "^3.24.5"
25
31
  },
26
32
  "peerDependencies": {
27
33
  "vite": ">=5"