@konomi-app/k2 0.2.0 → 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
+ }
@@ -0,0 +1,40 @@
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
+ }
@@ -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,40 +1,50 @@
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 } from '../lib/constants.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';
7
8
  export default function command() {
8
- 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);
9
16
  }
10
- export async function action() {
17
+ export async function action(options) {
11
18
  console.group('🚀 Start development server');
12
19
  try {
13
- const config = await importPluginConfig();
14
- const watcher = chokidar.watch(['src/**/*.{ts,js,jsx,tsx}'], {
15
- ignored: /node_modules/,
16
- persistent: true,
17
- });
18
- const viteConfig = getViteConfig(config);
19
- const listener = async () => build({
20
- ...viteConfig,
20
+ const { certdir, outdir, port } = options;
21
+ const viteConfig = getViteConfig({
21
22
  mode: 'development',
22
23
  build: {
23
- ...viteConfig.build,
24
+ rollupOptions: {
25
+ input: {
26
+ config: path.join('src', 'config', 'index.ts'),
27
+ desktop: path.join('src', 'desktop', 'index.ts'),
28
+ },
29
+ output: {
30
+ entryFileNames: '[name].js',
31
+ chunkFileNames: '[name].js',
32
+ assetFileNames: '[name].[ext]',
33
+ },
34
+ },
35
+ outDir: path.resolve(outdir),
24
36
  sourcemap: 'inline',
25
37
  chunkSizeWarningLimit: 8192,
26
38
  },
39
+ server: {
40
+ port: Number(port),
41
+ https: {
42
+ key: fs.readFileSync(path.join(certdir, 'localhost-key.pem')),
43
+ cert: fs.readFileSync(path.join(certdir, 'localhost-cert.pem')),
44
+ },
45
+ },
27
46
  });
28
- await listener();
29
- watcher.on('change', listener);
30
- watcher.on('add', listener);
31
- watcher.on('unlink', listener);
32
- const server = await createServer({
33
- ...viteConfig,
34
- root: PLUGIN_DEVELOPMENT_DIRECTORY,
35
- });
36
- await server.listen();
37
- server.printUrls();
47
+ await base({ viteConfig });
38
48
  }
39
49
  catch (error) {
40
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/dist/lib/vite.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import path from 'path';
2
- import fs from 'fs-extra';
3
- import { DEFAULT_PORT, PLUGIN_DEVELOPMENT_DIRECTORY, PLUGIN_WORKSPACE_DIRECTORY, } from './constants.js';
2
+ import { PLUGIN_DEVELOPMENT_DIRECTORY } from './constants.js';
4
3
  import tsconfigPaths from 'vite-tsconfig-paths';
5
4
  export const getViteConfig = (config) => {
6
5
  return {
@@ -9,15 +8,7 @@ export const getViteConfig = (config) => {
9
8
  outDir: PLUGIN_DEVELOPMENT_DIRECTORY,
10
9
  emptyOutDir: true,
11
10
  rollupOptions: {
12
- input: {
13
- config: path.join('src', 'config', 'index.ts'),
14
- desktop: path.join('src', 'desktop', 'index.ts'),
15
- },
16
- output: {
17
- entryFileNames: '[name].js',
18
- chunkFileNames: '[name].js',
19
- assetFileNames: '[name].[ext]',
20
- },
11
+ ...config.build?.rollupOptions,
21
12
  onwarn: (warning, warn) => {
22
13
  if (['MODULE_LEVEL_DIRECTIVE'].includes(warning.code ?? '')) {
23
14
  return;
@@ -27,13 +18,7 @@ export const getViteConfig = (config) => {
27
18
  },
28
19
  },
29
20
  plugins: [tsconfigPaths()],
30
- server: {
31
- port: config.server?.port ?? DEFAULT_PORT,
32
- https: {
33
- key: fs.readFileSync(path.join(PLUGIN_WORKSPACE_DIRECTORY, 'localhost-key.pem')),
34
- cert: fs.readFileSync(path.join(PLUGIN_WORKSPACE_DIRECTORY, 'localhost-cert.pem')),
35
- },
36
- },
21
+ server: config.server,
37
22
  resolve: {
38
23
  alias: { '@': path.resolve('src') },
39
24
  },
@@ -22,7 +22,7 @@ export const buildWithWebpack = async (props) => {
22
22
  plugins: [new TsconfigPathsPlugin({ configFile: path.join(cwd(), 'tsconfig.json') })],
23
23
  },
24
24
  cache: { type: 'filesystem' },
25
- output: { filename: '[name].js', path: outDir },
25
+ output: { filename: '[name].js', path: path.resolve(outDir) },
26
26
  module: {
27
27
  rules: [
28
28
  { test: /\.tsx?$/, exclude, loader: 'ts-loader' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konomi-app/k2",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "kintone sdk",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -1,30 +0,0 @@
1
- import { program } from 'commander';
2
- import { build } from 'vite';
3
- import { importPluginConfig } from '../lib/import.js';
4
- import { getViteConfig } from '../lib/vite.js';
5
- import { PLUGIN_CONTENTS_DIRECTORY } from '../lib/constants.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 config = await importPluginConfig();
16
- const viteConfig = getViteConfig(config);
17
- await build({
18
- ...viteConfig,
19
- mode: 'production',
20
- build: { ...viteConfig.build, outDir: PLUGIN_CONTENTS_DIRECTORY },
21
- });
22
- console.log('✨ Build success.');
23
- }
24
- catch (error) {
25
- throw error;
26
- }
27
- finally {
28
- console.groupEnd();
29
- }
30
- }