@konomi-app/k2 0.8.0 → 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 +0 -3
- package/dist/commands/plugin-dev/tailwind.js +1 -3
- package/dist/commands/plugin-dev/upload.js +2 -1
- package/dist/commands/plugin-esbuild.js +61 -0
- package/dist/lib/esbuild-sass-plugin.js +36 -0
- package/dist/lib/esbuild.js +22 -41
- package/dist/lib/tailwind.js +2 -1
- package/dist/plugin.js +2 -0
- package/package.json +1 -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;
|
|
@@ -26,16 +26,13 @@ export async function action() {
|
|
|
26
26
|
const tailwindConfig = await getTailwindConfig(config.tailwind);
|
|
27
27
|
const inputFile = path.resolve(config.tailwind.css);
|
|
28
28
|
const inputPath = path.resolve(inputFile);
|
|
29
|
-
const css = await fs.readFile(inputPath, 'utf8');
|
|
30
29
|
await outputCss({
|
|
31
|
-
css,
|
|
32
30
|
inputPath,
|
|
33
31
|
outputPath: path.join(PLUGIN_CONTENTS_DIRECTORY, 'config.css'),
|
|
34
32
|
config: tailwindConfig.config,
|
|
35
33
|
});
|
|
36
34
|
console.log('✨ Built config.css');
|
|
37
35
|
await outputCss({
|
|
38
|
-
css,
|
|
39
36
|
inputPath,
|
|
40
37
|
outputPath: path.join(PLUGIN_CONTENTS_DIRECTORY, 'desktop.css'),
|
|
41
38
|
config: tailwindConfig.config,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
1
|
import path from 'path';
|
|
3
2
|
import { PLUGIN_DEVELOPMENT_DIRECTORY } from '../../lib/constants.js';
|
|
4
3
|
import chokidar from 'chokidar';
|
|
@@ -8,7 +7,6 @@ async function buildTailwindCSS(params) {
|
|
|
8
7
|
const { inputFile, outputFileName, config } = params;
|
|
9
8
|
const inputPath = path.resolve(inputFile);
|
|
10
9
|
const outputPath = path.join(PLUGIN_DEVELOPMENT_DIRECTORY, outputFileName);
|
|
11
|
-
const css = await fs.readFile(inputPath, 'utf8');
|
|
12
10
|
const watcher = chokidar.watch([...(config.content ?? ['./src/**/*.{ts,tsx}']), inputPath], {
|
|
13
11
|
ignored: /node_modules/,
|
|
14
12
|
persistent: true,
|
|
@@ -23,7 +21,7 @@ async function buildTailwindCSS(params) {
|
|
|
23
21
|
if (type === 'add' && !initialScanComplete) {
|
|
24
22
|
return;
|
|
25
23
|
}
|
|
26
|
-
await outputCss({
|
|
24
|
+
await outputCss({ inputPath, outputPath, config });
|
|
27
25
|
console.log(chalk.hex('#e5e7eb')(`${new Date().toLocaleTimeString()} `) +
|
|
28
26
|
chalk.cyan(`[css] `) +
|
|
29
27
|
outputFileName +
|
|
@@ -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
|
+
}
|
|
@@ -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
|
};
|
package/dist/lib/tailwind.js
CHANGED
|
@@ -15,7 +15,8 @@ export const getTailwindConfig = async (config) => {
|
|
|
15
15
|
return { desktop: desktopConfig, config: configConfig };
|
|
16
16
|
};
|
|
17
17
|
export const outputCss = async (params) => {
|
|
18
|
-
const { inputPath, outputPath, config,
|
|
18
|
+
const { inputPath, outputPath, config, minify = false } = params;
|
|
19
|
+
const css = await fs.readFile(inputPath, 'utf8');
|
|
19
20
|
const result = await postcss([tailwindcss(config), ...(minify ? [cssnanoPlugin()] : [])]).process(css, {
|
|
20
21
|
from: inputPath,
|
|
21
22
|
to: outputPath,
|
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';
|
|
@@ -10,6 +11,7 @@ import upload from './commands/upload/index.js';
|
|
|
10
11
|
import zip from './commands/plugin-zip.js';
|
|
11
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
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
|
}
|