@konomi-app/k2 0.3.1 → 0.4.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.
@@ -0,0 +1,36 @@
1
+ import { program } from 'commander';
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ import { WORKSPACE_DIRECTORY } from '../lib/constants.js';
5
+ import { buildWithEsbuild } from '../lib/esbuild.js';
6
+ export default function command() {
7
+ program
8
+ .command('esbuild-build')
9
+ .option('-o, --outdir <outdir>', 'Output directory.', path.join(WORKSPACE_DIRECTORY, 'prod'))
10
+ .option('-i, --input <input>', 'Input directory.', path.join('src', 'apps'))
11
+ .description("Build the project for production. (It's a wrapper of webpack build command.)")
12
+ .action(action);
13
+ }
14
+ export async function action(options) {
15
+ console.group('🍳 Build the project for production');
16
+ try {
17
+ const { outdir, input } = options;
18
+ const allProjects = fs.readdirSync(path.resolve(input));
19
+ const entryPoints = allProjects.reduce((acc, dir) => {
20
+ for (const filename of ['index.ts', 'index.js', 'index.mjs']) {
21
+ if (fs.existsSync(path.join(input, dir, filename))) {
22
+ return { ...acc, [dir]: path.join(input, dir, filename) };
23
+ }
24
+ }
25
+ return acc;
26
+ }, {});
27
+ await buildWithEsbuild({ entryPoints, outdir, minify: true, sourcemap: false });
28
+ console.log('✨ Build success.');
29
+ }
30
+ catch (error) {
31
+ throw error;
32
+ }
33
+ finally {
34
+ console.groupEnd();
35
+ }
36
+ }
@@ -0,0 +1,15 @@
1
+ import path from 'path';
2
+ import { getEsbuildContext } from '../lib/esbuild.js';
3
+ export default async function action(params) {
4
+ const { entryPoints, staticDir: outdir, certDir, port } = params;
5
+ const context = await getEsbuildContext({ sourcemap: 'inline', entryPoints, outdir });
6
+ const [_, serveResult] = await Promise.all([
7
+ context.watch(),
8
+ context.serve({
9
+ port,
10
+ keyfile: path.join(certDir, 'localhost-key.pem'),
11
+ certfile: path.join(certDir, 'localhost-cert.pem'),
12
+ }),
13
+ ]);
14
+ console.log(`🚀 Start development server at https://localhost:${serveResult.port}`);
15
+ }
@@ -9,6 +9,7 @@ export default function command() {
9
9
  program
10
10
  .command('vite-dev')
11
11
  .description('Start development server.')
12
+ .option('-i, --input <input>', 'Input directory', 'src/apps')
12
13
  .option('-o, --outdir <outdir>', 'Output directory.', DEVELOPMENT_DIRECTORY)
13
14
  .option('-c, --certdir <certdir>', 'Certificate directory', WORKSPACE_DIRECTORY)
14
15
  .option('-p, --port <port>', 'Port number', DEFAULT_PORT.toString())
@@ -17,15 +18,22 @@ export default function command() {
17
18
  export async function action(options) {
18
19
  console.group('🚀 Start development server');
19
20
  try {
20
- const { certdir, outdir, port } = options;
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
+ }, {});
21
32
  const viteConfig = getViteConfig({
22
33
  mode: 'development',
23
34
  build: {
24
35
  rollupOptions: {
25
- input: {
26
- config: path.join('src', 'config', 'index.ts'),
27
- desktop: path.join('src', 'desktop', 'index.ts'),
28
- },
36
+ input: entryPoints,
29
37
  output: {
30
38
  entryFileNames: '[name].js',
31
39
  chunkFileNames: '[name].js',
@@ -2,23 +2,24 @@ import { program } from 'commander';
2
2
  import fs from 'fs-extra';
3
3
  import path from 'path';
4
4
  import { DEFAULT_PORT, DEVELOPMENT_DIRECTORY, WORKSPACE_DIRECTORY } from '../lib/constants.js';
5
- import base from './dev-base.js';
5
+ import base from './dev-base-esbuild.js';
6
6
  export default function command() {
7
7
  program
8
8
  .command('dev')
9
9
  .description('Start development server.')
10
+ .option('-i, --input <input>', 'Input directory', 'src/apps')
10
11
  .option('-o, --outdir <outdir>', 'Output directory.', DEVELOPMENT_DIRECTORY)
11
12
  .option('-c, --certdir <certdir>', 'Certificate directory', WORKSPACE_DIRECTORY)
12
13
  .option('-p, --port <port>', 'Port number', DEFAULT_PORT.toString())
13
14
  .action(action);
14
15
  }
15
16
  export async function action(options) {
16
- const { certdir, outdir, port } = options;
17
+ const { certdir, outdir, port, input } = options;
17
18
  console.group('🍳 Start development server');
18
19
  try {
19
20
  console.log(`📂 Output directory: ${outdir}`);
20
21
  console.log(`🔑 Certificate directory: ${certdir}`);
21
- const srcDir = path.join('src', 'apps');
22
+ const srcDir = path.resolve(input);
22
23
  const dirs = fs.readdirSync(srcDir);
23
24
  const entryPoints = dirs.reduce((acc, dir) => {
24
25
  for (const filename of ['index.ts', 'index.js', 'index.mjs']) {
@@ -9,7 +9,7 @@ import chokider from 'chokidar';
9
9
  import { getContentsZipBuffer, getZipFileNameSuffix, outputContentsZip } from '../lib/zip.js';
10
10
  import packer from '@kintone/plugin-packer';
11
11
  import { uploadZip } from '../lib/utils.js';
12
- import base from './dev-base.js';
12
+ import base from './dev-base-esbuild.js';
13
13
  export default function command() {
14
14
  program.command('dev').description('Start development server.').action(action);
15
15
  }
package/dist/index.js CHANGED
@@ -5,9 +5,11 @@ import viteBuild from './commands/build-vite.js';
5
5
  import dev from './commands/dev.js';
6
6
  import viteDev from './commands/dev-vite.js';
7
7
  import genkey from './commands/genkey.js';
8
+ import esbuildBuild from './commands/build-esbuild.js';
8
9
  program.name('k2').version('0.1.0').description('k2 - 🍳 kintone kitchen 🍳');
9
10
  build();
10
11
  viteBuild();
12
+ esbuildBuild();
11
13
  dev();
12
14
  viteDev();
13
15
  genkey();
@@ -36,14 +36,10 @@ export const getSassPlugin = () => {
36
36
  },
37
37
  };
38
38
  };
39
- export const buildWithEsbuild = async (params) => {
40
- const { entryPoints, outdir } = params;
41
- const context = await esbuild.context({
42
- entryPoints,
39
+ export const getEsbuildContext = async (params) => {
40
+ return esbuild.context({
43
41
  bundle: true,
44
- sourcemap: 'inline',
45
42
  platform: 'browser',
46
- outdir,
47
43
  plugins: [
48
44
  {
49
45
  name: 'on-end',
@@ -53,6 +49,10 @@ export const buildWithEsbuild = async (params) => {
53
49
  },
54
50
  getSassPlugin(),
55
51
  ],
52
+ ...params,
56
53
  });
54
+ };
55
+ export const buildWithEsbuild = async (params) => {
56
+ const context = await getEsbuildContext(params);
57
57
  context.watch();
58
58
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konomi-app/k2",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "kintone sdk",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",