@konomi-app/k2 0.7.1 → 0.8.1
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/commands/dev-base.js +1 -1
- package/dist/commands/plugin-build.js +26 -1
- package/dist/commands/plugin-dev/tailwind.js +6 -21
- package/dist/commands/plugin-dev/upload.js +2 -1
- package/dist/commands/plugin-esbuild.js +61 -0
- package/dist/index.js +1 -1
- package/dist/lib/esbuild-sass-plugin.js +36 -0
- package/dist/lib/esbuild.js +22 -41
- package/dist/lib/tailwind.js +28 -0
- package/dist/plugin.js +3 -1
- package/package.json +3 -1
- package/types/k2.d.ts +11 -0
|
@@ -10,7 +10,7 @@ export default function action(params) {
|
|
|
10
10
|
}
|
|
11
11
|
async function build(params) {
|
|
12
12
|
const { entryPoints, staticDir: outdir } = params;
|
|
13
|
-
return buildWithEsbuild({ entryPoints, outdir });
|
|
13
|
+
return buildWithEsbuild({ entryPoints, outdir, watch: true });
|
|
14
14
|
}
|
|
15
15
|
async function server(params) {
|
|
16
16
|
const { certDir, port, staticDir } = params;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { program } from 'commander';
|
|
2
|
-
import
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
3
|
import path from 'path';
|
|
4
|
+
import { PLUGIN_CONTENTS_DIRECTORY } from '../lib/constants.js';
|
|
5
|
+
import { importPluginConfig } from '../lib/import.js';
|
|
6
|
+
import { getTailwindConfig, outputCss } from '../lib/tailwind.js';
|
|
4
7
|
import base from './build-base.js';
|
|
5
8
|
export default function command() {
|
|
6
9
|
program
|
|
@@ -11,11 +14,33 @@ export default function command() {
|
|
|
11
14
|
export async function action() {
|
|
12
15
|
console.group('🍳 Build the project for production');
|
|
13
16
|
try {
|
|
17
|
+
const config = await importPluginConfig();
|
|
18
|
+
if (!fs.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
|
|
19
|
+
await fs.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
|
|
20
|
+
}
|
|
14
21
|
const entries = {
|
|
15
22
|
desktop: path.join('src', 'desktop', 'index.ts'),
|
|
16
23
|
config: path.join('src', 'config', 'index.ts'),
|
|
17
24
|
};
|
|
25
|
+
if (config.tailwind?.css && config.tailwind?.config) {
|
|
26
|
+
const tailwindConfig = await getTailwindConfig(config.tailwind);
|
|
27
|
+
const inputFile = path.resolve(config.tailwind.css);
|
|
28
|
+
const inputPath = path.resolve(inputFile);
|
|
29
|
+
await outputCss({
|
|
30
|
+
inputPath,
|
|
31
|
+
outputPath: path.join(PLUGIN_CONTENTS_DIRECTORY, 'config.css'),
|
|
32
|
+
config: tailwindConfig.config,
|
|
33
|
+
});
|
|
34
|
+
console.log('✨ Built config.css');
|
|
35
|
+
await outputCss({
|
|
36
|
+
inputPath,
|
|
37
|
+
outputPath: path.join(PLUGIN_CONTENTS_DIRECTORY, 'desktop.css'),
|
|
38
|
+
config: tailwindConfig.config,
|
|
39
|
+
});
|
|
40
|
+
console.log('✨ Built desktop.css');
|
|
41
|
+
}
|
|
18
42
|
await base({ entries, outDir: PLUGIN_CONTENTS_DIRECTORY });
|
|
43
|
+
console.log('✨ Built desktop.js and config.js');
|
|
19
44
|
console.log('✨ Build success.');
|
|
20
45
|
}
|
|
21
46
|
catch (error) {
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
1
|
import path from 'path';
|
|
3
|
-
import postcss from 'postcss';
|
|
4
|
-
import tailwindcss from 'tailwindcss';
|
|
5
2
|
import { PLUGIN_DEVELOPMENT_DIRECTORY } from '../../lib/constants.js';
|
|
6
|
-
import { esmImport } from '../../lib/import.js';
|
|
7
3
|
import chokidar from 'chokidar';
|
|
8
4
|
import chalk from 'chalk';
|
|
5
|
+
import { getTailwindConfig, outputCss } from '../../lib/tailwind.js';
|
|
9
6
|
async function buildTailwindCSS(params) {
|
|
10
7
|
const { inputFile, outputFileName, config } = params;
|
|
11
8
|
const inputPath = path.resolve(inputFile);
|
|
12
9
|
const outputPath = path.join(PLUGIN_DEVELOPMENT_DIRECTORY, outputFileName);
|
|
13
|
-
const css = await fs.readFile(inputPath, 'utf8');
|
|
14
10
|
const watcher = chokidar.watch([...(config.content ?? ['./src/**/*.{ts,tsx}']), inputPath], {
|
|
15
11
|
ignored: /node_modules/,
|
|
16
12
|
persistent: true,
|
|
@@ -25,14 +21,7 @@ async function buildTailwindCSS(params) {
|
|
|
25
21
|
if (type === 'add' && !initialScanComplete) {
|
|
26
22
|
return;
|
|
27
23
|
}
|
|
28
|
-
|
|
29
|
-
from: inputPath,
|
|
30
|
-
to: outputPath,
|
|
31
|
-
});
|
|
32
|
-
await fs.writeFile(outputPath, result.css);
|
|
33
|
-
if (result.map) {
|
|
34
|
-
await fs.writeFile(`${outputPath}.map`, result.map.toString());
|
|
35
|
-
}
|
|
24
|
+
await outputCss({ inputPath, outputPath, config });
|
|
36
25
|
console.log(chalk.hex('#e5e7eb')(`${new Date().toLocaleTimeString()} `) +
|
|
37
26
|
chalk.cyan(`[css] `) +
|
|
38
27
|
outputFileName +
|
|
@@ -54,14 +43,10 @@ export const watchCss = async (pluginConfig) => {
|
|
|
54
43
|
if (!pluginConfig.tailwind?.css || !pluginConfig.tailwind?.config) {
|
|
55
44
|
return;
|
|
56
45
|
}
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const configPathForConfig = typeof configPath === 'string' ? configPath : configPath.config;
|
|
60
|
-
const desktopConfig = (await esmImport(path.resolve(configPathForDesktop))).default;
|
|
61
|
-
const configConfig = (await esmImport(path.resolve(configPathForConfig))).default;
|
|
62
|
-
const inputFile = path.resolve(css);
|
|
46
|
+
const tailwindConfig = await getTailwindConfig(pluginConfig.tailwind);
|
|
47
|
+
const inputFile = path.resolve(pluginConfig.tailwind.css);
|
|
63
48
|
return Promise.all([
|
|
64
|
-
buildTailwindCSS({ inputFile, outputFileName: 'desktop.css', config:
|
|
65
|
-
buildTailwindCSS({ inputFile, outputFileName: 'config.css', config:
|
|
49
|
+
buildTailwindCSS({ inputFile, outputFileName: 'desktop.css', config: tailwindConfig.desktop }),
|
|
50
|
+
buildTailwindCSS({ inputFile, outputFileName: 'config.css', config: tailwindConfig.config }),
|
|
66
51
|
]);
|
|
67
52
|
};
|
|
@@ -42,7 +42,8 @@ export const watchContentsAndUploadZip = async (params) => {
|
|
|
42
42
|
catch (error) {
|
|
43
43
|
console.log(chalk.hex('#e5e7eb')(`${new Date().toLocaleTimeString()} `) +
|
|
44
44
|
chalk.cyan(`[upload] `) +
|
|
45
|
-
chalk.red(`failed`)
|
|
45
|
+
chalk.red(`failed`) +
|
|
46
|
+
chalk.hex('#e5e7eb')(`: ${error?.message ?? 'Unknown error'}`));
|
|
46
47
|
}
|
|
47
48
|
};
|
|
48
49
|
const contentsWatcher = chokider.watch(['src/contents/**/*'], {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { program } from 'commander';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { PLUGIN_CONTENTS_DIRECTORY } from '../lib/constants.js';
|
|
5
|
+
import { importPluginConfig } from '../lib/import.js';
|
|
6
|
+
import { getTailwindConfig, outputCss } from '../lib/tailwind.js';
|
|
7
|
+
import { buildWithEsbuild } from '../lib/esbuild.js';
|
|
8
|
+
export default function command() {
|
|
9
|
+
program
|
|
10
|
+
.command('esbuild')
|
|
11
|
+
.description("Build the project for production. (It's a wrapper of webpack build command.)")
|
|
12
|
+
.action(action);
|
|
13
|
+
}
|
|
14
|
+
export async function action() {
|
|
15
|
+
console.group('🍳 Build the project for production');
|
|
16
|
+
try {
|
|
17
|
+
const config = await importPluginConfig();
|
|
18
|
+
if (!fs.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
|
|
19
|
+
await fs.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
|
|
20
|
+
}
|
|
21
|
+
const entries = {
|
|
22
|
+
desktop: path.join('src', 'desktop', 'index.ts'),
|
|
23
|
+
config: path.join('src', 'config', 'index.ts'),
|
|
24
|
+
};
|
|
25
|
+
if (config.tailwind?.css && config.tailwind?.config) {
|
|
26
|
+
const tailwindConfig = await getTailwindConfig(config.tailwind);
|
|
27
|
+
const inputFile = path.resolve(config.tailwind.css);
|
|
28
|
+
const inputPath = path.resolve(inputFile);
|
|
29
|
+
await outputCss({
|
|
30
|
+
inputPath,
|
|
31
|
+
outputPath: path.join(PLUGIN_CONTENTS_DIRECTORY, 'config.css'),
|
|
32
|
+
config: tailwindConfig.config,
|
|
33
|
+
});
|
|
34
|
+
console.log('✨ Built config.css');
|
|
35
|
+
await outputCss({
|
|
36
|
+
inputPath,
|
|
37
|
+
outputPath: path.join(PLUGIN_CONTENTS_DIRECTORY, 'desktop.css'),
|
|
38
|
+
config: tailwindConfig.config,
|
|
39
|
+
});
|
|
40
|
+
console.log('✨ Built desktop.css');
|
|
41
|
+
}
|
|
42
|
+
const entryPoints = ['desktop', 'config'].map((dir) => ({
|
|
43
|
+
in: path.join('src', dir, 'index.ts'),
|
|
44
|
+
out: dir,
|
|
45
|
+
}));
|
|
46
|
+
await buildWithEsbuild({
|
|
47
|
+
entryPoints,
|
|
48
|
+
outdir: PLUGIN_CONTENTS_DIRECTORY,
|
|
49
|
+
minify: true,
|
|
50
|
+
sourcemap: false,
|
|
51
|
+
});
|
|
52
|
+
console.log('✨ Built desktop.js and config.js');
|
|
53
|
+
console.log('✨ Build success.');
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
console.groupEnd();
|
|
60
|
+
}
|
|
61
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import dev from './commands/dev.js';
|
|
|
6
6
|
import viteDev from './commands/dev-vite.js';
|
|
7
7
|
import genkey from './commands/genkey.js';
|
|
8
8
|
import esbuildBuild from './commands/build-esbuild.js';
|
|
9
|
-
program.name('k2').version('0.
|
|
9
|
+
program.name('k2').version('0.8.0').description('k2 - 🍳 kintone kitchen 🍳');
|
|
10
10
|
build();
|
|
11
11
|
viteBuild();
|
|
12
12
|
esbuildBuild();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { compile } from 'sass';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
export const getSassPlugin = () => {
|
|
4
|
+
const pluginName = 'esbuild-plugin-sass';
|
|
5
|
+
return {
|
|
6
|
+
name: pluginName,
|
|
7
|
+
setup(build) {
|
|
8
|
+
build.onResolve({ filter: /\.s[ac]ss$/ }, (args) => ({
|
|
9
|
+
path: resolve(args.resolveDir, args.path),
|
|
10
|
+
namespace: pluginName,
|
|
11
|
+
}));
|
|
12
|
+
build.onLoad({ filter: /.*/, namespace: pluginName }, async (args) => {
|
|
13
|
+
try {
|
|
14
|
+
const result = compile(args.path);
|
|
15
|
+
return {
|
|
16
|
+
contents: result.css,
|
|
17
|
+
loader: 'css',
|
|
18
|
+
watchFiles: [args.path],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return {
|
|
23
|
+
pluginName,
|
|
24
|
+
errors: [
|
|
25
|
+
{
|
|
26
|
+
text: error instanceof Error ? error.message : JSON.stringify(error),
|
|
27
|
+
pluginName,
|
|
28
|
+
location: { file: args.path, namespace: pluginName },
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
};
|
package/dist/lib/esbuild.js
CHANGED
|
@@ -1,58 +1,39 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import esbuild from 'esbuild';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export const getSassPlugin = () => {
|
|
6
|
-
const pluginName = 'esbuild-plugin-sass';
|
|
3
|
+
import { getSassPlugin } from './esbuild-sass-plugin.js';
|
|
4
|
+
const completeBuildOptions = (params) => {
|
|
7
5
|
return {
|
|
8
|
-
name: pluginName,
|
|
9
|
-
setup(build) {
|
|
10
|
-
build.onResolve({ filter: /\.s[ac]ss$/ }, (args) => ({
|
|
11
|
-
path: resolve(args.resolveDir, args.path),
|
|
12
|
-
namespace: pluginName,
|
|
13
|
-
}));
|
|
14
|
-
build.onLoad({ filter: /.*/, namespace: pluginName }, async (args) => {
|
|
15
|
-
try {
|
|
16
|
-
const result = compile(args.path);
|
|
17
|
-
return {
|
|
18
|
-
contents: result.css,
|
|
19
|
-
loader: 'css',
|
|
20
|
-
watchFiles: [args.path],
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
return {
|
|
25
|
-
pluginName,
|
|
26
|
-
errors: [
|
|
27
|
-
{
|
|
28
|
-
text: error instanceof Error ? error.message : JSON.stringify(error),
|
|
29
|
-
pluginName,
|
|
30
|
-
location: { file: args.path, namespace: pluginName },
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
export const getEsbuildContext = async (params) => {
|
|
40
|
-
return esbuild.context({
|
|
41
6
|
bundle: true,
|
|
42
7
|
platform: 'browser',
|
|
8
|
+
...params,
|
|
9
|
+
plugins: [...(params.plugins ?? []), getSassPlugin()],
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
const completeDevBuildOptions = (params) => {
|
|
13
|
+
return completeBuildOptions({
|
|
14
|
+
...params,
|
|
43
15
|
plugins: [
|
|
16
|
+
...(params.plugins ?? []),
|
|
44
17
|
{
|
|
45
18
|
name: 'on-end',
|
|
46
19
|
setup: ({ onEnd }) => onEnd(() => console.log(chalk.hex('#e5e7eb')(`${new Date().toLocaleTimeString()} `) +
|
|
47
20
|
chalk.cyan(`[js] `) +
|
|
48
21
|
`rebuilt`)),
|
|
49
22
|
},
|
|
50
|
-
getSassPlugin(),
|
|
51
23
|
],
|
|
52
|
-
...params,
|
|
53
24
|
});
|
|
54
25
|
};
|
|
26
|
+
export const getEsbuildContext = async (params) => {
|
|
27
|
+
return esbuild.context(completeDevBuildOptions(params));
|
|
28
|
+
};
|
|
55
29
|
export const buildWithEsbuild = async (params) => {
|
|
56
|
-
const
|
|
57
|
-
|
|
30
|
+
const { watch = false, ...rest } = params;
|
|
31
|
+
if (watch) {
|
|
32
|
+
const context = await getEsbuildContext(rest);
|
|
33
|
+
context.watch();
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const options = completeBuildOptions(rest);
|
|
37
|
+
await esbuild.build(options);
|
|
38
|
+
}
|
|
58
39
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import cssnanoPlugin from 'cssnano';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import postcss from 'postcss';
|
|
5
|
+
import tailwindcss from 'tailwindcss';
|
|
6
|
+
import invariant from 'tiny-invariant';
|
|
7
|
+
import { esmImport } from './import.js';
|
|
8
|
+
export const getTailwindConfig = async (config) => {
|
|
9
|
+
invariant(config?.config, 'tailwind.config is required');
|
|
10
|
+
const { config: configPath } = config;
|
|
11
|
+
const configPathForDesktop = typeof configPath === 'string' ? configPath : configPath.desktop;
|
|
12
|
+
const configPathForConfig = typeof configPath === 'string' ? configPath : configPath.config;
|
|
13
|
+
const desktopConfig = (await esmImport(path.resolve(configPathForDesktop))).default;
|
|
14
|
+
const configConfig = (await esmImport(path.resolve(configPathForConfig))).default;
|
|
15
|
+
return { desktop: desktopConfig, config: configConfig };
|
|
16
|
+
};
|
|
17
|
+
export const outputCss = async (params) => {
|
|
18
|
+
const { inputPath, outputPath, config, minify = false } = params;
|
|
19
|
+
const css = await fs.readFile(inputPath, 'utf8');
|
|
20
|
+
const result = await postcss([tailwindcss(config), ...(minify ? [cssnanoPlugin()] : [])]).process(css, {
|
|
21
|
+
from: inputPath,
|
|
22
|
+
to: outputPath,
|
|
23
|
+
});
|
|
24
|
+
await fs.writeFile(outputPath, result.css);
|
|
25
|
+
if (result.map) {
|
|
26
|
+
await fs.writeFile(`${outputPath}.map`, result.map.toString());
|
|
27
|
+
}
|
|
28
|
+
};
|
package/dist/plugin.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { program } from 'commander';
|
|
3
3
|
import build from './commands/plugin-build.js';
|
|
4
|
+
import esbuild from './commands/plugin-esbuild.js';
|
|
4
5
|
import dev from './commands/plugin-dev/index.js';
|
|
5
6
|
import genkey from './commands/plugin-genkey.js';
|
|
6
7
|
import init from './commands/plugin-init.js';
|
|
@@ -8,8 +9,9 @@ import manifest from './commands/manifest/index.js';
|
|
|
8
9
|
import test from './commands/test/index.js';
|
|
9
10
|
import upload from './commands/upload/index.js';
|
|
10
11
|
import zip from './commands/plugin-zip.js';
|
|
11
|
-
program.name('plugin').version('0.
|
|
12
|
+
program.name('plugin').version('0.8.0').description('🍳 kintone kitchen 🍳 for kintone plugin');
|
|
12
13
|
build();
|
|
14
|
+
esbuild();
|
|
13
15
|
dev();
|
|
14
16
|
genkey();
|
|
15
17
|
init();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@konomi-app/k2",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "kintone sdk",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"chokidar": "^3",
|
|
32
32
|
"commander": "^12",
|
|
33
33
|
"css-loader": "^7.1.2",
|
|
34
|
+
"cssnano": "^7.0.2",
|
|
34
35
|
"dotenv": "^16",
|
|
35
36
|
"esbuild": "^0.21",
|
|
36
37
|
"express": "^4",
|
|
@@ -43,6 +44,7 @@
|
|
|
43
44
|
"style-loader": "^4",
|
|
44
45
|
"tailwindcss": "^3.4.4",
|
|
45
46
|
"terser-webpack-plugin": "^5",
|
|
47
|
+
"tiny-invariant": "^1.3.3",
|
|
46
48
|
"ts-loader": "^9",
|
|
47
49
|
"tsconfig-paths-webpack-plugin": "^4",
|
|
48
50
|
"vite": "^5",
|
package/types/k2.d.ts
CHANGED
|
@@ -32,5 +32,16 @@ declare namespace K2 {
|
|
|
32
32
|
/** 0から65535までのポート番号 */
|
|
33
33
|
port?: number;
|
|
34
34
|
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* tailwindcssを使用している場合、設定ファイルのパスとCSSファイルのパスを指定することで、JavaScriptファイルのビルド時にCSSファイルを生成します
|
|
38
|
+
*
|
|
39
|
+
* @see {@link https://tailwindcss.com/docs/installation | Tailwind CSS}
|
|
40
|
+
*/
|
|
41
|
+
tailwind?: {
|
|
42
|
+
config?: string;
|
|
43
|
+
/** CSSファイルのパス */
|
|
44
|
+
css?: string;
|
|
45
|
+
};
|
|
35
46
|
};
|
|
36
47
|
}
|