@konomi-app/k2 2.1.5 → 3.0.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.js +278 -257
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +346 -284
- package/dist/plugin.js.map +1 -1
- package/package.json +7 -21
package/dist/plugin.js
CHANGED
|
@@ -1,32 +1,40 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
2
8
|
|
|
3
9
|
// src/plugin.ts
|
|
4
10
|
import { program as program11 } from "commander";
|
|
5
11
|
|
|
6
12
|
// src/commands/plugin-build.ts
|
|
7
13
|
import { program } from "commander";
|
|
8
|
-
import
|
|
14
|
+
import fs3 from "fs-extra";
|
|
9
15
|
import path5 from "path";
|
|
10
|
-
import "
|
|
16
|
+
import chalk2 from "chalk";
|
|
11
17
|
|
|
12
18
|
// src/lib/constants.ts
|
|
13
19
|
import path from "path";
|
|
14
20
|
var WORKSPACE_DIRECTORY = ".k2";
|
|
15
21
|
var DEVELOPMENT_DIRECTORY = path.join(WORKSPACE_DIRECTORY, "dev");
|
|
22
|
+
var PRODUCTION_DIRECTORY = path.join(WORKSPACE_DIRECTORY, "prod");
|
|
16
23
|
var PLUGIN_CONFIG_FILE_NAME = "plugin.config.mjs";
|
|
17
24
|
var PLUGIN_WORKSPACE_DIRECTORY = ".plugin";
|
|
18
25
|
var PLUGIN_CONTENTS_DIRECTORY = path.join(PLUGIN_WORKSPACE_DIRECTORY, "contents");
|
|
19
26
|
var PLUGIN_DEVELOPMENT_DIRECTORY = path.join(PLUGIN_WORKSPACE_DIRECTORY, "dev");
|
|
27
|
+
var PLUGIN_PRODUCTION_DIRECTORY = path.join(PLUGIN_WORKSPACE_DIRECTORY, "prod");
|
|
20
28
|
var DEFAULT_PORT = 32767;
|
|
21
29
|
|
|
22
30
|
// src/lib/import.ts
|
|
23
31
|
import { pathToFileURL } from "url";
|
|
24
32
|
import path2 from "path";
|
|
25
|
-
var esmImport = (
|
|
33
|
+
var esmImport = (path18) => {
|
|
26
34
|
if (process.platform === "win32") {
|
|
27
|
-
return import(pathToFileURL(
|
|
35
|
+
return import(pathToFileURL(path18).toString());
|
|
28
36
|
} else {
|
|
29
|
-
return import(
|
|
37
|
+
return import(path18);
|
|
30
38
|
}
|
|
31
39
|
};
|
|
32
40
|
var importK2PluginConfig = async (configFileName) => {
|
|
@@ -106,106 +114,21 @@ var watchTailwindCSS = async (params) => {
|
|
|
106
114
|
watcher.on("error", (error) => {
|
|
107
115
|
console.error("Error watching Tailwind CSS:", error);
|
|
108
116
|
});
|
|
109
|
-
watcher.on("add", (
|
|
117
|
+
watcher.on("add", (path18) => {
|
|
110
118
|
debouncedProcessChanges.call("add");
|
|
111
119
|
});
|
|
112
|
-
watcher.on("change", (
|
|
120
|
+
watcher.on("change", (path18) => {
|
|
113
121
|
debouncedProcessChanges.call("change");
|
|
114
122
|
});
|
|
115
|
-
watcher.on("unlink", (
|
|
123
|
+
watcher.on("unlink", (path18) => {
|
|
116
124
|
debouncedProcessChanges.call("unlink");
|
|
117
125
|
});
|
|
118
|
-
watcher.on("unlinkDir", (
|
|
126
|
+
watcher.on("unlinkDir", (path18) => {
|
|
119
127
|
debouncedProcessChanges.call("unlink");
|
|
120
128
|
});
|
|
121
129
|
return watcher;
|
|
122
130
|
};
|
|
123
131
|
|
|
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
132
|
// src/lib/lint.ts
|
|
210
133
|
import { ESLint } from "eslint";
|
|
211
134
|
import globals from "globals";
|
|
@@ -235,11 +158,118 @@ async function lint() {
|
|
|
235
158
|
}
|
|
236
159
|
}
|
|
237
160
|
|
|
161
|
+
// src/lib/vite.ts
|
|
162
|
+
import path4 from "path";
|
|
163
|
+
import fs2 from "fs-extra";
|
|
164
|
+
import { build as viteBuild } from "vite";
|
|
165
|
+
import chalk from "chalk";
|
|
166
|
+
var createViteConfig = (config2 = {}) => {
|
|
167
|
+
const plugins = [...config2.plugins ?? []];
|
|
168
|
+
try {
|
|
169
|
+
const tsconfigPaths = __require("vite-tsconfig-paths");
|
|
170
|
+
plugins.push(tsconfigPaths.default ? tsconfigPaths.default() : tsconfigPaths());
|
|
171
|
+
} catch {
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
...config2,
|
|
175
|
+
configFile: false,
|
|
176
|
+
build: {
|
|
177
|
+
...config2.build,
|
|
178
|
+
cssCodeSplit: false,
|
|
179
|
+
rollupOptions: {
|
|
180
|
+
...config2.build?.rollupOptions,
|
|
181
|
+
onwarn: (warning, warn) => {
|
|
182
|
+
if (["MODULE_LEVEL_DIRECTIVE"].includes(warning.code ?? "")) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
warn(warning);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
plugins,
|
|
190
|
+
resolve: {
|
|
191
|
+
...config2.resolve,
|
|
192
|
+
alias: {
|
|
193
|
+
"@": path4.resolve(process.cwd(), "src"),
|
|
194
|
+
...config2.resolve?.alias
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
async function buildEntriesWithVite(params) {
|
|
200
|
+
const {
|
|
201
|
+
entries,
|
|
202
|
+
outDir,
|
|
203
|
+
mode = "production",
|
|
204
|
+
sourcemap = false,
|
|
205
|
+
minify = true,
|
|
206
|
+
viteConfig = {}
|
|
207
|
+
} = params;
|
|
208
|
+
for (const name of Object.keys(entries)) {
|
|
209
|
+
const entryPath = entries[name];
|
|
210
|
+
const config2 = createViteConfig({
|
|
211
|
+
...viteConfig,
|
|
212
|
+
mode,
|
|
213
|
+
build: {
|
|
214
|
+
...viteConfig.build,
|
|
215
|
+
lib: {
|
|
216
|
+
entry: entryPath,
|
|
217
|
+
name,
|
|
218
|
+
fileName: () => `${name}.js`,
|
|
219
|
+
formats: ["iife"]
|
|
220
|
+
},
|
|
221
|
+
rollupOptions: {
|
|
222
|
+
...viteConfig.build?.rollupOptions,
|
|
223
|
+
output: {
|
|
224
|
+
assetFileNames: `${name}.[ext]`,
|
|
225
|
+
...viteConfig.build?.rollupOptions?.output
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
outDir,
|
|
229
|
+
emptyOutDir: false,
|
|
230
|
+
sourcemap,
|
|
231
|
+
minify,
|
|
232
|
+
cssCodeSplit: false
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
await viteBuild(config2);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
var ENTRY_FILE_NAMES = ["index.ts", "index.tsx", "index.js", "index.jsx", "index.mjs"];
|
|
239
|
+
function findEntryPoint(basePath) {
|
|
240
|
+
for (const filename of ENTRY_FILE_NAMES) {
|
|
241
|
+
const entryPath = path4.join(basePath, filename);
|
|
242
|
+
if (fs2.existsSync(entryPath)) {
|
|
243
|
+
return entryPath;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (fs2.existsSync(basePath) && fs2.statSync(basePath).isFile()) {
|
|
247
|
+
return basePath;
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
function getPluginEntryPoints(options) {
|
|
252
|
+
const entries = {};
|
|
253
|
+
const configPath = findEntryPoint(options.configEntry);
|
|
254
|
+
if (configPath) {
|
|
255
|
+
entries["config"] = configPath;
|
|
256
|
+
} else {
|
|
257
|
+
console.log(chalk.yellow(` \u26A0 Config entry not found: ${options.configEntry}`));
|
|
258
|
+
}
|
|
259
|
+
const desktopPath = findEntryPoint(options.desktopEntry);
|
|
260
|
+
if (desktopPath) {
|
|
261
|
+
entries["desktop"] = desktopPath;
|
|
262
|
+
} else {
|
|
263
|
+
console.log(chalk.yellow(` \u26A0 Desktop entry not found: ${options.desktopEntry}`));
|
|
264
|
+
}
|
|
265
|
+
return entries;
|
|
266
|
+
}
|
|
267
|
+
|
|
238
268
|
// src/commands/plugin-build.ts
|
|
239
269
|
function command() {
|
|
240
|
-
program.command("build").description("Build the project for production
|
|
270
|
+
program.command("build").description("Build the project for production with Vite.").action(action);
|
|
241
271
|
}
|
|
242
|
-
async function
|
|
272
|
+
async function action() {
|
|
243
273
|
console.group("\u{1F373} Build the project for production");
|
|
244
274
|
try {
|
|
245
275
|
const config2 = await importK2PluginConfig();
|
|
@@ -247,13 +277,19 @@ async function action2() {
|
|
|
247
277
|
await lint();
|
|
248
278
|
console.log("\u2728 Lint success.");
|
|
249
279
|
}
|
|
250
|
-
if (!
|
|
251
|
-
await
|
|
280
|
+
if (!fs3.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
|
|
281
|
+
await fs3.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
|
|
282
|
+
}
|
|
283
|
+
await fs3.emptyDir(PLUGIN_CONTENTS_DIRECTORY);
|
|
284
|
+
const entries = getPluginEntryPoints({
|
|
285
|
+
configEntry: path5.resolve("src", "config"),
|
|
286
|
+
desktopEntry: path5.resolve("src", "desktop")
|
|
287
|
+
});
|
|
288
|
+
const entryNames = Object.keys(entries);
|
|
289
|
+
if (entryNames.length === 0) {
|
|
290
|
+
throw new Error("No entry points found for plugin. Check src/config and src/desktop paths.");
|
|
252
291
|
}
|
|
253
|
-
|
|
254
|
-
desktop: path5.join("src", "desktop", "index.ts"),
|
|
255
|
-
config: path5.join("src", "config", "index.ts")
|
|
256
|
-
};
|
|
292
|
+
console.log(chalk2.gray(` Entry points: ${entryNames.join(", ")}`));
|
|
257
293
|
if (config2.tailwind?.css && config2.tailwind?.config) {
|
|
258
294
|
const tailwindConfig = await getTailwindConfig(config2.tailwind);
|
|
259
295
|
const inputFile = getTailwindInputCss(config2.tailwind);
|
|
@@ -272,7 +308,13 @@ async function action2() {
|
|
|
272
308
|
});
|
|
273
309
|
console.log("\u2728 Built desktop.css");
|
|
274
310
|
}
|
|
275
|
-
await
|
|
311
|
+
await buildEntriesWithVite({
|
|
312
|
+
entries,
|
|
313
|
+
outDir: PLUGIN_CONTENTS_DIRECTORY,
|
|
314
|
+
mode: "production",
|
|
315
|
+
sourcemap: false,
|
|
316
|
+
minify: true
|
|
317
|
+
});
|
|
276
318
|
console.log("\u2728 Built desktop.js and config.js");
|
|
277
319
|
console.log("\u2728 Build success.");
|
|
278
320
|
} catch (error) {
|
|
@@ -284,56 +326,13 @@ async function action2() {
|
|
|
284
326
|
|
|
285
327
|
// src/commands/plugin-esbuild.ts
|
|
286
328
|
import { program as program2 } from "commander";
|
|
287
|
-
import
|
|
329
|
+
import fs4 from "fs-extra";
|
|
288
330
|
import path6 from "path";
|
|
289
|
-
import "
|
|
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
|
|
331
|
+
import chalk3 from "chalk";
|
|
333
332
|
function command2() {
|
|
334
|
-
program2.command("esbuild").description("Build the project for production. (
|
|
333
|
+
program2.command("esbuild").description("Build the project for production with Vite. (Legacy command name, now uses Vite)").action(action2);
|
|
335
334
|
}
|
|
336
|
-
async function
|
|
335
|
+
async function action2() {
|
|
337
336
|
console.group("\u{1F373} Build the project for production");
|
|
338
337
|
try {
|
|
339
338
|
const config2 = await importK2PluginConfig();
|
|
@@ -341,9 +340,10 @@ async function action3() {
|
|
|
341
340
|
await lint();
|
|
342
341
|
console.log("\u2728 Lint success.");
|
|
343
342
|
}
|
|
344
|
-
if (!
|
|
345
|
-
await
|
|
343
|
+
if (!fs4.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
|
|
344
|
+
await fs4.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
|
|
346
345
|
}
|
|
346
|
+
await fs4.emptyDir(PLUGIN_CONTENTS_DIRECTORY);
|
|
347
347
|
if (config2.tailwind?.css && config2.tailwind?.config) {
|
|
348
348
|
const tailwindConfig = await getTailwindConfig(config2.tailwind);
|
|
349
349
|
const inputFile = getTailwindInputCss(config2.tailwind);
|
|
@@ -362,16 +362,21 @@ async function action3() {
|
|
|
362
362
|
});
|
|
363
363
|
console.log("\u2728 Built desktop.css");
|
|
364
364
|
}
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
})
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
365
|
+
const entries = getPluginEntryPoints({
|
|
366
|
+
configEntry: path6.resolve("src", "config"),
|
|
367
|
+
desktopEntry: path6.resolve("src", "desktop")
|
|
368
|
+
});
|
|
369
|
+
const entryNames = Object.keys(entries);
|
|
370
|
+
if (entryNames.length === 0) {
|
|
371
|
+
throw new Error("No entry points found for plugin. Check src/config and src/desktop paths.");
|
|
372
|
+
}
|
|
373
|
+
console.log(chalk3.gray(` Entry points: ${entryNames.join(", ")}`));
|
|
374
|
+
await buildEntriesWithVite({
|
|
375
|
+
entries,
|
|
376
|
+
outDir: PLUGIN_CONTENTS_DIRECTORY,
|
|
377
|
+
mode: "production",
|
|
373
378
|
sourcemap: false,
|
|
374
|
-
|
|
379
|
+
minify: true
|
|
375
380
|
});
|
|
376
381
|
console.log("\u2728 Built desktop.js and config.js");
|
|
377
382
|
console.log("\u2728 Build success.");
|
|
@@ -384,37 +389,55 @@ async function action3() {
|
|
|
384
389
|
|
|
385
390
|
// src/commands/plugin-dev/index.ts
|
|
386
391
|
import { program as program3 } from "commander";
|
|
387
|
-
import "
|
|
388
|
-
import
|
|
392
|
+
import { createServer } from "vite";
|
|
393
|
+
import fs11 from "fs-extra";
|
|
389
394
|
import path14 from "path";
|
|
395
|
+
import chalk6 from "chalk";
|
|
396
|
+
|
|
397
|
+
// src/lib/exec.ts
|
|
398
|
+
import { exec as defaultExec } from "child_process";
|
|
399
|
+
import { promisify } from "util";
|
|
400
|
+
var exec = promisify(defaultExec);
|
|
390
401
|
|
|
391
|
-
// src/
|
|
392
|
-
import "
|
|
402
|
+
// src/lib/cert.ts
|
|
403
|
+
import fs5 from "fs-extra";
|
|
393
404
|
import path7 from "path";
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
405
|
+
var CERT_KEY_FILENAME = "localhost-key.pem";
|
|
406
|
+
var CERT_FILENAME = "localhost-cert.pem";
|
|
407
|
+
var generateCert = async (outDir) => {
|
|
408
|
+
await fs5.ensureDir(outDir);
|
|
409
|
+
const { stdout } = await exec(`mkcert localhost 127.0.0.1 ::1`);
|
|
410
|
+
[
|
|
411
|
+
{ input: "localhost+2.pem", output: CERT_FILENAME },
|
|
412
|
+
{ input: "localhost+2-key.pem", output: CERT_KEY_FILENAME }
|
|
413
|
+
].forEach(({ input, output }) => {
|
|
414
|
+
if (fs5.existsSync(input)) {
|
|
415
|
+
fs5.moveSync(`./${input}`, path7.join(outDir, output), {
|
|
416
|
+
overwrite: true
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
return { stdout };
|
|
421
|
+
};
|
|
422
|
+
function hasCertificates(certDir) {
|
|
423
|
+
return fs5.existsSync(path7.join(certDir, CERT_KEY_FILENAME)) && fs5.existsSync(path7.join(certDir, CERT_FILENAME));
|
|
424
|
+
}
|
|
425
|
+
function loadCertificates(certDir) {
|
|
426
|
+
return {
|
|
427
|
+
key: fs5.readFileSync(path7.join(certDir, CERT_KEY_FILENAME)),
|
|
428
|
+
cert: fs5.readFileSync(path7.join(certDir, CERT_FILENAME))
|
|
429
|
+
};
|
|
407
430
|
}
|
|
408
431
|
|
|
409
432
|
// src/lib/plugin-manifest.ts
|
|
410
|
-
import
|
|
433
|
+
import fs6 from "fs-extra";
|
|
411
434
|
import path8 from "path";
|
|
412
435
|
import merge from "deepmerge";
|
|
413
436
|
var outputManifest = async (env, options) => {
|
|
414
437
|
const config2 = options?.config || await importK2PluginConfig();
|
|
415
438
|
const merged = merge(config2.manifest.base, config2.manifest[env] || {});
|
|
416
|
-
await
|
|
417
|
-
await
|
|
439
|
+
await fs6.mkdirs(PLUGIN_CONTENTS_DIRECTORY);
|
|
440
|
+
await fs6.writeJson(path8.join(PLUGIN_CONTENTS_DIRECTORY, "manifest.json"), merged);
|
|
418
441
|
return merged;
|
|
419
442
|
};
|
|
420
443
|
|
|
@@ -451,7 +474,7 @@ var getManifest = async (params) => {
|
|
|
451
474
|
// src/commands/plugin-dev/tailwind.ts
|
|
452
475
|
import path9 from "path";
|
|
453
476
|
import "tailwindcss";
|
|
454
|
-
import
|
|
477
|
+
import chalk4 from "chalk";
|
|
455
478
|
async function buildTailwindCSS(params) {
|
|
456
479
|
const { inputFile, outputFileName, config: config2 } = params;
|
|
457
480
|
const inputPath = path9.resolve(inputFile);
|
|
@@ -463,7 +486,7 @@ async function buildTailwindCSS(params) {
|
|
|
463
486
|
onChanges: ({ output, type }) => {
|
|
464
487
|
const outputFileName2 = path9.basename(output);
|
|
465
488
|
console.log(
|
|
466
|
-
|
|
489
|
+
chalk4.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk4.cyan(`[css] `) + outputFileName2 + (type === "init" ? " init" : ` rebuilt`)
|
|
467
490
|
);
|
|
468
491
|
}
|
|
469
492
|
});
|
|
@@ -492,20 +515,20 @@ var watchCss = async (pluginConfig) => {
|
|
|
492
515
|
import packer from "@kintone/plugin-packer";
|
|
493
516
|
|
|
494
517
|
// src/lib/plugin-contents.ts
|
|
495
|
-
import
|
|
518
|
+
import fs7 from "fs-extra";
|
|
496
519
|
import path10 from "path";
|
|
497
520
|
import htmlMinifier from "html-minifier";
|
|
498
521
|
var copyPluginContents = async (params = {}) => {
|
|
499
522
|
const { inputDir = path10.join("src", "contents"), outputDir = PLUGIN_CONTENTS_DIRECTORY } = params;
|
|
500
|
-
if (!
|
|
501
|
-
await
|
|
523
|
+
if (!fs7.existsSync(inputDir)) {
|
|
524
|
+
await fs7.mkdir(inputDir, { recursive: true });
|
|
502
525
|
}
|
|
503
|
-
await
|
|
526
|
+
await fs7.copy(inputDir, outputDir, { overwrite: true });
|
|
504
527
|
const configHtmlPath = path10.join(outputDir, "config.html");
|
|
505
|
-
if (!
|
|
528
|
+
if (!fs7.existsSync(configHtmlPath)) {
|
|
506
529
|
throw new Error(`Plugin HTML file not found. Create "config.html" in ${inputDir}.`);
|
|
507
530
|
}
|
|
508
|
-
const html = await
|
|
531
|
+
const html = await fs7.readFile(configHtmlPath, "utf8");
|
|
509
532
|
const minified = htmlMinifier.minify(html, {
|
|
510
533
|
minifyCSS: true,
|
|
511
534
|
collapseWhitespace: true,
|
|
@@ -516,12 +539,12 @@ var copyPluginContents = async (params = {}) => {
|
|
|
516
539
|
removeTagWhitespace: true,
|
|
517
540
|
useShortDoctype: true
|
|
518
541
|
});
|
|
519
|
-
await
|
|
542
|
+
await fs7.writeFile(configHtmlPath, minified);
|
|
520
543
|
};
|
|
521
544
|
|
|
522
545
|
// src/lib/zip.ts
|
|
523
546
|
import archiver from "archiver";
|
|
524
|
-
import
|
|
547
|
+
import fs8 from "fs-extra";
|
|
525
548
|
import path11 from "path";
|
|
526
549
|
import invariant2 from "tiny-invariant";
|
|
527
550
|
var outputContentsZip = async (manifest) => {
|
|
@@ -534,7 +557,7 @@ var outputContentsZip = async (manifest) => {
|
|
|
534
557
|
}
|
|
535
558
|
});
|
|
536
559
|
const outputZipPath = path11.join(PLUGIN_WORKSPACE_DIRECTORY, "contents.zip");
|
|
537
|
-
const outputZipStream =
|
|
560
|
+
const outputZipStream = fs8.createWriteStream(outputZipPath);
|
|
538
561
|
outputZipStream.on("close", () => {
|
|
539
562
|
console.log(`\u{1F4E6} ${archive.pointer()} total bytes`);
|
|
540
563
|
});
|
|
@@ -566,7 +589,7 @@ var outputContentsZip = async (manifest) => {
|
|
|
566
589
|
console.groupEnd();
|
|
567
590
|
for (const file of targetFiles) {
|
|
568
591
|
const filePath = path11.join(PLUGIN_CONTENTS_DIRECTORY, file);
|
|
569
|
-
if (!
|
|
592
|
+
if (!fs8.existsSync(filePath)) {
|
|
570
593
|
throw new Error(`${filePath} does not exist`);
|
|
571
594
|
}
|
|
572
595
|
archive.file(filePath, { name: file });
|
|
@@ -577,14 +600,14 @@ var outputContentsZip = async (manifest) => {
|
|
|
577
600
|
};
|
|
578
601
|
var getContentsZipBuffer = async () => {
|
|
579
602
|
const outputZipPath = path11.join(PLUGIN_WORKSPACE_DIRECTORY, "contents.zip");
|
|
580
|
-
return
|
|
603
|
+
return fs8.readFile(outputZipPath);
|
|
581
604
|
};
|
|
582
605
|
var getZipFileNameSuffix = (env) => {
|
|
583
606
|
return env === "prod" ? "" : `-${env}`;
|
|
584
607
|
};
|
|
585
608
|
|
|
586
609
|
// src/commands/plugin-dev/upload.ts
|
|
587
|
-
import
|
|
610
|
+
import fs10 from "fs-extra";
|
|
588
611
|
import path13 from "path";
|
|
589
612
|
|
|
590
613
|
// src/lib/kintone-api-client.ts
|
|
@@ -620,8 +643,8 @@ KINTONE_PASSWORD`);
|
|
|
620
643
|
this.#baseUrl = KINTONE_BASE_URL;
|
|
621
644
|
this.#authHeader = authHeader;
|
|
622
645
|
}
|
|
623
|
-
getEndpointUrl(
|
|
624
|
-
return `${this.#baseUrl}${
|
|
646
|
+
getEndpointUrl(path18) {
|
|
647
|
+
return `${this.#baseUrl}${path18}`;
|
|
625
648
|
}
|
|
626
649
|
async upload(params) {
|
|
627
650
|
const { blob, fileName } = params;
|
|
@@ -692,7 +715,7 @@ KINTONE_PASSWORD`);
|
|
|
692
715
|
};
|
|
693
716
|
|
|
694
717
|
// src/lib/utils.ts
|
|
695
|
-
import
|
|
718
|
+
import fs9 from "fs-extra";
|
|
696
719
|
import path12 from "path";
|
|
697
720
|
var isEnv = (env) => {
|
|
698
721
|
return ["prod", "dev", "standalone"].includes(env);
|
|
@@ -701,7 +724,7 @@ var apiUploadZip = async (params) => {
|
|
|
701
724
|
const { env, pluginId } = params;
|
|
702
725
|
const kc = new KintoneApiClient();
|
|
703
726
|
const zipFileName = `plugin${getZipFileNameSuffix(env)}.zip`;
|
|
704
|
-
const zipFile = new Blob([await
|
|
727
|
+
const zipFile = new Blob([await fs9.readFile(path12.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName))]);
|
|
705
728
|
const fileKey = await kc.upload({ blob: zipFile, fileName: zipFileName });
|
|
706
729
|
const plugins = await kc.getAllPlugins();
|
|
707
730
|
const plugin = plugins.find((p) => p.id === pluginId);
|
|
@@ -721,7 +744,7 @@ var apiUploadZip = async (params) => {
|
|
|
721
744
|
|
|
722
745
|
// src/commands/plugin-dev/upload.ts
|
|
723
746
|
import chokider from "chokidar";
|
|
724
|
-
import
|
|
747
|
+
import chalk5 from "chalk";
|
|
725
748
|
var watchContentsAndUploadZip = async (params) => {
|
|
726
749
|
const { manifest, ppkPath } = params;
|
|
727
750
|
let initialScanComplete = false;
|
|
@@ -732,7 +755,7 @@ var watchContentsAndUploadZip = async (params) => {
|
|
|
732
755
|
}
|
|
733
756
|
await copyPluginContents();
|
|
734
757
|
console.log(
|
|
735
|
-
|
|
758
|
+
chalk5.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk5.cyan(`[contents] `) + `updated`
|
|
736
759
|
);
|
|
737
760
|
} catch (error) {
|
|
738
761
|
console.error("Error copying plugin contents:", error);
|
|
@@ -741,17 +764,17 @@ var watchContentsAndUploadZip = async (params) => {
|
|
|
741
764
|
try {
|
|
742
765
|
await outputContentsZip(manifest);
|
|
743
766
|
const buffer = await getContentsZipBuffer();
|
|
744
|
-
const pluginPrivateKey = await
|
|
767
|
+
const pluginPrivateKey = await fs10.readFile(path13.resolve(ppkPath), "utf8");
|
|
745
768
|
const output = await packer(buffer, pluginPrivateKey);
|
|
746
769
|
const zipFileName = `plugin${getZipFileNameSuffix("dev")}.zip`;
|
|
747
|
-
await
|
|
770
|
+
await fs10.writeFile(path13.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName), output.plugin);
|
|
748
771
|
const { method } = await apiUploadZip({ env: "dev", pluginId: output.id });
|
|
749
772
|
console.log(
|
|
750
|
-
|
|
773
|
+
chalk5.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk5.cyan(`[upload] `) + `uploaded ${method === "POST" ? "(new)" : "(update)"}`
|
|
751
774
|
);
|
|
752
775
|
} catch (error) {
|
|
753
776
|
console.log(
|
|
754
|
-
|
|
777
|
+
chalk5.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk5.cyan(`[upload] `) + chalk5.red(`failed`) + chalk5.hex("#e5e7eb")(`: ${error?.message ?? "Unknown error"}`)
|
|
755
778
|
);
|
|
756
779
|
}
|
|
757
780
|
};
|
|
@@ -774,64 +797,103 @@ function command3() {
|
|
|
774
797
|
"-p, --ppk <ppk>",
|
|
775
798
|
".ppk file path",
|
|
776
799
|
path14.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk")
|
|
777
|
-
).option("-c, --cert-dir <certDir>", "Certificate directory", PLUGIN_WORKSPACE_DIRECTORY).description("Start development server.").action(
|
|
800
|
+
).option("-c, --cert-dir <certDir>", "Certificate directory", PLUGIN_WORKSPACE_DIRECTORY).description("Start development server with Vite.").action(action3);
|
|
778
801
|
}
|
|
779
|
-
async function
|
|
802
|
+
async function action3(options) {
|
|
780
803
|
console.group("\u{1F373} Start development server");
|
|
781
804
|
try {
|
|
782
805
|
const { ppk: ppkPath, certDir } = options;
|
|
783
806
|
const config2 = await importK2PluginConfig();
|
|
784
|
-
|
|
785
|
-
|
|
807
|
+
const certDirPath = path14.resolve(certDir);
|
|
808
|
+
const outputDir = path14.resolve(PLUGIN_DEVELOPMENT_DIRECTORY);
|
|
809
|
+
if (!fs11.existsSync(PLUGIN_DEVELOPMENT_DIRECTORY)) {
|
|
810
|
+
await fs11.mkdir(PLUGIN_DEVELOPMENT_DIRECTORY, { recursive: true });
|
|
786
811
|
}
|
|
787
812
|
const port = config2.server?.port ?? DEFAULT_PORT;
|
|
813
|
+
if (!hasCertificates(certDirPath)) {
|
|
814
|
+
console.log(chalk6.yellow("\u{1F4DC} SSL certificates not found. Generating..."));
|
|
815
|
+
try {
|
|
816
|
+
await generateCert(certDirPath);
|
|
817
|
+
console.log(chalk6.green("\u2705 SSL certificates generated successfully"));
|
|
818
|
+
} catch (error) {
|
|
819
|
+
console.log(
|
|
820
|
+
chalk6.red("\u274C Failed to generate SSL certificates. Make sure mkcert is installed.")
|
|
821
|
+
);
|
|
822
|
+
console.log(chalk6.gray(" Install mkcert: https://github.com/FiloSottile/mkcert"));
|
|
823
|
+
throw error;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
788
826
|
const manifest = await getManifest({ config: config2, port });
|
|
789
827
|
console.log(`\u{1F4DD} manifest.json generated`);
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
828
|
+
const entries = getPluginEntryPoints({
|
|
829
|
+
configEntry: path14.resolve("src", "config"),
|
|
830
|
+
desktopEntry: path14.resolve("src", "desktop")
|
|
831
|
+
});
|
|
832
|
+
const entryNames = Object.keys(entries);
|
|
833
|
+
if (entryNames.length === 0) {
|
|
834
|
+
throw new Error("No entry points found for plugin. Check src/config and src/desktop paths.");
|
|
835
|
+
}
|
|
836
|
+
console.log(chalk6.gray(` Entry points: ${entryNames.join(", ")}`));
|
|
837
|
+
await fs11.emptyDir(outputDir);
|
|
838
|
+
const { key, cert } = loadCertificates(certDirPath);
|
|
839
|
+
console.log(chalk6.gray(" Building..."));
|
|
840
|
+
await buildEntriesWithVite({
|
|
841
|
+
entries,
|
|
842
|
+
outDir: outputDir,
|
|
843
|
+
mode: "development",
|
|
844
|
+
sourcemap: "inline",
|
|
845
|
+
minify: false
|
|
846
|
+
});
|
|
847
|
+
const serverConfig = createViteConfig({
|
|
848
|
+
root: outputDir,
|
|
849
|
+
server: {
|
|
850
|
+
port,
|
|
851
|
+
https: { key, cert }
|
|
852
|
+
}
|
|
853
|
+
});
|
|
854
|
+
const server = await createServer(serverConfig);
|
|
855
|
+
await server.listen();
|
|
856
|
+
console.log(chalk6.green(`
|
|
857
|
+
\u2728 Plugin development server ready!`));
|
|
858
|
+
console.log(chalk6.cyan(` Local: https://localhost:${port}`));
|
|
859
|
+
console.log(chalk6.gray(` Output: ${outputDir}`));
|
|
860
|
+
console.log(chalk6.gray(` Files: config.js, desktop.js`));
|
|
861
|
+
console.log(chalk6.gray("\n Watching for changes...\n"));
|
|
862
|
+
const chokidar2 = await import("chokidar");
|
|
863
|
+
const watchPaths = [
|
|
864
|
+
"src/config/**/*.{ts,tsx,js,jsx,css,scss}",
|
|
865
|
+
"src/desktop/**/*.{ts,tsx,js,jsx,css,scss}"
|
|
866
|
+
];
|
|
867
|
+
const watcher = chokidar2.watch(watchPaths, {
|
|
868
|
+
ignored: /node_modules/,
|
|
869
|
+
persistent: true
|
|
870
|
+
});
|
|
871
|
+
const rebuild = async () => {
|
|
872
|
+
console.log(chalk6.gray(" Rebuilding..."));
|
|
873
|
+
await buildEntriesWithVite({
|
|
874
|
+
entries,
|
|
875
|
+
outDir: outputDir,
|
|
876
|
+
mode: "development",
|
|
877
|
+
sourcemap: "inline",
|
|
878
|
+
minify: false
|
|
879
|
+
});
|
|
880
|
+
};
|
|
881
|
+
watcher.on("change", rebuild);
|
|
882
|
+
watcher.on("add", rebuild);
|
|
883
|
+
watcher.on("unlink", rebuild);
|
|
884
|
+
Promise.all([watchContentsAndUploadZip({ manifest, ppkPath }), watchCss(config2)]);
|
|
795
885
|
} catch (error) {
|
|
796
886
|
throw error;
|
|
797
887
|
} finally {
|
|
798
888
|
console.groupEnd();
|
|
799
889
|
}
|
|
800
890
|
}
|
|
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
891
|
|
|
809
892
|
// src/commands/plugin-genkey.ts
|
|
810
893
|
import { program as program4 } from "commander";
|
|
811
894
|
|
|
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
895
|
// src/commands/genkey-base.ts
|
|
834
|
-
async function
|
|
896
|
+
async function action4(options) {
|
|
835
897
|
const { output } = options;
|
|
836
898
|
console.group("\u{1F373} Generate SSL key for localhost");
|
|
837
899
|
try {
|
|
@@ -849,21 +911,21 @@ async function action6(options) {
|
|
|
849
911
|
|
|
850
912
|
// src/commands/plugin-genkey.ts
|
|
851
913
|
function command4() {
|
|
852
|
-
program4.command("genkey").description("Generate SSL key for localhost. (Require mkcert)").action(
|
|
914
|
+
program4.command("genkey").description("Generate SSL key for localhost. (Require mkcert)").action(action5);
|
|
853
915
|
}
|
|
854
|
-
async function
|
|
855
|
-
await
|
|
916
|
+
async function action5() {
|
|
917
|
+
await action4({ output: PLUGIN_WORKSPACE_DIRECTORY });
|
|
856
918
|
}
|
|
857
919
|
|
|
858
920
|
// src/commands/plugin-init.ts
|
|
859
921
|
import { program as program5 } from "commander";
|
|
860
|
-
import
|
|
861
|
-
import
|
|
922
|
+
import fs12 from "fs-extra";
|
|
923
|
+
import path15 from "path";
|
|
862
924
|
import packer2 from "@kintone/plugin-packer";
|
|
863
925
|
function command5() {
|
|
864
|
-
program5.command("init").description("generate private.ppk and kitting config").action(
|
|
926
|
+
program5.command("init").description("generate private.ppk and kitting config").action(action6);
|
|
865
927
|
}
|
|
866
|
-
async function
|
|
928
|
+
async function action6() {
|
|
867
929
|
console.group("\u{1F373} Executing plugin initialization setup");
|
|
868
930
|
try {
|
|
869
931
|
const manifest = await outputManifest("dev");
|
|
@@ -871,20 +933,20 @@ async function action8() {
|
|
|
871
933
|
await copyPluginContents();
|
|
872
934
|
console.log("\u{1F4C1} contents copied");
|
|
873
935
|
let privateKey;
|
|
874
|
-
const keyPath =
|
|
875
|
-
if (
|
|
876
|
-
privateKey = await
|
|
936
|
+
const keyPath = path15.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk");
|
|
937
|
+
if (fs12.existsSync(keyPath)) {
|
|
938
|
+
privateKey = await fs12.readFile(keyPath, "utf8");
|
|
877
939
|
}
|
|
878
940
|
await outputContentsZip(manifest);
|
|
879
941
|
const buffer = await getContentsZipBuffer();
|
|
880
942
|
const output = await packer2(buffer, privateKey);
|
|
881
943
|
if (!privateKey) {
|
|
882
|
-
await
|
|
944
|
+
await fs12.writeFile(path15.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk"), output.privateKey);
|
|
883
945
|
console.log("\u{1F511} private.ppk generated");
|
|
884
946
|
} else {
|
|
885
947
|
console.log("\u{1F511} private.ppk already exists. The existing private.ppk will be used.");
|
|
886
948
|
}
|
|
887
|
-
await
|
|
949
|
+
await fs12.writeFile(path15.join(PLUGIN_WORKSPACE_DIRECTORY, "plugin.zip"), output.plugin);
|
|
888
950
|
console.log("\u{1F4E6} plugin.zip generated");
|
|
889
951
|
console.log("\u2728 Plugin initialization setup completed! zip file path is ./.plugin/plugin.zip");
|
|
890
952
|
} catch (error) {
|
|
@@ -897,9 +959,9 @@ async function action8() {
|
|
|
897
959
|
// src/commands/manifest/index.ts
|
|
898
960
|
import { program as program6 } from "commander";
|
|
899
961
|
function command6() {
|
|
900
|
-
program6.command("manifest").option("-e, --env <env>", "create manifest", "prod").action(
|
|
962
|
+
program6.command("manifest").option("-e, --env <env>", "create manifest", "prod").action(action7);
|
|
901
963
|
}
|
|
902
|
-
async function
|
|
964
|
+
async function action7(options) {
|
|
903
965
|
console.group("\u{1F680} Executing manifest generation");
|
|
904
966
|
try {
|
|
905
967
|
const { env } = options;
|
|
@@ -919,13 +981,13 @@ async function action9(options) {
|
|
|
919
981
|
|
|
920
982
|
// src/commands/test/index.ts
|
|
921
983
|
import { program as program7 } from "commander";
|
|
922
|
-
import
|
|
984
|
+
import fs13 from "fs-extra";
|
|
923
985
|
function command7() {
|
|
924
|
-
program7.command("test").description("test").action(
|
|
986
|
+
program7.command("test").description("test").action(action8);
|
|
925
987
|
}
|
|
926
|
-
async function
|
|
988
|
+
async function action8() {
|
|
927
989
|
console.group("package.json");
|
|
928
|
-
const packageJson =
|
|
990
|
+
const packageJson = fs13.readJSONSync("package.json");
|
|
929
991
|
console.log("package.json detected");
|
|
930
992
|
console.groupEnd();
|
|
931
993
|
console.group("Config");
|
|
@@ -936,17 +998,17 @@ async function action10() {
|
|
|
936
998
|
|
|
937
999
|
// src/commands/plugin-zip.ts
|
|
938
1000
|
import { program as program8 } from "commander";
|
|
939
|
-
import
|
|
940
|
-
import
|
|
1001
|
+
import fs14 from "fs-extra";
|
|
1002
|
+
import path16 from "path";
|
|
941
1003
|
import packer3 from "@kintone/plugin-packer";
|
|
942
1004
|
function command8() {
|
|
943
1005
|
program8.command("zip").description("generate plugin zip").option("-e, --env <env>", "plugin environment (dev, prod, standalone)", "prod").option(
|
|
944
1006
|
"-p, --ppk <ppk>",
|
|
945
1007
|
".ppk file path",
|
|
946
|
-
|
|
947
|
-
).action(
|
|
1008
|
+
path16.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk")
|
|
1009
|
+
).action(action9);
|
|
948
1010
|
}
|
|
949
|
-
async function
|
|
1011
|
+
async function action9(options) {
|
|
950
1012
|
console.group("\u{1F373} Executing plugin zip generation");
|
|
951
1013
|
try {
|
|
952
1014
|
const { env, ppk: ppkPath } = options;
|
|
@@ -960,13 +1022,13 @@ async function action11(options) {
|
|
|
960
1022
|
await outputContentsZip(manifest);
|
|
961
1023
|
console.log("\u{1F4E6} contents.zip generated");
|
|
962
1024
|
const buffer = await getContentsZipBuffer();
|
|
963
|
-
const privateKey = await
|
|
1025
|
+
const privateKey = await fs14.readFile(path16.resolve(ppkPath), "utf8");
|
|
964
1026
|
const output = await packer3(buffer, privateKey);
|
|
965
1027
|
const zipFileName = `plugin${getZipFileNameSuffix(env)}.zip`;
|
|
966
|
-
await
|
|
1028
|
+
await fs14.writeFile(path16.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName), output.plugin);
|
|
967
1029
|
console.log("\u{1F4E6} plugin.zip generated");
|
|
968
1030
|
const version = String(manifest.version);
|
|
969
|
-
await
|
|
1031
|
+
await fs14.writeFile(path16.join(PLUGIN_WORKSPACE_DIRECTORY, "version"), version);
|
|
970
1032
|
console.log(`\u{1F4DD} version file generated (${version})`);
|
|
971
1033
|
console.log(`\u2728 Plugin zip generation completed! zip file path is ./.plugin/${zipFileName}`);
|
|
972
1034
|
} catch (error) {
|
|
@@ -979,9 +1041,9 @@ async function action11(options) {
|
|
|
979
1041
|
// src/commands/lint.ts
|
|
980
1042
|
import { program as program9 } from "commander";
|
|
981
1043
|
function command9() {
|
|
982
|
-
program9.command("lint").description("Lint source files").option("-c, --config <config>", "Config file path").action(
|
|
1044
|
+
program9.command("lint").description("Lint source files").option("-c, --config <config>", "Config file path").action(action10);
|
|
983
1045
|
}
|
|
984
|
-
async function
|
|
1046
|
+
async function action10(options) {
|
|
985
1047
|
try {
|
|
986
1048
|
lint();
|
|
987
1049
|
} catch (error) {
|
|
@@ -992,12 +1054,12 @@ async function action12(options) {
|
|
|
992
1054
|
|
|
993
1055
|
// src/commands/plugin-tsup.ts
|
|
994
1056
|
import { program as program10 } from "commander";
|
|
995
|
-
import
|
|
996
|
-
import
|
|
1057
|
+
import fs15 from "fs-extra";
|
|
1058
|
+
import path17 from "path";
|
|
997
1059
|
|
|
998
1060
|
// src/lib/tsup.ts
|
|
999
|
-
import { build
|
|
1000
|
-
var
|
|
1061
|
+
import { build } from "tsup";
|
|
1062
|
+
var completeBuildOptions = (params) => {
|
|
1001
1063
|
return {
|
|
1002
1064
|
bundle: true,
|
|
1003
1065
|
minify: "terser",
|
|
@@ -1012,15 +1074,15 @@ var completeBuildOptions2 = (params) => {
|
|
|
1012
1074
|
};
|
|
1013
1075
|
};
|
|
1014
1076
|
var buildWithTsup = async (buildOptions) => {
|
|
1015
|
-
const options =
|
|
1016
|
-
await
|
|
1077
|
+
const options = completeBuildOptions(buildOptions);
|
|
1078
|
+
await build(options);
|
|
1017
1079
|
};
|
|
1018
1080
|
|
|
1019
1081
|
// src/commands/plugin-tsup.ts
|
|
1020
1082
|
function command10() {
|
|
1021
|
-
program10.command("tsup").description("Build the project for production. (It's a wrapper of webpack build command.)").action(
|
|
1083
|
+
program10.command("tsup").description("Build the project for production. (It's a wrapper of webpack build command.)").action(action11);
|
|
1022
1084
|
}
|
|
1023
|
-
async function
|
|
1085
|
+
async function action11() {
|
|
1024
1086
|
console.group("\u{1F373} Build the project for production");
|
|
1025
1087
|
try {
|
|
1026
1088
|
const config2 = await importK2PluginConfig();
|
|
@@ -1028,22 +1090,22 @@ async function action13() {
|
|
|
1028
1090
|
await lint();
|
|
1029
1091
|
console.log("\u2728 Lint success.");
|
|
1030
1092
|
}
|
|
1031
|
-
if (!
|
|
1032
|
-
await
|
|
1093
|
+
if (!fs15.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
|
|
1094
|
+
await fs15.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
|
|
1033
1095
|
}
|
|
1034
1096
|
if (config2.tailwind?.css && config2.tailwind?.config) {
|
|
1035
1097
|
const tailwindConfig = await getTailwindConfig(config2.tailwind);
|
|
1036
1098
|
const inputFile = getTailwindInputCss(config2.tailwind);
|
|
1037
1099
|
await outputCss({
|
|
1038
1100
|
inputPath: inputFile.config,
|
|
1039
|
-
outputPath:
|
|
1101
|
+
outputPath: path17.join(PLUGIN_CONTENTS_DIRECTORY, "config.css"),
|
|
1040
1102
|
config: tailwindConfig.config,
|
|
1041
1103
|
minify: true
|
|
1042
1104
|
});
|
|
1043
1105
|
console.log("\u2728 Built config.css");
|
|
1044
1106
|
await outputCss({
|
|
1045
1107
|
inputPath: inputFile.desktop,
|
|
1046
|
-
outputPath:
|
|
1108
|
+
outputPath: path17.join(PLUGIN_CONTENTS_DIRECTORY, "desktop.css"),
|
|
1047
1109
|
config: tailwindConfig.desktop,
|
|
1048
1110
|
minify: true
|
|
1049
1111
|
});
|
|
@@ -1052,7 +1114,7 @@ async function action13() {
|
|
|
1052
1114
|
const entryPoints = ["desktop", "config"].reduce(
|
|
1053
1115
|
(acc, dir) => ({
|
|
1054
1116
|
...acc,
|
|
1055
|
-
[dir]:
|
|
1117
|
+
[dir]: path17.join("src", dir, "index.ts")
|
|
1056
1118
|
}),
|
|
1057
1119
|
{}
|
|
1058
1120
|
);
|