@konomi-app/k2 2.1.3 → 2.1.4
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 +0 -2
- package/dist/index.js +551 -13
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +0 -2
- package/dist/plugin.js +1086 -23
- package/dist/plugin.js.map +1 -1
- package/package.json +4 -4
- package/dist/commands/build-base.d.ts +0 -6
- package/dist/commands/build-base.d.ts.map +0 -1
- package/dist/commands/build-base.js +0 -7
- package/dist/commands/build-base.js.map +0 -1
- package/dist/commands/build-esbuild.d.ts +0 -7
- package/dist/commands/build-esbuild.d.ts.map +0 -1
- package/dist/commands/build-esbuild.js +0 -63
- package/dist/commands/build-esbuild.js.map +0 -1
- package/dist/commands/build-tailwind.d.ts +0 -2
- package/dist/commands/build-tailwind.d.ts.map +0 -1
- package/dist/commands/build-tailwind.js +0 -19
- package/dist/commands/build-tailwind.js.map +0 -1
- package/dist/commands/build.d.ts +0 -7
- package/dist/commands/build.d.ts.map +0 -1
- package/dist/commands/build.js +0 -52
- package/dist/commands/build.js.map +0 -1
- package/dist/commands/dev/index.d.ts +0 -9
- package/dist/commands/dev/index.d.ts.map +0 -1
- package/dist/commands/dev/index.js +0 -60
- package/dist/commands/dev/index.js.map +0 -1
- package/dist/commands/dev/tailwind.d.ts +0 -5
- package/dist/commands/dev/tailwind.d.ts.map +0 -1
- package/dist/commands/dev/tailwind.js +0 -30
- package/dist/commands/dev/tailwind.js.map +0 -1
- package/dist/commands/dev-base-esbuild.d.ts +0 -8
- package/dist/commands/dev-base-esbuild.d.ts.map +0 -1
- package/dist/commands/dev-base-esbuild.js +0 -18
- package/dist/commands/dev-base-esbuild.js.map +0 -1
- package/dist/commands/genkey-base.d.ts +0 -4
- package/dist/commands/genkey-base.d.ts.map +0 -1
- package/dist/commands/genkey-base.js +0 -19
- package/dist/commands/genkey-base.js.map +0 -1
- package/dist/commands/genkey.d.ts +0 -5
- package/dist/commands/genkey.d.ts.map +0 -1
- package/dist/commands/genkey.js +0 -14
- package/dist/commands/genkey.js.map +0 -1
- package/dist/commands/lint.d.ts +0 -8
- package/dist/commands/lint.d.ts.map +0 -1
- package/dist/commands/lint.js +0 -20
- package/dist/commands/lint.js.map +0 -1
- package/dist/commands/manifest/index.d.ts +0 -2
- package/dist/commands/manifest/index.d.ts.map +0 -1
- package/dist/commands/manifest/index.js +0 -29
- package/dist/commands/manifest/index.js.map +0 -1
- package/dist/commands/plugin-build.d.ts +0 -3
- package/dist/commands/plugin-build.d.ts.map +0 -1
- package/dist/commands/plugin-build.js +0 -60
- package/dist/commands/plugin-build.js.map +0 -1
- package/dist/commands/plugin-dev/create-manifest.d.ts +0 -5
- package/dist/commands/plugin-dev/create-manifest.d.ts.map +0 -1
- package/dist/commands/plugin-dev/create-manifest.js +0 -30
- package/dist/commands/plugin-dev/create-manifest.js.map +0 -1
- package/dist/commands/plugin-dev/index.d.ts +0 -6
- package/dist/commands/plugin-dev/index.d.ts.map +0 -1
- package/dist/commands/plugin-dev/index.js +0 -50
- package/dist/commands/plugin-dev/index.js.map +0 -1
- package/dist/commands/plugin-dev/tailwind.d.ts +0 -2
- package/dist/commands/plugin-dev/tailwind.d.ts.map +0 -1
- package/dist/commands/plugin-dev/tailwind.js +0 -42
- package/dist/commands/plugin-dev/tailwind.js.map +0 -1
- package/dist/commands/plugin-dev/upload.d.ts +0 -5
- package/dist/commands/plugin-dev/upload.d.ts.map +0 -1
- package/dist/commands/plugin-dev/upload.js +0 -58
- package/dist/commands/plugin-dev/upload.js.map +0 -1
- package/dist/commands/plugin-esbuild.d.ts +0 -3
- package/dist/commands/plugin-esbuild.d.ts.map +0 -1
- package/dist/commands/plugin-esbuild.js +0 -66
- package/dist/commands/plugin-esbuild.js.map +0 -1
- package/dist/commands/plugin-genkey.d.ts +0 -3
- package/dist/commands/plugin-genkey.d.ts.map +0 -1
- package/dist/commands/plugin-genkey.js +0 -13
- package/dist/commands/plugin-genkey.js.map +0 -1
- package/dist/commands/plugin-init.d.ts +0 -3
- package/dist/commands/plugin-init.d.ts.map +0 -1
- package/dist/commands/plugin-init.js +0 -45
- package/dist/commands/plugin-init.js.map +0 -1
- package/dist/commands/plugin-tsup.d.ts +0 -3
- package/dist/commands/plugin-tsup.d.ts.map +0 -1
- package/dist/commands/plugin-tsup.js +0 -65
- package/dist/commands/plugin-tsup.js.map +0 -1
- package/dist/commands/plugin-zip.d.ts +0 -2
- package/dist/commands/plugin-zip.d.ts.map +0 -1
- package/dist/commands/plugin-zip.js +0 -50
- package/dist/commands/plugin-zip.js.map +0 -1
- package/dist/commands/test/index.d.ts +0 -3
- package/dist/commands/test/index.d.ts.map +0 -1
- package/dist/commands/test/index.js +0 -17
- package/dist/commands/test/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/lib/cert.d.ts +0 -4
- package/dist/lib/cert.d.ts.map +0 -1
- package/dist/lib/cert.js +0 -16
- package/dist/lib/cert.js.map +0 -1
- package/dist/lib/constants.d.ts +0 -13
- package/dist/lib/constants.d.ts.map +0 -1
- package/dist/lib/constants.js +0 -14
- package/dist/lib/constants.js.map +0 -1
- package/dist/lib/esbuild.d.ts +0 -6
- package/dist/lib/esbuild.d.ts.map +0 -1
- package/dist/lib/esbuild.js +0 -39
- package/dist/lib/esbuild.js.map +0 -1
- package/dist/lib/exec.d.ts +0 -3
- package/dist/lib/exec.d.ts.map +0 -1
- package/dist/lib/exec.js +0 -4
- package/dist/lib/exec.js.map +0 -1
- package/dist/lib/import.d.ts +0 -4
- package/dist/lib/import.d.ts.map +0 -1
- package/dist/lib/import.js +0 -18
- package/dist/lib/import.js.map +0 -1
- package/dist/lib/k2.d.ts +0 -2
- package/dist/lib/k2.d.ts.map +0 -1
- package/dist/lib/k2.js +0 -9
- package/dist/lib/k2.js.map +0 -1
- package/dist/lib/kintone-api-client.d.ts +0 -57
- package/dist/lib/kintone-api-client.d.ts.map +0 -1
- package/dist/lib/kintone-api-client.js +0 -95
- package/dist/lib/kintone-api-client.js.map +0 -1
- package/dist/lib/lint.d.ts +0 -2
- package/dist/lib/lint.d.ts.map +0 -1
- package/dist/lib/lint.js +0 -28
- package/dist/lib/lint.js.map +0 -1
- package/dist/lib/plugin-contents.d.ts +0 -5
- package/dist/lib/plugin-contents.d.ts.map +0 -1
- package/dist/lib/plugin-contents.js +0 -28
- package/dist/lib/plugin-contents.js.map +0 -1
- package/dist/lib/plugin-manifest.d.ts +0 -4
- package/dist/lib/plugin-manifest.d.ts.map +0 -1
- package/dist/lib/plugin-manifest.js +0 -13
- package/dist/lib/plugin-manifest.js.map +0 -1
- package/dist/lib/tailwind.d.ts +0 -33
- package/dist/lib/tailwind.d.ts.map +0 -1
- package/dist/lib/tailwind.js +0 -91
- package/dist/lib/tailwind.js.map +0 -1
- package/dist/lib/tsup.d.ts +0 -3
- package/dist/lib/tsup.d.ts.map +0 -1
- package/dist/lib/tsup.js +0 -26
- package/dist/lib/tsup.js.map +0 -1
- package/dist/lib/utils.d.ts +0 -16
- package/dist/lib/utils.d.ts.map +0 -1
- package/dist/lib/utils.js +0 -66
- package/dist/lib/utils.js.map +0 -1
- package/dist/lib/webpack.d.ts +0 -6
- package/dist/lib/webpack.d.ts.map +0 -1
- package/dist/lib/webpack.js +0 -72
- package/dist/lib/webpack.js.map +0 -1
- package/dist/lib/zip.d.ts +0 -4
- package/dist/lib/zip.d.ts.map +0 -1
- package/dist/lib/zip.js +0 -65
- package/dist/lib/zip.js.map +0 -1
- package/dist/plugin.d.ts.map +0 -1
package/dist/plugin.js
CHANGED
|
@@ -1,25 +1,1088 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2
|
+
|
|
3
|
+
// src/plugin.ts
|
|
4
|
+
import { program as program11 } from "commander";
|
|
5
|
+
|
|
6
|
+
// src/commands/plugin-build.ts
|
|
7
|
+
import { program } from "commander";
|
|
8
|
+
import fs2 from "fs-extra";
|
|
9
|
+
import path5 from "path";
|
|
10
|
+
import "webpack";
|
|
11
|
+
|
|
12
|
+
// src/lib/constants.ts
|
|
13
|
+
import path from "path";
|
|
14
|
+
var WORKSPACE_DIRECTORY = ".k2";
|
|
15
|
+
var DEVELOPMENT_DIRECTORY = path.join(WORKSPACE_DIRECTORY, "dev");
|
|
16
|
+
var PLUGIN_CONFIG_FILE_NAME = "plugin.config.mjs";
|
|
17
|
+
var PLUGIN_WORKSPACE_DIRECTORY = ".plugin";
|
|
18
|
+
var PLUGIN_CONTENTS_DIRECTORY = path.join(PLUGIN_WORKSPACE_DIRECTORY, "contents");
|
|
19
|
+
var PLUGIN_DEVELOPMENT_DIRECTORY = path.join(PLUGIN_WORKSPACE_DIRECTORY, "dev");
|
|
20
|
+
var DEFAULT_PORT = 32767;
|
|
21
|
+
|
|
22
|
+
// src/lib/import.ts
|
|
23
|
+
import { pathToFileURL } from "url";
|
|
24
|
+
import path2 from "path";
|
|
25
|
+
var esmImport = (path19) => {
|
|
26
|
+
if (process.platform === "win32") {
|
|
27
|
+
return import(pathToFileURL(path19).toString());
|
|
28
|
+
} else {
|
|
29
|
+
return import(path19);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var importK2PluginConfig = async (configFileName) => {
|
|
33
|
+
return (await esmImport(path2.resolve(configFileName ?? PLUGIN_CONFIG_FILE_NAME))).default;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/lib/tailwind.ts
|
|
37
|
+
import chokidar from "chokidar";
|
|
38
|
+
import cssnanoPlugin from "cssnano";
|
|
39
|
+
import fs from "fs-extra";
|
|
40
|
+
import { glob } from "glob";
|
|
41
|
+
import path3 from "path";
|
|
42
|
+
import postcss from "postcss";
|
|
43
|
+
import { debounce } from "remeda";
|
|
44
|
+
import tailwindcss from "tailwindcss";
|
|
45
|
+
import invariant from "tiny-invariant";
|
|
46
|
+
var getTailwindInputCss = (config2) => {
|
|
47
|
+
invariant(config2?.css, "tailwind.css is required");
|
|
48
|
+
const { css } = config2;
|
|
49
|
+
if (typeof css === "string") {
|
|
50
|
+
const resolved = path3.resolve(css);
|
|
51
|
+
return { desktop: resolved, config: resolved };
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
desktop: path3.resolve(css.desktop),
|
|
55
|
+
config: path3.resolve(css.config)
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
var getTailwindConfig = async (config2) => {
|
|
59
|
+
invariant(config2?.config, "tailwind.config is required");
|
|
60
|
+
const { config: configPath } = config2;
|
|
61
|
+
const configPathForDesktop = typeof configPath === "string" ? configPath : configPath.desktop;
|
|
62
|
+
const configPathForConfig = typeof configPath === "string" ? configPath : configPath.config;
|
|
63
|
+
const desktopConfig = (await esmImport(path3.resolve(configPathForDesktop))).default;
|
|
64
|
+
const configConfig = (await esmImport(path3.resolve(configPathForConfig))).default;
|
|
65
|
+
return { desktop: desktopConfig, config: configConfig };
|
|
66
|
+
};
|
|
67
|
+
var outputCss = async (params) => {
|
|
68
|
+
const { inputPath, outputPath, config: config2, minify = false } = params;
|
|
69
|
+
const css = await fs.readFile(inputPath, "utf8");
|
|
70
|
+
const result = await postcss([tailwindcss(config2), ...minify ? [cssnanoPlugin()] : []]).process(
|
|
71
|
+
css,
|
|
72
|
+
{
|
|
73
|
+
from: inputPath,
|
|
74
|
+
to: outputPath
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
await fs.writeFile(outputPath, result.css);
|
|
78
|
+
if (result.map) {
|
|
79
|
+
await fs.writeFile(`${outputPath}.map`, result.map.toString());
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var watchTailwindCSS = async (params) => {
|
|
83
|
+
const { input, output, config: config2 } = params;
|
|
84
|
+
const content = config2.content ?? ["./src/**/*.{ts,tsx}"];
|
|
85
|
+
const files = await glob([...content, input], { ignore: ["**/node_modules/**"] });
|
|
86
|
+
const watcher = chokidar.watch(files, {
|
|
87
|
+
persistent: true,
|
|
88
|
+
ignoreInitial: true
|
|
89
|
+
});
|
|
90
|
+
let isInitialized = false;
|
|
91
|
+
const processChanges = async (type) => {
|
|
92
|
+
try {
|
|
93
|
+
await outputCss({ inputPath: input, outputPath: output, config: config2 });
|
|
94
|
+
params.onChanges?.({ input, output, type });
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error("Error building Tailwind CSS:", error);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const debouncedProcessChanges = debounce(processChanges, { waitMs: 1e3 });
|
|
100
|
+
watcher.on("ready", async () => {
|
|
101
|
+
if (!isInitialized) {
|
|
102
|
+
isInitialized = true;
|
|
103
|
+
await processChanges("init");
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
watcher.on("error", (error) => {
|
|
107
|
+
console.error("Error watching Tailwind CSS:", error);
|
|
108
|
+
});
|
|
109
|
+
watcher.on("add", (path19) => {
|
|
110
|
+
debouncedProcessChanges.call("add");
|
|
111
|
+
});
|
|
112
|
+
watcher.on("change", (path19) => {
|
|
113
|
+
debouncedProcessChanges.call("change");
|
|
114
|
+
});
|
|
115
|
+
watcher.on("unlink", (path19) => {
|
|
116
|
+
debouncedProcessChanges.call("unlink");
|
|
117
|
+
});
|
|
118
|
+
watcher.on("unlinkDir", (path19) => {
|
|
119
|
+
debouncedProcessChanges.call("unlink");
|
|
120
|
+
});
|
|
121
|
+
return watcher;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// src/commands/build-base.ts
|
|
125
|
+
import "webpack";
|
|
126
|
+
|
|
127
|
+
// src/lib/webpack.ts
|
|
128
|
+
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|
129
|
+
import path4 from "path";
|
|
130
|
+
import { cwd } from "process";
|
|
131
|
+
import TerserPlugin from "terser-webpack-plugin";
|
|
132
|
+
import webpack from "webpack";
|
|
133
|
+
import chalk from "chalk";
|
|
134
|
+
import { TsconfigPathsPlugin } from "tsconfig-paths-webpack-plugin";
|
|
135
|
+
var buildWithWebpack = async (props) => {
|
|
136
|
+
const { entries, outDir } = props;
|
|
137
|
+
const exclude = /node_modules/;
|
|
138
|
+
const styleLoader = MiniCssExtractPlugin.loader;
|
|
139
|
+
const tsConfigPath = path4.join(cwd(), "tsconfig.json");
|
|
140
|
+
console.group(chalk.blue("\u{1F680} Building with Webpack..."));
|
|
141
|
+
console.log("\u{1F527} tsconfig.json path:", tsConfigPath);
|
|
142
|
+
console.groupEnd();
|
|
143
|
+
return new Promise((resolve, reject) => {
|
|
144
|
+
webpack(
|
|
145
|
+
{
|
|
146
|
+
mode: "production",
|
|
147
|
+
target: ["web", "es2023"],
|
|
148
|
+
entry: entries,
|
|
149
|
+
resolve: {
|
|
150
|
+
extensions: [".ts", ".tsx", ".js", ".json"],
|
|
151
|
+
fallback: {
|
|
152
|
+
path: false
|
|
153
|
+
},
|
|
154
|
+
plugins: [new TsconfigPathsPlugin({ configFile: tsConfigPath })]
|
|
155
|
+
},
|
|
156
|
+
cache: { type: "filesystem" },
|
|
157
|
+
output: { filename: "[name].js", path: path4.resolve(outDir) },
|
|
158
|
+
module: {
|
|
159
|
+
rules: [
|
|
160
|
+
{ test: /\.tsx?$/, exclude, loader: "ts-loader" },
|
|
161
|
+
{ test: /\.css$/, use: [styleLoader, "css-loader"] },
|
|
162
|
+
{
|
|
163
|
+
test: /\.scss$/,
|
|
164
|
+
use: [
|
|
165
|
+
styleLoader,
|
|
166
|
+
"css-loader",
|
|
167
|
+
{ loader: "sass-loader", options: { sassOptions: { outputStyle: "expanded" } } }
|
|
168
|
+
]
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
},
|
|
172
|
+
plugins: [new MiniCssExtractPlugin()],
|
|
173
|
+
optimization: {
|
|
174
|
+
minimize: true,
|
|
175
|
+
minimizer: [
|
|
176
|
+
new TerserPlugin({
|
|
177
|
+
terserOptions: { format: { comments: false } },
|
|
178
|
+
extractComments: false
|
|
179
|
+
})
|
|
180
|
+
]
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
(err, stats) => {
|
|
184
|
+
if (err) {
|
|
185
|
+
reject(err);
|
|
186
|
+
} else {
|
|
187
|
+
if (stats?.compilation.errors.length) {
|
|
188
|
+
reject(
|
|
189
|
+
[
|
|
190
|
+
chalk.red("\u26A0 Build failed."),
|
|
191
|
+
...stats.compilation.errors.map((error) => error.message)
|
|
192
|
+
].join("\n")
|
|
193
|
+
);
|
|
194
|
+
} else {
|
|
195
|
+
resolve();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// src/commands/build-base.ts
|
|
204
|
+
async function action(params) {
|
|
205
|
+
const { entries, outDir } = params;
|
|
206
|
+
return buildWithWebpack({ entries, outDir });
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/lib/lint.ts
|
|
210
|
+
import { ESLint } from "eslint";
|
|
211
|
+
import globals from "globals";
|
|
212
|
+
import pluginJs from "@eslint/js";
|
|
213
|
+
import "typescript-eslint";
|
|
214
|
+
import pluginReact from "eslint-plugin-react";
|
|
215
|
+
async function lint() {
|
|
216
|
+
const eslint = new ESLint({
|
|
217
|
+
baseConfig: [
|
|
218
|
+
{ files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"] },
|
|
219
|
+
{ languageOptions: { globals: globals.browser } },
|
|
220
|
+
pluginJs.configs.recommended,
|
|
221
|
+
// ...tseslint.configs.recommended,
|
|
222
|
+
...pluginReact.configs.flat?.recommended ? [pluginReact.configs.flat.recommended] : []
|
|
223
|
+
]
|
|
224
|
+
});
|
|
225
|
+
const results = await eslint.lintFiles(["src/**/*.{ts,tsx?}"]);
|
|
226
|
+
const formatter = await eslint.loadFormatter("stylish");
|
|
227
|
+
const resultText = formatter.format(results);
|
|
228
|
+
console.group("\u{1F455} Lint Results");
|
|
229
|
+
console.log(resultText);
|
|
230
|
+
console.groupEnd();
|
|
231
|
+
const hasErrors = results.some((result) => result.errorCount > 0);
|
|
232
|
+
if (hasErrors) {
|
|
233
|
+
console.error("\u{1F6A8} Lint errors found");
|
|
234
|
+
process.exit(1);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/commands/plugin-build.ts
|
|
239
|
+
function command() {
|
|
240
|
+
program.command("build").description("Build the project for production. (It's a wrapper of webpack build command.)").action(action2);
|
|
241
|
+
}
|
|
242
|
+
async function action2() {
|
|
243
|
+
console.group("\u{1F373} Build the project for production");
|
|
244
|
+
try {
|
|
245
|
+
const config2 = await importK2PluginConfig();
|
|
246
|
+
if (config2?.lint?.build) {
|
|
247
|
+
await lint();
|
|
248
|
+
console.log("\u2728 Lint success.");
|
|
249
|
+
}
|
|
250
|
+
if (!fs2.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
|
|
251
|
+
await fs2.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
|
|
252
|
+
}
|
|
253
|
+
const entries = {
|
|
254
|
+
desktop: path5.join("src", "desktop", "index.ts"),
|
|
255
|
+
config: path5.join("src", "config", "index.ts")
|
|
256
|
+
};
|
|
257
|
+
if (config2.tailwind?.css && config2.tailwind?.config) {
|
|
258
|
+
const tailwindConfig = await getTailwindConfig(config2.tailwind);
|
|
259
|
+
const inputFile = getTailwindInputCss(config2.tailwind);
|
|
260
|
+
await outputCss({
|
|
261
|
+
inputPath: inputFile.config,
|
|
262
|
+
outputPath: path5.join(PLUGIN_CONTENTS_DIRECTORY, "config.css"),
|
|
263
|
+
config: tailwindConfig.config,
|
|
264
|
+
minify: true
|
|
265
|
+
});
|
|
266
|
+
console.log("\u2728 Built config.css");
|
|
267
|
+
await outputCss({
|
|
268
|
+
inputPath: inputFile.desktop,
|
|
269
|
+
outputPath: path5.join(PLUGIN_CONTENTS_DIRECTORY, "desktop.css"),
|
|
270
|
+
config: tailwindConfig.desktop,
|
|
271
|
+
minify: true
|
|
272
|
+
});
|
|
273
|
+
console.log("\u2728 Built desktop.css");
|
|
274
|
+
}
|
|
275
|
+
await action({ entries, outDir: PLUGIN_CONTENTS_DIRECTORY });
|
|
276
|
+
console.log("\u2728 Built desktop.js and config.js");
|
|
277
|
+
console.log("\u2728 Build success.");
|
|
278
|
+
} catch (error) {
|
|
279
|
+
throw error;
|
|
280
|
+
} finally {
|
|
281
|
+
console.groupEnd();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// src/commands/plugin-esbuild.ts
|
|
286
|
+
import { program as program2 } from "commander";
|
|
287
|
+
import fs3 from "fs-extra";
|
|
288
|
+
import path6 from "path";
|
|
289
|
+
import "esbuild";
|
|
290
|
+
|
|
291
|
+
// src/lib/esbuild.ts
|
|
292
|
+
import chalk2 from "chalk";
|
|
293
|
+
import esbuild from "esbuild";
|
|
294
|
+
var completeBuildOptions = (params) => {
|
|
295
|
+
return {
|
|
296
|
+
bundle: true,
|
|
297
|
+
platform: "browser",
|
|
298
|
+
...params,
|
|
299
|
+
plugins: [...params.plugins ?? []]
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
var completeDevBuildOptions = (params) => {
|
|
303
|
+
return completeBuildOptions({
|
|
304
|
+
...params,
|
|
305
|
+
plugins: [
|
|
306
|
+
...params.plugins ?? [],
|
|
307
|
+
{
|
|
308
|
+
name: "on-end",
|
|
309
|
+
setup: ({ onEnd }) => onEnd(
|
|
310
|
+
() => console.log(
|
|
311
|
+
chalk2.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk2.cyan(`[js] `) + `rebuilt`
|
|
312
|
+
)
|
|
313
|
+
)
|
|
314
|
+
}
|
|
315
|
+
]
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
var getEsbuildContext = async (params) => {
|
|
319
|
+
return esbuild.context(completeDevBuildOptions(params));
|
|
320
|
+
};
|
|
321
|
+
var buildWithEsbuild = async (params) => {
|
|
322
|
+
const { watch = false, ...rest } = params;
|
|
323
|
+
if (watch) {
|
|
324
|
+
const context = await getEsbuildContext(rest);
|
|
325
|
+
context.watch();
|
|
326
|
+
} else {
|
|
327
|
+
const options = completeBuildOptions(rest);
|
|
328
|
+
await esbuild.build(options);
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// src/commands/plugin-esbuild.ts
|
|
333
|
+
function command2() {
|
|
334
|
+
program2.command("esbuild").description("Build the project for production. (It's a wrapper of webpack build command.)").action(action3);
|
|
335
|
+
}
|
|
336
|
+
async function action3() {
|
|
337
|
+
console.group("\u{1F373} Build the project for production");
|
|
338
|
+
try {
|
|
339
|
+
const config2 = await importK2PluginConfig();
|
|
340
|
+
if (config2?.lint?.build) {
|
|
341
|
+
await lint();
|
|
342
|
+
console.log("\u2728 Lint success.");
|
|
343
|
+
}
|
|
344
|
+
if (!fs3.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
|
|
345
|
+
await fs3.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
|
|
346
|
+
}
|
|
347
|
+
if (config2.tailwind?.css && config2.tailwind?.config) {
|
|
348
|
+
const tailwindConfig = await getTailwindConfig(config2.tailwind);
|
|
349
|
+
const inputFile = getTailwindInputCss(config2.tailwind);
|
|
350
|
+
await outputCss({
|
|
351
|
+
inputPath: inputFile.config,
|
|
352
|
+
outputPath: path6.join(PLUGIN_CONTENTS_DIRECTORY, "config.css"),
|
|
353
|
+
config: tailwindConfig.config,
|
|
354
|
+
minify: true
|
|
355
|
+
});
|
|
356
|
+
console.log("\u2728 Built config.css");
|
|
357
|
+
await outputCss({
|
|
358
|
+
inputPath: inputFile.desktop,
|
|
359
|
+
outputPath: path6.join(PLUGIN_CONTENTS_DIRECTORY, "desktop.css"),
|
|
360
|
+
config: tailwindConfig.desktop,
|
|
361
|
+
minify: true
|
|
362
|
+
});
|
|
363
|
+
console.log("\u2728 Built desktop.css");
|
|
364
|
+
}
|
|
365
|
+
const entryPoints = ["desktop", "config"].map((dir) => ({
|
|
366
|
+
in: path6.join("src", dir, "index.ts"),
|
|
367
|
+
out: dir
|
|
368
|
+
}));
|
|
369
|
+
await buildWithEsbuild({
|
|
370
|
+
entryPoints,
|
|
371
|
+
outdir: PLUGIN_CONTENTS_DIRECTORY,
|
|
372
|
+
minify: true,
|
|
373
|
+
sourcemap: false,
|
|
374
|
+
legalComments: "none"
|
|
375
|
+
});
|
|
376
|
+
console.log("\u2728 Built desktop.js and config.js");
|
|
377
|
+
console.log("\u2728 Build success.");
|
|
378
|
+
} catch (error) {
|
|
379
|
+
throw error;
|
|
380
|
+
} finally {
|
|
381
|
+
console.groupEnd();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// src/commands/plugin-dev/index.ts
|
|
386
|
+
import { program as program3 } from "commander";
|
|
387
|
+
import "esbuild";
|
|
388
|
+
import fs9 from "fs-extra";
|
|
389
|
+
import path14 from "path";
|
|
390
|
+
|
|
391
|
+
// src/commands/dev-base-esbuild.ts
|
|
392
|
+
import "esbuild";
|
|
393
|
+
import path7 from "path";
|
|
394
|
+
async function action4(params) {
|
|
395
|
+
const { entryPoints, staticDir: outdir, certDir, port } = params;
|
|
396
|
+
const context = await getEsbuildContext({ sourcemap: "inline", entryPoints, outdir });
|
|
397
|
+
const [_, serveResult] = await Promise.all([
|
|
398
|
+
context.watch(),
|
|
399
|
+
context.serve({
|
|
400
|
+
port,
|
|
401
|
+
keyfile: path7.join(certDir, "localhost-key.pem"),
|
|
402
|
+
certfile: path7.join(certDir, "localhost-cert.pem"),
|
|
403
|
+
servedir: outdir
|
|
404
|
+
})
|
|
405
|
+
]);
|
|
406
|
+
console.log(`\u{1F680} Start development server at https://localhost:${serveResult.port}`);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// src/lib/plugin-manifest.ts
|
|
410
|
+
import fs4 from "fs-extra";
|
|
411
|
+
import path8 from "path";
|
|
412
|
+
import merge from "deepmerge";
|
|
413
|
+
var outputManifest = async (env, options) => {
|
|
414
|
+
const config2 = options?.config || await importK2PluginConfig();
|
|
415
|
+
const merged = merge(config2.manifest.base, config2.manifest[env] || {});
|
|
416
|
+
await fs4.mkdirs(PLUGIN_CONTENTS_DIRECTORY);
|
|
417
|
+
await fs4.writeJson(path8.join(PLUGIN_CONTENTS_DIRECTORY, "manifest.json"), merged);
|
|
418
|
+
return merged;
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
// src/commands/plugin-dev/create-manifest.ts
|
|
422
|
+
var getManifest = async (params) => {
|
|
423
|
+
const { config: config2, port } = params;
|
|
424
|
+
return outputManifest("dev", {
|
|
425
|
+
config: {
|
|
426
|
+
...config2,
|
|
427
|
+
manifest: {
|
|
428
|
+
...config2.manifest,
|
|
429
|
+
dev: {
|
|
430
|
+
config: {
|
|
431
|
+
...config2.manifest?.dev?.config,
|
|
432
|
+
js: [`https://localhost:${port}/config.js`],
|
|
433
|
+
css: [`https://localhost:${port}/config.css`]
|
|
434
|
+
},
|
|
435
|
+
desktop: {
|
|
436
|
+
...config2.manifest?.dev?.desktop,
|
|
437
|
+
js: [`https://localhost:${port}/desktop.js`],
|
|
438
|
+
css: [`https://localhost:${port}/desktop.css`]
|
|
439
|
+
},
|
|
440
|
+
mobile: {
|
|
441
|
+
...config2.manifest?.dev?.mobile,
|
|
442
|
+
js: [`https://localhost:${port}/desktop.js`],
|
|
443
|
+
css: [`https://localhost:${port}/desktop.css`]
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
// src/commands/plugin-dev/tailwind.ts
|
|
452
|
+
import path9 from "path";
|
|
453
|
+
import "tailwindcss";
|
|
454
|
+
import chalk3 from "chalk";
|
|
455
|
+
async function buildTailwindCSS(params) {
|
|
456
|
+
const { inputFile, outputFileName, config: config2 } = params;
|
|
457
|
+
const inputPath = path9.resolve(inputFile);
|
|
458
|
+
const outputPath = path9.join(PLUGIN_DEVELOPMENT_DIRECTORY, outputFileName);
|
|
459
|
+
return watchTailwindCSS({
|
|
460
|
+
input: inputPath,
|
|
461
|
+
output: outputPath,
|
|
462
|
+
config: config2,
|
|
463
|
+
onChanges: ({ output, type }) => {
|
|
464
|
+
const outputFileName2 = path9.basename(output);
|
|
465
|
+
console.log(
|
|
466
|
+
chalk3.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk3.cyan(`[css] `) + outputFileName2 + (type === "init" ? " init" : ` rebuilt`)
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
var watchCss = async (pluginConfig) => {
|
|
472
|
+
if (!pluginConfig.tailwind?.css || !pluginConfig.tailwind?.config) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
const tailwindConfig = await getTailwindConfig(pluginConfig.tailwind);
|
|
476
|
+
const inputFile = getTailwindInputCss(pluginConfig.tailwind);
|
|
477
|
+
return Promise.all([
|
|
478
|
+
buildTailwindCSS({
|
|
479
|
+
inputFile: inputFile.desktop,
|
|
480
|
+
outputFileName: "desktop.css",
|
|
481
|
+
config: tailwindConfig.desktop
|
|
482
|
+
}),
|
|
483
|
+
buildTailwindCSS({
|
|
484
|
+
inputFile: inputFile.config,
|
|
485
|
+
outputFileName: "config.css",
|
|
486
|
+
config: tailwindConfig.config
|
|
487
|
+
})
|
|
488
|
+
]);
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
// src/commands/plugin-dev/upload.ts
|
|
492
|
+
import packer from "@kintone/plugin-packer";
|
|
493
|
+
|
|
494
|
+
// src/lib/plugin-contents.ts
|
|
495
|
+
import fs5 from "fs-extra";
|
|
496
|
+
import path10 from "path";
|
|
497
|
+
import htmlMinifier from "html-minifier";
|
|
498
|
+
var copyPluginContents = async (params = {}) => {
|
|
499
|
+
const { inputDir = path10.join("src", "contents"), outputDir = PLUGIN_CONTENTS_DIRECTORY } = params;
|
|
500
|
+
if (!fs5.existsSync(inputDir)) {
|
|
501
|
+
await fs5.mkdir(inputDir, { recursive: true });
|
|
502
|
+
}
|
|
503
|
+
await fs5.copy(inputDir, outputDir, { overwrite: true });
|
|
504
|
+
const configHtmlPath = path10.join(outputDir, "config.html");
|
|
505
|
+
if (!fs5.existsSync(configHtmlPath)) {
|
|
506
|
+
throw new Error(`Plugin HTML file not found. Create "config.html" in ${inputDir}.`);
|
|
507
|
+
}
|
|
508
|
+
const html = await fs5.readFile(configHtmlPath, "utf8");
|
|
509
|
+
const minified = htmlMinifier.minify(html, {
|
|
510
|
+
minifyCSS: true,
|
|
511
|
+
collapseWhitespace: true,
|
|
512
|
+
removeComments: true,
|
|
513
|
+
removeOptionalTags: true,
|
|
514
|
+
removeRedundantAttributes: true,
|
|
515
|
+
removeScriptTypeAttributes: true,
|
|
516
|
+
removeTagWhitespace: true,
|
|
517
|
+
useShortDoctype: true
|
|
518
|
+
});
|
|
519
|
+
await fs5.writeFile(configHtmlPath, minified);
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
// src/lib/zip.ts
|
|
523
|
+
import archiver from "archiver";
|
|
524
|
+
import fs6 from "fs-extra";
|
|
525
|
+
import path11 from "path";
|
|
526
|
+
import invariant2 from "tiny-invariant";
|
|
527
|
+
var outputContentsZip = async (manifest) => {
|
|
528
|
+
const archive = archiver("zip", { zlib: { level: 9 } });
|
|
529
|
+
archive.on("warning", (error) => {
|
|
530
|
+
if (error.code === "ENOENT") {
|
|
531
|
+
console.warn(error);
|
|
532
|
+
} else {
|
|
533
|
+
throw error;
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
const outputZipPath = path11.join(PLUGIN_WORKSPACE_DIRECTORY, "contents.zip");
|
|
537
|
+
const outputZipStream = fs6.createWriteStream(outputZipPath);
|
|
538
|
+
outputZipStream.on("close", () => {
|
|
539
|
+
console.log(`\u{1F4E6} ${archive.pointer()} total bytes`);
|
|
540
|
+
});
|
|
541
|
+
outputZipStream.on("end", function() {
|
|
542
|
+
console.log("\u{1F4E6} Data has been drained");
|
|
543
|
+
});
|
|
544
|
+
const filterLocalContent = (file) => {
|
|
545
|
+
return !/^https?:\/\//.test(file);
|
|
546
|
+
};
|
|
547
|
+
invariant2(manifest.config?.html, "manifest.config.html is required");
|
|
548
|
+
const targetFiles = [
|
|
549
|
+
"manifest.json",
|
|
550
|
+
.../* @__PURE__ */ new Set([
|
|
551
|
+
manifest.icon,
|
|
552
|
+
manifest.config.html,
|
|
553
|
+
...(manifest.desktop?.js || []).filter(filterLocalContent),
|
|
554
|
+
...(manifest.desktop?.css || []).filter(filterLocalContent),
|
|
555
|
+
...(manifest.mobile?.js || []).filter(filterLocalContent),
|
|
556
|
+
...(manifest.mobile?.css || []).filter(filterLocalContent),
|
|
557
|
+
...(manifest.config.js || []).filter(filterLocalContent),
|
|
558
|
+
...(manifest.config.css || []).filter(filterLocalContent)
|
|
559
|
+
])
|
|
560
|
+
];
|
|
561
|
+
console.group("\u{1F4C1} Target files");
|
|
562
|
+
targetFiles.forEach((file, i) => {
|
|
563
|
+
const prefix = i === targetFiles.length - 1 ? "\u2514\u2500" : "\u251C\u2500";
|
|
564
|
+
console.log(`${prefix} \u{1F4C4} ${file}`);
|
|
565
|
+
});
|
|
566
|
+
console.groupEnd();
|
|
567
|
+
for (const file of targetFiles) {
|
|
568
|
+
const filePath = path11.join(PLUGIN_CONTENTS_DIRECTORY, file);
|
|
569
|
+
if (!fs6.existsSync(filePath)) {
|
|
570
|
+
throw new Error(`${filePath} does not exist`);
|
|
571
|
+
}
|
|
572
|
+
archive.file(filePath, { name: file });
|
|
573
|
+
}
|
|
574
|
+
archive.pipe(outputZipStream);
|
|
575
|
+
await archive.finalize();
|
|
576
|
+
await new Promise((resolve) => outputZipStream.on("close", resolve));
|
|
577
|
+
};
|
|
578
|
+
var getContentsZipBuffer = async () => {
|
|
579
|
+
const outputZipPath = path11.join(PLUGIN_WORKSPACE_DIRECTORY, "contents.zip");
|
|
580
|
+
return fs6.readFile(outputZipPath);
|
|
581
|
+
};
|
|
582
|
+
var getZipFileNameSuffix = (env) => {
|
|
583
|
+
return env === "prod" ? "" : `-${env}`;
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
// src/commands/plugin-dev/upload.ts
|
|
587
|
+
import fs8 from "fs-extra";
|
|
588
|
+
import path13 from "path";
|
|
589
|
+
|
|
590
|
+
// src/lib/kintone-api-client.ts
|
|
591
|
+
import { config } from "dotenv";
|
|
592
|
+
var KintoneApiClient = class {
|
|
593
|
+
#baseUrl;
|
|
594
|
+
#authHeader;
|
|
595
|
+
constructor() {
|
|
596
|
+
config();
|
|
597
|
+
const {
|
|
598
|
+
KINTONE_BASE_URL,
|
|
599
|
+
KINTONE_USERNAME,
|
|
600
|
+
KINTONE_PASSWORD,
|
|
601
|
+
KINTONE_BASIC_AUTH_USERNAME = "",
|
|
602
|
+
KINTONE_BASIC_AUTH_PASSWORD = ""
|
|
603
|
+
} = process.env;
|
|
604
|
+
if (!KINTONE_BASE_URL || !KINTONE_USERNAME || !KINTONE_PASSWORD) {
|
|
605
|
+
throw new Error(`.env\u306E\u8A2D\u5B9A\u304C\u4E0D\u5341\u5206\u3067\u3059\u3002\u4EE5\u4E0B\u306E\u30D1\u30E9\u30E1\u30FC\u30BF\u306F\u5FC5\u9808\u3067\u3059
|
|
606
|
+
KINTONE_BASE_URL
|
|
607
|
+
KINTONE_USERNAME
|
|
608
|
+
KINTONE_PASSWORD`);
|
|
609
|
+
}
|
|
610
|
+
const authHeader = {
|
|
611
|
+
"X-Cybozu-Authorization": Buffer.from(`${KINTONE_USERNAME}:${KINTONE_PASSWORD}`).toString(
|
|
612
|
+
"base64"
|
|
613
|
+
),
|
|
614
|
+
...KINTONE_BASIC_AUTH_USERNAME && KINTONE_BASIC_AUTH_PASSWORD && {
|
|
615
|
+
Authorization: `Basic ${Buffer.from(
|
|
616
|
+
`${KINTONE_BASIC_AUTH_USERNAME}:${KINTONE_BASIC_AUTH_PASSWORD}`
|
|
617
|
+
).toString("base64")}`
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
this.#baseUrl = KINTONE_BASE_URL;
|
|
621
|
+
this.#authHeader = authHeader;
|
|
622
|
+
}
|
|
623
|
+
getEndpointUrl(path19) {
|
|
624
|
+
return `${this.#baseUrl}${path19}`;
|
|
625
|
+
}
|
|
626
|
+
async upload(params) {
|
|
627
|
+
const { blob, fileName } = params;
|
|
628
|
+
const form = new FormData();
|
|
629
|
+
form.append("file", blob, fileName);
|
|
630
|
+
const uploadResult = await fetch(this.getEndpointUrl("/k/v1/file.json"), {
|
|
631
|
+
method: "POST",
|
|
632
|
+
headers: this.#authHeader,
|
|
633
|
+
body: form
|
|
634
|
+
});
|
|
635
|
+
const { fileKey } = await uploadResult.json();
|
|
636
|
+
return fileKey;
|
|
637
|
+
}
|
|
638
|
+
async getPlugins(params = {}) {
|
|
639
|
+
const url = new URL(this.getEndpointUrl("/k/v1/plugins.json"));
|
|
640
|
+
if (params.offset) {
|
|
641
|
+
url.searchParams.set("offset", String(params.offset));
|
|
642
|
+
}
|
|
643
|
+
if (params.limit) {
|
|
644
|
+
url.searchParams.set("limit", String(params.limit));
|
|
645
|
+
}
|
|
646
|
+
const pluginResponse = await fetch(url.toString(), {
|
|
647
|
+
headers: this.#authHeader
|
|
648
|
+
});
|
|
649
|
+
return pluginResponse.json();
|
|
650
|
+
}
|
|
651
|
+
async getAllPlugins() {
|
|
652
|
+
const plugins = [];
|
|
653
|
+
let offset = 0;
|
|
654
|
+
let limit = 100;
|
|
655
|
+
let hasMore = true;
|
|
656
|
+
while (hasMore) {
|
|
657
|
+
const { plugins: currentPlugins } = await this.getPlugins({ offset, limit });
|
|
658
|
+
plugins.push(...currentPlugins);
|
|
659
|
+
if (currentPlugins.length < limit) {
|
|
660
|
+
hasMore = false;
|
|
661
|
+
} else {
|
|
662
|
+
offset += limit;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
return plugins;
|
|
666
|
+
}
|
|
667
|
+
async addPlugin(params) {
|
|
668
|
+
const { fileKey } = params;
|
|
669
|
+
const pluginResponse = await fetch(this.getEndpointUrl("/k/v1/plugin.json"), {
|
|
670
|
+
method: "POST",
|
|
671
|
+
headers: {
|
|
672
|
+
"Content-Type": "application/json",
|
|
673
|
+
...this.#authHeader
|
|
674
|
+
},
|
|
675
|
+
body: JSON.stringify({
|
|
676
|
+
fileKey
|
|
677
|
+
})
|
|
678
|
+
});
|
|
679
|
+
return pluginResponse.json();
|
|
680
|
+
}
|
|
681
|
+
async updatePlugin(params) {
|
|
682
|
+
const pluginResponse = await fetch(this.getEndpointUrl("/k/v1/plugin.json"), {
|
|
683
|
+
method: "PUT",
|
|
684
|
+
headers: {
|
|
685
|
+
"Content-Type": "application/json",
|
|
686
|
+
...this.#authHeader
|
|
687
|
+
},
|
|
688
|
+
body: JSON.stringify(params)
|
|
689
|
+
});
|
|
690
|
+
return pluginResponse.json();
|
|
691
|
+
}
|
|
692
|
+
};
|
|
693
|
+
|
|
694
|
+
// src/lib/utils.ts
|
|
695
|
+
import fs7 from "fs-extra";
|
|
696
|
+
import path12 from "path";
|
|
697
|
+
var isEnv = (env) => {
|
|
698
|
+
return ["prod", "dev", "standalone"].includes(env);
|
|
699
|
+
};
|
|
700
|
+
var apiUploadZip = async (params) => {
|
|
701
|
+
const { env, pluginId } = params;
|
|
702
|
+
const kc = new KintoneApiClient();
|
|
703
|
+
const zipFileName = `plugin${getZipFileNameSuffix(env)}.zip`;
|
|
704
|
+
const zipFile = new Blob([await fs7.readFile(path12.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName))]);
|
|
705
|
+
const fileKey = await kc.upload({ blob: zipFile, fileName: zipFileName });
|
|
706
|
+
const plugins = await kc.getAllPlugins();
|
|
707
|
+
const plugin = plugins.find((p) => p.id === pluginId);
|
|
708
|
+
if (plugin) {
|
|
709
|
+
const json = await kc.updatePlugin({ id: pluginId, fileKey });
|
|
710
|
+
if ("errors" in json && json.errors) {
|
|
711
|
+
console.error((json.errors.id?.messages ?? []).map((m) => `Error: ${m}`).join("\n"));
|
|
712
|
+
}
|
|
713
|
+
return { method: "PUT" };
|
|
714
|
+
}
|
|
715
|
+
const result = await kc.addPlugin({ fileKey });
|
|
716
|
+
if ("code" in result) {
|
|
717
|
+
console.error(`Error: ${result.message}`);
|
|
718
|
+
}
|
|
719
|
+
return { method: "POST" };
|
|
720
|
+
};
|
|
721
|
+
|
|
722
|
+
// src/commands/plugin-dev/upload.ts
|
|
723
|
+
import chokider from "chokidar";
|
|
724
|
+
import chalk4 from "chalk";
|
|
725
|
+
var watchContentsAndUploadZip = async (params) => {
|
|
726
|
+
const { manifest, ppkPath } = params;
|
|
727
|
+
let initialScanComplete = false;
|
|
728
|
+
const contentsListener = async () => {
|
|
729
|
+
try {
|
|
730
|
+
if (!initialScanComplete) {
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
await copyPluginContents();
|
|
734
|
+
console.log(
|
|
735
|
+
chalk4.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk4.cyan(`[contents] `) + `updated`
|
|
736
|
+
);
|
|
737
|
+
} catch (error) {
|
|
738
|
+
console.error("Error copying plugin contents:", error);
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
try {
|
|
742
|
+
await outputContentsZip(manifest);
|
|
743
|
+
const buffer = await getContentsZipBuffer();
|
|
744
|
+
const pluginPrivateKey = await fs8.readFile(path13.resolve(ppkPath), "utf8");
|
|
745
|
+
const output = await packer(buffer, pluginPrivateKey);
|
|
746
|
+
const zipFileName = `plugin${getZipFileNameSuffix("dev")}.zip`;
|
|
747
|
+
await fs8.writeFile(path13.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName), output.plugin);
|
|
748
|
+
const { method } = await apiUploadZip({ env: "dev", pluginId: output.id });
|
|
749
|
+
console.log(
|
|
750
|
+
chalk4.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk4.cyan(`[upload] `) + `uploaded ${method === "POST" ? "(new)" : "(update)"}`
|
|
751
|
+
);
|
|
752
|
+
} catch (error) {
|
|
753
|
+
console.log(
|
|
754
|
+
chalk4.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk4.cyan(`[upload] `) + chalk4.red(`failed`) + chalk4.hex("#e5e7eb")(`: ${error?.message ?? "Unknown error"}`)
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
const contentsWatcher = chokider.watch(["src/contents/**/*"], {
|
|
759
|
+
ignored: /node_modules/,
|
|
760
|
+
persistent: true
|
|
761
|
+
});
|
|
762
|
+
contentsWatcher.on("ready", () => {
|
|
763
|
+
initialScanComplete = true;
|
|
764
|
+
contentsListener();
|
|
765
|
+
});
|
|
766
|
+
contentsWatcher.on("change", contentsListener);
|
|
767
|
+
contentsWatcher.on("add", contentsListener);
|
|
768
|
+
contentsWatcher.on("unlink", contentsListener);
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
// src/commands/plugin-dev/index.ts
|
|
772
|
+
function command3() {
|
|
773
|
+
program3.command("dev").option(
|
|
774
|
+
"-p, --ppk <ppk>",
|
|
775
|
+
".ppk file path",
|
|
776
|
+
path14.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk")
|
|
777
|
+
).option("-c, --cert-dir <certDir>", "Certificate directory", PLUGIN_WORKSPACE_DIRECTORY).description("Start development server.").action(action5);
|
|
778
|
+
}
|
|
779
|
+
async function action5(options) {
|
|
780
|
+
console.group("\u{1F373} Start development server");
|
|
781
|
+
try {
|
|
782
|
+
const { ppk: ppkPath, certDir } = options;
|
|
783
|
+
const config2 = await importK2PluginConfig();
|
|
784
|
+
if (!fs9.existsSync(PLUGIN_DEVELOPMENT_DIRECTORY)) {
|
|
785
|
+
await fs9.mkdir(PLUGIN_DEVELOPMENT_DIRECTORY, { recursive: true });
|
|
786
|
+
}
|
|
787
|
+
const port = config2.server?.port ?? DEFAULT_PORT;
|
|
788
|
+
const manifest = await getManifest({ config: config2, port });
|
|
789
|
+
console.log(`\u{1F4DD} manifest.json generated`);
|
|
790
|
+
Promise.all([
|
|
791
|
+
watchContentsAndUploadZip({ manifest, ppkPath }),
|
|
792
|
+
watchCss(config2),
|
|
793
|
+
build(port, certDir)
|
|
794
|
+
]);
|
|
795
|
+
} catch (error) {
|
|
796
|
+
throw error;
|
|
797
|
+
} finally {
|
|
798
|
+
console.groupEnd();
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
async function build(port, certDir = PLUGIN_WORKSPACE_DIRECTORY, staticDir = PLUGIN_DEVELOPMENT_DIRECTORY) {
|
|
802
|
+
const entryPoints = ["desktop", "config"].map((dir) => ({
|
|
803
|
+
in: path14.join("src", dir, "index.ts"),
|
|
804
|
+
out: dir
|
|
805
|
+
}));
|
|
806
|
+
action4({ port, entryPoints, certDir, staticDir });
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// src/commands/plugin-genkey.ts
|
|
810
|
+
import { program as program4 } from "commander";
|
|
811
|
+
|
|
812
|
+
// src/lib/exec.ts
|
|
813
|
+
import { exec as defaultExec } from "child_process";
|
|
814
|
+
import { promisify } from "util";
|
|
815
|
+
var exec = promisify(defaultExec);
|
|
816
|
+
|
|
817
|
+
// src/lib/cert.ts
|
|
818
|
+
import fs10 from "fs-extra";
|
|
819
|
+
import path15 from "path";
|
|
820
|
+
var generateCert = async (outDir) => {
|
|
821
|
+
const { stdout } = await exec(`mkcert localhost 127.0.0.1 ::1`);
|
|
822
|
+
[
|
|
823
|
+
{ input: "localhost+2.pem", output: "localhost-cert.pem" },
|
|
824
|
+
{ input: "localhost+2-key.pem", output: "localhost-key.pem" }
|
|
825
|
+
].forEach(({ input, output }) => {
|
|
826
|
+
fs10.moveSync(`./${input}`, path15.join(outDir, output), {
|
|
827
|
+
overwrite: true
|
|
828
|
+
});
|
|
829
|
+
});
|
|
830
|
+
return { stdout };
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
// src/commands/genkey-base.ts
|
|
834
|
+
async function action6(options) {
|
|
835
|
+
const { output } = options;
|
|
836
|
+
console.group("\u{1F373} Generate SSL key for localhost");
|
|
837
|
+
try {
|
|
838
|
+
const { stdout } = await generateCert(output);
|
|
839
|
+
if (stdout) {
|
|
840
|
+
console.log(stdout);
|
|
841
|
+
}
|
|
842
|
+
console.log(`\u{1F511} key generation success. Output to ./${output}`);
|
|
843
|
+
} catch (error) {
|
|
844
|
+
throw error;
|
|
845
|
+
} finally {
|
|
846
|
+
console.groupEnd();
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
// src/commands/plugin-genkey.ts
|
|
851
|
+
function command4() {
|
|
852
|
+
program4.command("genkey").description("Generate SSL key for localhost. (Require mkcert)").action(action7);
|
|
853
|
+
}
|
|
854
|
+
async function action7() {
|
|
855
|
+
await action6({ output: PLUGIN_WORKSPACE_DIRECTORY });
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// src/commands/plugin-init.ts
|
|
859
|
+
import { program as program5 } from "commander";
|
|
860
|
+
import fs11 from "fs-extra";
|
|
861
|
+
import path16 from "path";
|
|
862
|
+
import packer2 from "@kintone/plugin-packer";
|
|
863
|
+
function command5() {
|
|
864
|
+
program5.command("init").description("generate private.ppk and kitting config").action(action8);
|
|
865
|
+
}
|
|
866
|
+
async function action8() {
|
|
867
|
+
console.group("\u{1F373} Executing plugin initialization setup");
|
|
868
|
+
try {
|
|
869
|
+
const manifest = await outputManifest("dev");
|
|
870
|
+
console.log("\u{1F4DD} manifest.json generated");
|
|
871
|
+
await copyPluginContents();
|
|
872
|
+
console.log("\u{1F4C1} contents copied");
|
|
873
|
+
let privateKey;
|
|
874
|
+
const keyPath = path16.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk");
|
|
875
|
+
if (fs11.existsSync(keyPath)) {
|
|
876
|
+
privateKey = await fs11.readFile(keyPath, "utf8");
|
|
877
|
+
}
|
|
878
|
+
await outputContentsZip(manifest);
|
|
879
|
+
const buffer = await getContentsZipBuffer();
|
|
880
|
+
const output = await packer2(buffer, privateKey);
|
|
881
|
+
if (!privateKey) {
|
|
882
|
+
await fs11.writeFile(path16.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk"), output.privateKey);
|
|
883
|
+
console.log("\u{1F511} private.ppk generated");
|
|
884
|
+
} else {
|
|
885
|
+
console.log("\u{1F511} private.ppk already exists. The existing private.ppk will be used.");
|
|
886
|
+
}
|
|
887
|
+
await fs11.writeFile(path16.join(PLUGIN_WORKSPACE_DIRECTORY, "plugin.zip"), output.plugin);
|
|
888
|
+
console.log("\u{1F4E6} plugin.zip generated");
|
|
889
|
+
console.log("\u2728 Plugin initialization setup completed! zip file path is ./.plugin/plugin.zip");
|
|
890
|
+
} catch (error) {
|
|
891
|
+
throw error;
|
|
892
|
+
} finally {
|
|
893
|
+
console.groupEnd();
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// src/commands/manifest/index.ts
|
|
898
|
+
import { program as program6 } from "commander";
|
|
899
|
+
function command6() {
|
|
900
|
+
program6.command("manifest").option("-e, --env <env>", "create manifest", "prod").action(action9);
|
|
901
|
+
}
|
|
902
|
+
async function action9(options) {
|
|
903
|
+
console.group("\u{1F680} Executing manifest generation");
|
|
904
|
+
try {
|
|
905
|
+
const { env } = options;
|
|
906
|
+
if (env !== "prod" && env !== "dev" && env !== "standalone") {
|
|
907
|
+
throw new Error("Invalid environment");
|
|
908
|
+
}
|
|
909
|
+
await copyPluginContents();
|
|
910
|
+
console.log("\u{1F4C1} contents copied");
|
|
911
|
+
await outputManifest(env);
|
|
912
|
+
console.log(`\u{1F4DD} manifest.json generated (${env})`);
|
|
913
|
+
} catch (error) {
|
|
914
|
+
throw error;
|
|
915
|
+
} finally {
|
|
916
|
+
console.groupEnd();
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
// src/commands/test/index.ts
|
|
921
|
+
import { program as program7 } from "commander";
|
|
922
|
+
import fs12 from "fs-extra";
|
|
923
|
+
function command7() {
|
|
924
|
+
program7.command("test").description("test").action(action10);
|
|
925
|
+
}
|
|
926
|
+
async function action10() {
|
|
927
|
+
console.group("package.json");
|
|
928
|
+
const packageJson = fs12.readJSONSync("package.json");
|
|
929
|
+
console.log("package.json detected");
|
|
930
|
+
console.groupEnd();
|
|
931
|
+
console.group("Config");
|
|
932
|
+
const config2 = await esmImport("plugin.config.mjs");
|
|
933
|
+
console.log("plugin.config.mjs detected", config2);
|
|
934
|
+
console.groupEnd();
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
// src/commands/plugin-zip.ts
|
|
938
|
+
import { program as program8 } from "commander";
|
|
939
|
+
import fs13 from "fs-extra";
|
|
940
|
+
import path17 from "path";
|
|
941
|
+
import packer3 from "@kintone/plugin-packer";
|
|
942
|
+
function command8() {
|
|
943
|
+
program8.command("zip").description("generate plugin zip").option("-e, --env <env>", "plugin environment (dev, prod, standalone)", "prod").option(
|
|
944
|
+
"-p, --ppk <ppk>",
|
|
945
|
+
".ppk file path",
|
|
946
|
+
path17.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk")
|
|
947
|
+
).action(action11);
|
|
948
|
+
}
|
|
949
|
+
async function action11(options) {
|
|
950
|
+
console.group("\u{1F373} Executing plugin zip generation");
|
|
951
|
+
try {
|
|
952
|
+
const { env, ppk: ppkPath } = options;
|
|
953
|
+
if (!isEnv(env)) {
|
|
954
|
+
throw new Error("Invalid environment");
|
|
955
|
+
}
|
|
956
|
+
await copyPluginContents();
|
|
957
|
+
console.log("\u{1F4C1} contents copied");
|
|
958
|
+
const manifest = await outputManifest(env);
|
|
959
|
+
console.log(`\u{1F4DD} manifest.json generated (${env})`);
|
|
960
|
+
await outputContentsZip(manifest);
|
|
961
|
+
console.log("\u{1F4E6} contents.zip generated");
|
|
962
|
+
const buffer = await getContentsZipBuffer();
|
|
963
|
+
const privateKey = await fs13.readFile(path17.resolve(ppkPath), "utf8");
|
|
964
|
+
const output = await packer3(buffer, privateKey);
|
|
965
|
+
const zipFileName = `plugin${getZipFileNameSuffix(env)}.zip`;
|
|
966
|
+
await fs13.writeFile(path17.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName), output.plugin);
|
|
967
|
+
console.log("\u{1F4E6} plugin.zip generated");
|
|
968
|
+
const version = String(manifest.version);
|
|
969
|
+
await fs13.writeFile(path17.join(PLUGIN_WORKSPACE_DIRECTORY, "version"), version);
|
|
970
|
+
console.log(`\u{1F4DD} version file generated (${version})`);
|
|
971
|
+
console.log(`\u2728 Plugin zip generation completed! zip file path is ./.plugin/${zipFileName}`);
|
|
972
|
+
} catch (error) {
|
|
973
|
+
throw error;
|
|
974
|
+
} finally {
|
|
975
|
+
console.groupEnd();
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
// src/commands/lint.ts
|
|
980
|
+
import { program as program9 } from "commander";
|
|
981
|
+
function command9() {
|
|
982
|
+
program9.command("lint").description("Lint source files").option("-c, --config <config>", "Config file path").action(action12);
|
|
983
|
+
}
|
|
984
|
+
async function action12(options) {
|
|
985
|
+
try {
|
|
986
|
+
lint();
|
|
987
|
+
} catch (error) {
|
|
988
|
+
throw error;
|
|
989
|
+
} finally {
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
// src/commands/plugin-tsup.ts
|
|
994
|
+
import { program as program10 } from "commander";
|
|
995
|
+
import fs14 from "fs-extra";
|
|
996
|
+
import path18 from "path";
|
|
997
|
+
|
|
998
|
+
// src/lib/tsup.ts
|
|
999
|
+
import { build as build2 } from "tsup";
|
|
1000
|
+
var completeBuildOptions2 = (params) => {
|
|
1001
|
+
return {
|
|
1002
|
+
bundle: true,
|
|
1003
|
+
minify: "terser",
|
|
1004
|
+
splitting: false,
|
|
1005
|
+
noExternal: [/.*/],
|
|
1006
|
+
platform: "browser",
|
|
1007
|
+
dts: true,
|
|
1008
|
+
...params,
|
|
1009
|
+
esbuildOptions(options, context) {
|
|
1010
|
+
options.legalComments = "none";
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
};
|
|
1014
|
+
var buildWithTsup = async (buildOptions) => {
|
|
1015
|
+
const options = completeBuildOptions2(buildOptions);
|
|
1016
|
+
await build2(options);
|
|
1017
|
+
};
|
|
1018
|
+
|
|
1019
|
+
// src/commands/plugin-tsup.ts
|
|
1020
|
+
function command10() {
|
|
1021
|
+
program10.command("tsup").description("Build the project for production. (It's a wrapper of webpack build command.)").action(action13);
|
|
1022
|
+
}
|
|
1023
|
+
async function action13() {
|
|
1024
|
+
console.group("\u{1F373} Build the project for production");
|
|
1025
|
+
try {
|
|
1026
|
+
const config2 = await importK2PluginConfig();
|
|
1027
|
+
if (config2?.lint?.build) {
|
|
1028
|
+
await lint();
|
|
1029
|
+
console.log("\u2728 Lint success.");
|
|
1030
|
+
}
|
|
1031
|
+
if (!fs14.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
|
|
1032
|
+
await fs14.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
|
|
1033
|
+
}
|
|
1034
|
+
if (config2.tailwind?.css && config2.tailwind?.config) {
|
|
1035
|
+
const tailwindConfig = await getTailwindConfig(config2.tailwind);
|
|
1036
|
+
const inputFile = getTailwindInputCss(config2.tailwind);
|
|
1037
|
+
await outputCss({
|
|
1038
|
+
inputPath: inputFile.config,
|
|
1039
|
+
outputPath: path18.join(PLUGIN_CONTENTS_DIRECTORY, "config.css"),
|
|
1040
|
+
config: tailwindConfig.config,
|
|
1041
|
+
minify: true
|
|
1042
|
+
});
|
|
1043
|
+
console.log("\u2728 Built config.css");
|
|
1044
|
+
await outputCss({
|
|
1045
|
+
inputPath: inputFile.desktop,
|
|
1046
|
+
outputPath: path18.join(PLUGIN_CONTENTS_DIRECTORY, "desktop.css"),
|
|
1047
|
+
config: tailwindConfig.desktop,
|
|
1048
|
+
minify: true
|
|
1049
|
+
});
|
|
1050
|
+
console.log("\u2728 Built desktop.css");
|
|
1051
|
+
}
|
|
1052
|
+
const entryPoints = ["desktop", "config"].reduce(
|
|
1053
|
+
(acc, dir) => ({
|
|
1054
|
+
...acc,
|
|
1055
|
+
[dir]: path18.join("src", dir, "index.ts")
|
|
1056
|
+
}),
|
|
1057
|
+
{}
|
|
1058
|
+
);
|
|
1059
|
+
await buildWithTsup({
|
|
1060
|
+
entryPoints,
|
|
1061
|
+
outDir: PLUGIN_CONTENTS_DIRECTORY,
|
|
1062
|
+
minify: true,
|
|
1063
|
+
treeshake: true,
|
|
1064
|
+
sourcemap: false
|
|
1065
|
+
});
|
|
1066
|
+
console.log("\u2728 Built desktop.js and config.js");
|
|
1067
|
+
console.log("\u2728 Build success.");
|
|
1068
|
+
} catch (error) {
|
|
1069
|
+
throw error;
|
|
1070
|
+
} finally {
|
|
1071
|
+
console.groupEnd();
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
// src/plugin.ts
|
|
1076
|
+
program11.name("plugin").version("1.12.0").description("\u{1F373} kintone kitchen \u{1F373} for kintone plugin");
|
|
1077
|
+
command();
|
|
1078
|
+
command2();
|
|
1079
|
+
command3();
|
|
1080
|
+
command4();
|
|
1081
|
+
command5();
|
|
1082
|
+
command6();
|
|
1083
|
+
command7();
|
|
1084
|
+
command8();
|
|
1085
|
+
command9();
|
|
1086
|
+
command10();
|
|
1087
|
+
program11.parse(process.argv);
|
|
25
1088
|
//# sourceMappingURL=plugin.js.map
|