@konomi-app/k2 1.7.6 → 1.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.
@@ -1,3 +1,4 @@
1
+ import {} from 'webpack';
1
2
  import { buildWithWebpack } from '../lib/webpack.js';
2
3
  export default async function action(params) {
3
4
  const { entries, outDir } = params;
@@ -2,6 +2,7 @@ import { program } from 'commander';
2
2
  import fs from 'fs-extra';
3
3
  import path from 'path';
4
4
  import { WORKSPACE_DIRECTORY } from '../lib/constants.js';
5
+ import {} from 'esbuild';
5
6
  import { buildWithEsbuild } from '../lib/esbuild.js';
6
7
  import { importK2Config } from '../lib/import.js';
7
8
  import { getDefaultK2Config } from '../lib/k2.js';
@@ -1,4 +1,5 @@
1
1
  import { program } from 'commander';
2
+ import {} from 'esbuild';
2
3
  import fs from 'fs-extra';
3
4
  import path from 'path';
4
5
  import { CONFIG_FILE_NAME, DEFAULT_PORT, DEVELOPMENT_DIRECTORY, WORKSPACE_DIRECTORY, } from '../../lib/constants.js';
@@ -1,3 +1,4 @@
1
+ import {} from 'esbuild';
1
2
  import path from 'path';
2
3
  import { getEsbuildContext } from '../lib/esbuild.js';
3
4
  export default async function action(params) {
@@ -1,6 +1,7 @@
1
1
  import { program } from 'commander';
2
2
  import fs from 'fs-extra';
3
3
  import path from 'path';
4
+ import {} from 'webpack';
4
5
  import { PLUGIN_CONTENTS_DIRECTORY } from '../lib/constants.js';
5
6
  import { importK2PluginConfig } from '../lib/import.js';
6
7
  import { getTailwindConfig, getTailwindInputCss, outputCss } from '../lib/tailwind.js';
@@ -1,4 +1,5 @@
1
1
  import { program } from 'commander';
2
+ import {} from 'esbuild';
2
3
  import fs from 'fs-extra';
3
4
  import path from 'path';
4
5
  import { DEFAULT_PORT, PLUGIN_DEVELOPMENT_DIRECTORY, PLUGIN_WORKSPACE_DIRECTORY, } from '../../lib/constants.js';
@@ -1,4 +1,5 @@
1
1
  import path from 'path';
2
+ import {} from 'tailwindcss';
2
3
  import { PLUGIN_DEVELOPMENT_DIRECTORY } from '../../lib/constants.js';
3
4
  import chalk from 'chalk';
4
5
  import { getTailwindConfig, getTailwindInputCss, watchTailwindCSS } from '../../lib/tailwind.js';
@@ -4,6 +4,7 @@ import path from 'path';
4
4
  import { PLUGIN_CONTENTS_DIRECTORY } from '../lib/constants.js';
5
5
  import { importK2PluginConfig } from '../lib/import.js';
6
6
  import { getTailwindConfig, getTailwindInputCss, outputCss } from '../lib/tailwind.js';
7
+ import {} from 'esbuild';
7
8
  import { buildWithEsbuild } from '../lib/esbuild.js';
8
9
  import { lint } from '../lib/lint.js';
9
10
  export default function command() {
@@ -0,0 +1,64 @@
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 { importK2PluginConfig } from '../lib/import.js';
6
+ import { lint } from '../lib/lint.js';
7
+ import { getTailwindConfig, getTailwindInputCss, outputCss } from '../lib/tailwind.js';
8
+ import { buildWithTsup } from '../lib/tsup.js';
9
+ export default function command() {
10
+ program
11
+ .command('tsup')
12
+ .description("Build the project for production. (It's a wrapper of webpack build command.)")
13
+ .action(action);
14
+ }
15
+ export async function action() {
16
+ console.group('🍳 Build the project for production');
17
+ try {
18
+ const config = await importK2PluginConfig();
19
+ if (config?.lint?.build) {
20
+ await lint();
21
+ console.log('✨ Lint success.');
22
+ }
23
+ if (!fs.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
24
+ await fs.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
25
+ }
26
+ if (config.tailwind?.css && config.tailwind?.config) {
27
+ const tailwindConfig = await getTailwindConfig(config.tailwind);
28
+ const inputFile = getTailwindInputCss(config.tailwind);
29
+ await outputCss({
30
+ inputPath: inputFile.config,
31
+ outputPath: path.join(PLUGIN_CONTENTS_DIRECTORY, 'config.css'),
32
+ config: tailwindConfig.config,
33
+ minify: true,
34
+ });
35
+ console.log('✨ Built config.css');
36
+ await outputCss({
37
+ inputPath: inputFile.desktop,
38
+ outputPath: path.join(PLUGIN_CONTENTS_DIRECTORY, 'desktop.css'),
39
+ config: tailwindConfig.desktop,
40
+ minify: true,
41
+ });
42
+ console.log('✨ Built desktop.css');
43
+ }
44
+ const entryPoints = ['desktop', 'config'].reduce((acc, dir) => ({
45
+ ...acc,
46
+ [dir]: path.join('src', dir, 'index.ts'),
47
+ }), {});
48
+ await buildWithTsup({
49
+ entryPoints,
50
+ outDir: PLUGIN_CONTENTS_DIRECTORY,
51
+ minify: true,
52
+ treeshake: true,
53
+ sourcemap: false,
54
+ });
55
+ console.log('✨ Built desktop.js and config.js');
56
+ console.log('✨ Build success.');
57
+ }
58
+ catch (error) {
59
+ throw error;
60
+ }
61
+ finally {
62
+ console.groupEnd();
63
+ }
64
+ }
package/dist/index.js CHANGED
@@ -1,18 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  import { program } from 'commander';
3
3
  import build from './commands/build.js';
4
- import viteBuild from './commands/build-vite.js';
5
4
  import dev from './commands/dev/index.js';
6
- import viteDev from './commands/dev-vite.js';
7
5
  import genkey from './commands/genkey.js';
8
6
  import esbuildBuild from './commands/build-esbuild.js';
9
7
  import lint from './commands/lint.js';
10
8
  program.name('k2').version('1.4.0').description('k2 - 🍳 kintone kitchen 🍳');
11
9
  build();
12
- viteBuild();
13
10
  esbuildBuild();
14
11
  dev();
15
- viteDev();
16
12
  genkey();
17
13
  lint();
18
14
  program.parse(process.argv);
@@ -1,3 +1,4 @@
1
+ import {} from 'esbuild';
1
2
  import { compile } from 'sass';
2
3
  import { resolve } from 'path';
3
4
  export const getSassPlugin = () => {
@@ -1,5 +1,5 @@
1
1
  import chalk from 'chalk';
2
- import esbuild from 'esbuild';
2
+ import esbuild, {} from 'esbuild';
3
3
  import { getSassPlugin } from './esbuild-sass-plugin.js';
4
4
  const completeBuildOptions = (params) => {
5
5
  return {
@@ -1,13 +1,13 @@
1
1
  import chokidar from 'chokidar';
2
2
  import cssnanoPlugin from 'cssnano';
3
3
  import fs from 'fs-extra';
4
+ import { glob } from 'glob';
4
5
  import path from 'path';
5
6
  import postcss from 'postcss';
6
7
  import { debounce } from 'remeda';
7
- import tailwindcss from 'tailwindcss';
8
+ import tailwindcss, {} from 'tailwindcss';
8
9
  import invariant from 'tiny-invariant';
9
10
  import { esmImport } from './import.js';
10
- import { glob } from 'glob';
11
11
  export const getTailwindConfigFromK2Config = async (k2Config) => {
12
12
  invariant(k2Config?.config, 'tailwind.config is required');
13
13
  const config = (await esmImport(path.resolve(k2Config?.config))).default;
@@ -0,0 +1,27 @@
1
+ import { getSassPlugin } from './esbuild-sass-plugin.js';
2
+ import { build } from 'tsup';
3
+ /**
4
+ * 受け取ったビルドオプションに対して、共通するビルドオプションを補完します
5
+ *
6
+ * @param params
7
+ * @returns
8
+ */
9
+ const completeBuildOptions = (params) => {
10
+ return {
11
+ bundle: true,
12
+ minify: 'terser',
13
+ splitting: false,
14
+ noExternal: [/.*/],
15
+ platform: 'browser',
16
+ dts: true,
17
+ ...params,
18
+ esbuildOptions(options, context) {
19
+ options.legalComments = 'none';
20
+ },
21
+ esbuildPlugins: [...(params.esbuildPlugins ?? []), getSassPlugin()],
22
+ };
23
+ };
24
+ export const buildWithTsup = async (buildOptions) => {
25
+ const options = completeBuildOptions(buildOptions);
26
+ await build(options);
27
+ };
@@ -2,13 +2,17 @@ import MiniCssExtractPlugin from 'mini-css-extract-plugin';
2
2
  import path from 'path';
3
3
  import { cwd } from 'process';
4
4
  import TerserPlugin from 'terser-webpack-plugin';
5
- import webpack from 'webpack';
5
+ import webpack, {} from 'webpack';
6
6
  import chalk from 'chalk';
7
7
  import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
8
8
  export const buildWithWebpack = async (props) => {
9
9
  const { entries, outDir } = props;
10
10
  const exclude = /node_modules/;
11
11
  const styleLoader = MiniCssExtractPlugin.loader;
12
+ const tsConfigPath = path.join(cwd(), 'tsconfig.json');
13
+ console.group(chalk.blue('🚀 Building with Webpack...'));
14
+ console.log('🔧 tsconfig.json path:', tsConfigPath);
15
+ console.groupEnd();
12
16
  return new Promise((resolve, reject) => {
13
17
  webpack({
14
18
  mode: 'production',
@@ -19,7 +23,7 @@ export const buildWithWebpack = async (props) => {
19
23
  fallback: {
20
24
  path: false,
21
25
  },
22
- plugins: [new TsconfigPathsPlugin({ configFile: path.join(cwd(), 'tsconfig.json') })],
26
+ plugins: [new TsconfigPathsPlugin({ configFile: tsConfigPath })],
23
27
  },
24
28
  cache: { type: 'filesystem' },
25
29
  output: { filename: '[name].js', path: path.resolve(outDir) },
package/dist/plugin.js CHANGED
@@ -9,6 +9,7 @@ import manifest from './commands/manifest/index.js';
9
9
  import test from './commands/test/index.js';
10
10
  import zip from './commands/plugin-zip.js';
11
11
  import lint from './commands/lint.js';
12
+ import tsup from './commands/plugin-tsup.js';
12
13
  program.name('plugin').version('1.4.0').description('🍳 kintone kitchen 🍳 for kintone plugin');
13
14
  build();
14
15
  esbuild();
@@ -19,4 +20,5 @@ manifest();
19
20
  test();
20
21
  zip();
21
22
  lint();
23
+ tsup();
22
24
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konomi-app/k2",
3
- "version": "1.7.6",
3
+ "version": "1.8.1",
4
4
  "description": "kintone sdk",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -57,16 +57,15 @@
57
57
  "tiny-invariant": "^1",
58
58
  "ts-loader": "^9",
59
59
  "tsconfig-paths-webpack-plugin": "^4",
60
- "vite": "^5",
61
- "vite-tsconfig-paths": "^5",
60
+ "tsup": "^8",
62
61
  "webpack": "^5"
63
62
  },
64
63
  "devDependencies": {
65
64
  "@types/archiver": "*",
66
65
  "@types/eslint": "^8",
67
- "@types/express": "^4",
66
+ "@types/express": "^5",
68
67
  "@types/fs-extra": "*",
69
68
  "@types/html-minifier": "^4",
70
69
  "typescript": "*"
71
70
  }
72
- }
71
+ }
package/types/k2.d.ts CHANGED
@@ -1,27 +1,3 @@
1
- type Locales = {
2
- /** 日本語 */
3
- ja: string;
4
- /** 英語 */
5
- en: string;
6
- /** 簡体字中国語 */
7
- zh: string;
8
- };
9
-
10
- type Resources = {
11
- /**
12
- * プラグインのJavaScriptファイル
13
- *
14
- * URLの配列
15
- */
16
- js: string[];
17
- /**
18
- * プラグインのCSSファイル
19
- *
20
- * URLの配列
21
- */
22
- css: string[];
23
- };
24
-
25
1
  declare namespace K2 {
26
2
  /**
27
3
  * 公開しているプラグインテンプレートで使用する設定ファイル
@@ -48,4 +24,28 @@ declare namespace K2 {
48
24
  type FullConfig = Config & {
49
25
  outDir: string;
50
26
  };
27
+
28
+ type Locales = {
29
+ /** 日本語 */
30
+ ja: string;
31
+ /** 英語 */
32
+ en: string;
33
+ /** 簡体字中国語 */
34
+ zh: string;
35
+ };
36
+
37
+ type Resources = {
38
+ /**
39
+ * プラグインのJavaScriptファイル
40
+ *
41
+ * URLの配列
42
+ */
43
+ js: string[];
44
+ /**
45
+ * プラグインのCSSファイル
46
+ *
47
+ * URLの配列
48
+ */
49
+ css: string[];
50
+ };
51
51
  }
package/types/plugin.d.ts CHANGED
@@ -1,27 +1,3 @@
1
- type Locales = {
2
- /** 日本語 */
3
- ja: string;
4
- /** 英語 */
5
- en: string;
6
- /** 簡体字中国語 */
7
- zh: string;
8
- };
9
-
10
- type Resources = {
11
- /**
12
- * プラグインのJavaScriptファイル
13
- *
14
- * URLの配列
15
- */
16
- js: string[];
17
- /**
18
- * プラグインのCSSファイル
19
- *
20
- * URLの配列
21
- */
22
- css: string[];
23
- };
24
-
25
1
  declare namespace Plugin {
26
2
  namespace Meta {
27
3
  type Env = 'dev' | 'prod' | 'standalone';
@@ -144,4 +120,28 @@ declare namespace Plugin {
144
120
  };
145
121
  };
146
122
  }
123
+
124
+ type Locales = {
125
+ /** 日本語 */
126
+ ja: string;
127
+ /** 英語 */
128
+ en: string;
129
+ /** 簡体字中国語 */
130
+ zh: string;
131
+ };
132
+
133
+ type Resources = {
134
+ /**
135
+ * プラグインのJavaScriptファイル
136
+ *
137
+ * URLの配列
138
+ */
139
+ js: string[];
140
+ /**
141
+ * プラグインのCSSファイル
142
+ *
143
+ * URLの配列
144
+ */
145
+ css: string[];
146
+ };
147
147
  }
@@ -1,8 +0,0 @@
1
- import { build } from 'vite';
2
- export default async function action(params) {
3
- const { viteConfig } = params;
4
- await build({
5
- ...viteConfig,
6
- mode: 'production',
7
- });
8
- }
@@ -1,40 +0,0 @@
1
- import { program } from 'commander';
2
- import { getViteConfig } from '../lib/vite.js';
3
- import { PLUGIN_CONTENTS_DIRECTORY } from '../lib/constants.js';
4
- import path from 'path';
5
- import base from './build-vite-base.js';
6
- export default function command() {
7
- program
8
- .command('build')
9
- .description("Build the project for production. (It's a wrapper of Vite build command.)")
10
- .action(action);
11
- }
12
- export async function action() {
13
- console.group('🍳 Build the project for production');
14
- try {
15
- const viteConfig = getViteConfig({
16
- build: {
17
- rollupOptions: {
18
- input: {
19
- config: path.join('src', 'config', 'index.ts'),
20
- desktop: path.join('src', 'desktop', 'index.ts'),
21
- },
22
- output: {
23
- entryFileNames: '[name].js',
24
- chunkFileNames: '[name].js',
25
- assetFileNames: '[name].[ext]',
26
- },
27
- },
28
- outDir: PLUGIN_CONTENTS_DIRECTORY,
29
- },
30
- });
31
- await base({ viteConfig });
32
- console.log('✨ Build success.');
33
- }
34
- catch (error) {
35
- throw error;
36
- }
37
- finally {
38
- console.groupEnd();
39
- }
40
- }
@@ -1,50 +0,0 @@
1
- import { program } from 'commander';
2
- import { getViteConfig } from '../lib/vite.js';
3
- import { WORKSPACE_DIRECTORY } from '../lib/constants.js';
4
- import path from 'path';
5
- import base from './build-vite-base.js';
6
- import fs from 'fs-extra';
7
- export default function command() {
8
- program
9
- .command('vite-build')
10
- .option('-o, --outdir <outdir>', 'Output directory.', path.join(WORKSPACE_DIRECTORY, 'prod'))
11
- .option('-i, --input <input>', 'Input directory.', path.join('src', 'apps'))
12
- .description("Build the project for production. (It's a wrapper of webpack build command.)")
13
- .action(action);
14
- }
15
- export async function action(options) {
16
- console.group('🍳 Build the project for production');
17
- try {
18
- const { outdir, input } = options;
19
- const allProjects = fs.readdirSync(path.resolve(input));
20
- const entries = allProjects.reduce((acc, dir) => {
21
- for (const filename of ['index.ts', 'index.js', 'index.mjs']) {
22
- if (fs.existsSync(path.join(input, dir, filename))) {
23
- return { ...acc, [dir]: path.join(input, dir, filename) };
24
- }
25
- }
26
- return acc;
27
- }, {});
28
- const viteConfig = getViteConfig({
29
- build: {
30
- rollupOptions: {
31
- input: entries,
32
- output: {
33
- entryFileNames: '[name].js',
34
- chunkFileNames: '[name].js',
35
- assetFileNames: '[name].[ext]',
36
- },
37
- },
38
- outDir: path.resolve(outdir),
39
- },
40
- });
41
- await base({ viteConfig });
42
- console.log('✨ Build success.');
43
- }
44
- catch (error) {
45
- throw error;
46
- }
47
- finally {
48
- console.groupEnd();
49
- }
50
- }
@@ -1,30 +0,0 @@
1
- import { createServer, build } from 'vite';
2
- import chokidar from 'chokidar';
3
- import { PLUGIN_DEVELOPMENT_DIRECTORY } from '../lib/constants.js';
4
- export default async function action(params) {
5
- console.group('🚀 Start development server');
6
- try {
7
- const { viteConfig } = params;
8
- const watcher = chokidar.watch(['src/**/*.{ts,js,jsx,tsx}'], {
9
- ignored: /node_modules/,
10
- persistent: true,
11
- });
12
- const listener = async () => build(viteConfig);
13
- await listener();
14
- watcher.on('change', listener);
15
- watcher.on('add', listener);
16
- watcher.on('unlink', listener);
17
- const server = await createServer({
18
- ...viteConfig,
19
- root: PLUGIN_DEVELOPMENT_DIRECTORY,
20
- });
21
- await server.listen();
22
- server.printUrls();
23
- }
24
- catch (error) {
25
- throw error;
26
- }
27
- finally {
28
- console.groupEnd();
29
- }
30
- }
@@ -1,63 +0,0 @@
1
- import { program } from 'commander';
2
- import { getViteConfig } from '../lib/vite.js';
3
- import { DEVELOPMENT_DIRECTORY, WORKSPACE_DIRECTORY } from '../lib/constants.js';
4
- import path from 'path';
5
- import { DEFAULT_PORT } from '../lib/constants.js';
6
- import fs from 'fs-extra';
7
- import base from './dev-vite-base.js';
8
- export default function command() {
9
- program
10
- .command('vite-dev')
11
- .description('Start development server.')
12
- .option('-i, --input <input>', 'Input directory', 'src/apps')
13
- .option('-o, --outdir <outdir>', 'Output directory.', DEVELOPMENT_DIRECTORY)
14
- .option('-c, --certdir <certdir>', 'Certificate directory', WORKSPACE_DIRECTORY)
15
- .option('-p, --port <port>', 'Port number', DEFAULT_PORT.toString())
16
- .action(action);
17
- }
18
- export async function action(options) {
19
- console.group('🚀 Start development server');
20
- try {
21
- const { certdir, outdir, port, srcdir } = options;
22
- const srcDir = path.resolve(srcdir);
23
- const dirs = fs.readdirSync(srcDir);
24
- const entryPoints = dirs.reduce((acc, dir) => {
25
- for (const filename of ['index.ts', 'index.js', 'index.mjs']) {
26
- if (fs.existsSync(path.join(srcDir, dir, filename))) {
27
- return { ...acc, [dir]: path.join(srcDir, dir, filename) };
28
- }
29
- }
30
- return acc;
31
- }, {});
32
- const viteConfig = getViteConfig({
33
- mode: 'development',
34
- build: {
35
- rollupOptions: {
36
- input: entryPoints,
37
- output: {
38
- entryFileNames: '[name].js',
39
- chunkFileNames: '[name].js',
40
- assetFileNames: '[name].[ext]',
41
- },
42
- },
43
- outDir: path.resolve(outdir),
44
- sourcemap: 'inline',
45
- chunkSizeWarningLimit: 8192,
46
- },
47
- server: {
48
- port: Number(port),
49
- https: {
50
- key: fs.readFileSync(path.join(certdir, 'localhost-key.pem')),
51
- cert: fs.readFileSync(path.join(certdir, 'localhost-cert.pem')),
52
- },
53
- },
54
- });
55
- await base({ viteConfig });
56
- }
57
- catch (error) {
58
- throw error;
59
- }
60
- finally {
61
- console.groupEnd();
62
- }
63
- }
package/dist/lib/vite.js DELETED
@@ -1,25 +0,0 @@
1
- import path from 'path';
2
- import tsconfigPaths from 'vite-tsconfig-paths';
3
- export const getViteConfig = (config) => {
4
- return {
5
- ...config,
6
- configFile: false,
7
- build: {
8
- ...config.build,
9
- rollupOptions: {
10
- ...config.build?.rollupOptions,
11
- onwarn: (warning, warn) => {
12
- if (['MODULE_LEVEL_DIRECTIVE'].includes(warning.code ?? '')) {
13
- return;
14
- }
15
- warn(warning);
16
- },
17
- },
18
- },
19
- plugins: [...(config.plugins ?? []), tsconfigPaths()],
20
- resolve: {
21
- ...config.resolve,
22
- alias: { '@': path.resolve('src') },
23
- },
24
- };
25
- };