@konomi-app/k2 0.2.1 → 0.3.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,8 @@
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,8 +1,8 @@
1
1
  import { program } from 'commander';
2
- import { build } from 'vite';
3
2
  import { getViteConfig } from '../lib/vite.js';
4
3
  import { PLUGIN_CONTENTS_DIRECTORY } from '../lib/constants.js';
5
4
  import path from 'path';
5
+ import base from './build-vite-base.js';
6
6
  export default function command() {
7
7
  program
8
8
  .command('build')
@@ -25,13 +25,10 @@ export async function action() {
25
25
  assetFileNames: '[name].[ext]',
26
26
  },
27
27
  },
28
+ outDir: PLUGIN_CONTENTS_DIRECTORY,
28
29
  },
29
30
  });
30
- await build({
31
- ...viteConfig,
32
- mode: 'production',
33
- build: { ...viteConfig.build, outDir: PLUGIN_CONTENTS_DIRECTORY },
34
- });
31
+ await base({ viteConfig });
35
32
  console.log('✨ Build success.');
36
33
  }
37
34
  catch (error) {
@@ -0,0 +1,50 @@
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('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
+ }
@@ -0,0 +1,30 @@
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,24 +1,25 @@
1
1
  import { program } from 'commander';
2
- import { createServer, build } from 'vite';
3
- import { importPluginConfig } from '../lib/import.js';
4
2
  import { getViteConfig } from '../lib/vite.js';
5
- import chokidar from 'chokidar';
6
- import { PLUGIN_DEVELOPMENT_DIRECTORY, PLUGIN_WORKSPACE_DIRECTORY } from '../lib/constants.js';
3
+ import { DEVELOPMENT_DIRECTORY, WORKSPACE_DIRECTORY } from '../lib/constants.js';
7
4
  import path from 'path';
8
5
  import { DEFAULT_PORT } from '../lib/constants.js';
9
6
  import fs from 'fs-extra';
7
+ import base from './dev-vite-base.js';
10
8
  export default function command() {
11
- program.command('dev').description('Start development server.').action(action);
9
+ program
10
+ .command('vite-dev')
11
+ .description('Start development server.')
12
+ .option('-o, --outdir <outdir>', 'Output directory.', DEVELOPMENT_DIRECTORY)
13
+ .option('-c, --certdir <certdir>', 'Certificate directory', WORKSPACE_DIRECTORY)
14
+ .option('-p, --port <port>', 'Port number', DEFAULT_PORT.toString())
15
+ .action(action);
12
16
  }
13
- export async function action() {
17
+ export async function action(options) {
14
18
  console.group('🚀 Start development server');
15
19
  try {
16
- const config = await importPluginConfig();
17
- const watcher = chokidar.watch(['src/**/*.{ts,js,jsx,tsx}'], {
18
- ignored: /node_modules/,
19
- persistent: true,
20
- });
20
+ const { certdir, outdir, port } = options;
21
21
  const viteConfig = getViteConfig({
22
+ mode: 'development',
22
23
  build: {
23
24
  rollupOptions: {
24
25
  input: {
@@ -31,34 +32,19 @@ export async function action() {
31
32
  assetFileNames: '[name].[ext]',
32
33
  },
33
34
  },
35
+ outDir: path.resolve(outdir),
36
+ sourcemap: 'inline',
37
+ chunkSizeWarningLimit: 8192,
34
38
  },
35
39
  server: {
36
- port: config.server?.port ?? DEFAULT_PORT,
40
+ port: Number(port),
37
41
  https: {
38
- key: fs.readFileSync(path.join(PLUGIN_WORKSPACE_DIRECTORY, 'localhost-key.pem')),
39
- cert: fs.readFileSync(path.join(PLUGIN_WORKSPACE_DIRECTORY, 'localhost-cert.pem')),
42
+ key: fs.readFileSync(path.join(certdir, 'localhost-key.pem')),
43
+ cert: fs.readFileSync(path.join(certdir, 'localhost-cert.pem')),
40
44
  },
41
45
  },
42
46
  });
43
- const listener = async () => build({
44
- ...viteConfig,
45
- mode: 'development',
46
- build: {
47
- ...viteConfig.build,
48
- sourcemap: 'inline',
49
- chunkSizeWarningLimit: 8192,
50
- },
51
- });
52
- await listener();
53
- watcher.on('change', listener);
54
- watcher.on('add', listener);
55
- watcher.on('unlink', listener);
56
- const server = await createServer({
57
- ...viteConfig,
58
- root: PLUGIN_DEVELOPMENT_DIRECTORY,
59
- });
60
- await server.listen();
61
- server.printUrls();
47
+ await base({ viteConfig });
62
48
  }
63
49
  catch (error) {
64
50
  throw error;
package/dist/index.js CHANGED
@@ -1,10 +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';
4
5
  import dev from './commands/dev.js';
6
+ import viteDev from './commands/vite-dev.js';
5
7
  import genkey from './commands/genkey.js';
6
8
  program.name('k2').version('0.1.0').description('k2 - 🍳 kintone kitchen 🍳');
7
9
  build();
10
+ viteBuild();
8
11
  dev();
12
+ viteDev();
9
13
  genkey();
10
14
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konomi-app/k2",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "kintone sdk",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",