@konomi-app/k2 0.1.0 → 0.1.2

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,8 +1,8 @@
1
1
  import { program } from 'commander';
2
2
  import { build } from 'vite';
3
- import { importPluginConfig } from '../../lib/import.js';
4
- import { getViteConfig } from '../../lib/vite.js';
5
- import { CONTENTS_DIRECTORY } from '../../lib/constants.js';
3
+ import { importPluginConfig } from '../lib/import.js';
4
+ import { getViteConfig } from '../lib/vite.js';
5
+ import { PLUGIN_CONTENTS_DIRECTORY } from '../lib/constants.js';
6
6
  export default function command() {
7
7
  program
8
8
  .command('build')
@@ -10,14 +10,14 @@ export default function command() {
10
10
  .action(action);
11
11
  }
12
12
  export async function action() {
13
- console.group('🚀 Build the project for production');
13
+ console.group('🍳 Build the project for production');
14
14
  try {
15
15
  const config = await importPluginConfig();
16
16
  const viteConfig = getViteConfig(config);
17
17
  await build({
18
18
  ...viteConfig,
19
19
  mode: 'production',
20
- build: { ...viteConfig.build, outDir: CONTENTS_DIRECTORY },
20
+ build: { ...viteConfig.build, outDir: PLUGIN_CONTENTS_DIRECTORY },
21
21
  });
22
22
  console.log('✨ Build success.');
23
23
  }
@@ -0,0 +1,35 @@
1
+ import express from 'express';
2
+ import fs from 'fs-extra';
3
+ import { createServer } from 'https';
4
+ import path from 'path';
5
+ import { generateCert } from '../lib/cert.js';
6
+ import { buildWithEsbuild } from '../lib/esbuild.js';
7
+ export default function action(params) {
8
+ const { entryPoints, staticDir, certDir, port } = params;
9
+ return Promise.all([build({ entryPoints, staticDir }), server({ port, certDir, staticDir })]);
10
+ }
11
+ async function build(params) {
12
+ const { entryPoints, staticDir: outdir } = params;
13
+ return buildWithEsbuild({ entryPoints, outdir });
14
+ }
15
+ async function server(params) {
16
+ const { certDir, port, staticDir } = params;
17
+ const app = express();
18
+ app.use(express.static(staticDir));
19
+ const privateKeyPath = path.join(certDir, 'localhost-key.pem');
20
+ const certificatePath = path.join(certDir, 'localhost-cert.pem');
21
+ if (!fs.existsSync(privateKeyPath) || !fs.existsSync(certificatePath)) {
22
+ await generateCert(certDir);
23
+ console.log('🔑 Certificate generated');
24
+ }
25
+ const privateKey = fs.readFileSync(privateKeyPath);
26
+ const certificate = fs.readFileSync(certificatePath);
27
+ const server = createServer({ key: privateKey, cert: certificate }, app);
28
+ const res = server.listen(port);
29
+ res.on('error', (error) => {
30
+ console.error(error);
31
+ });
32
+ res.on('listening', () => {
33
+ console.log(`🚀 Server started! https://localhost:${port}`);
34
+ });
35
+ }
@@ -0,0 +1,41 @@
1
+ import { program } from 'commander';
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ import { DEFAULT_PORT, DEVELOPMENT_DIRECTORY, WORKSPACE_DIRECTORY } from '../lib/constants.js';
5
+ import base from './dev-base.js';
6
+ export default function command() {
7
+ program
8
+ .command('dev')
9
+ .description('Start development server.')
10
+ .option('-o, --outdir <outdir>', 'Output directory.', DEVELOPMENT_DIRECTORY)
11
+ .option('-p, --port <port>', 'Port number', DEFAULT_PORT.toString())
12
+ .action(action);
13
+ }
14
+ export async function action(options) {
15
+ const { outdir, port } = options;
16
+ console.group('🍳 Start development server');
17
+ try {
18
+ const srcDir = path.join('src', 'apps');
19
+ const dirs = fs.readdirSync(srcDir);
20
+ const entryPoints = dirs.reduce((acc, dir) => {
21
+ for (const filename of ['index.ts', 'index.js', 'index.mjs']) {
22
+ if (fs.existsSync(path.join(srcDir, dir, filename))) {
23
+ return [...acc, { in: path.join(srcDir, dir, filename), out: dir }];
24
+ }
25
+ }
26
+ return acc;
27
+ }, []);
28
+ base({
29
+ port: Number(port),
30
+ entryPoints,
31
+ certDir: WORKSPACE_DIRECTORY,
32
+ staticDir: outdir,
33
+ });
34
+ }
35
+ catch (error) {
36
+ throw error;
37
+ }
38
+ finally {
39
+ console.groupEnd();
40
+ }
41
+ }
@@ -0,0 +1,18 @@
1
+ import { generateCert } from '../lib/cert.js';
2
+ export default async function action(options) {
3
+ const { output } = options;
4
+ console.group('🍳 Generate SSL key for localhost');
5
+ try {
6
+ const { stdout } = await generateCert(output);
7
+ if (stdout) {
8
+ console.log(stdout);
9
+ }
10
+ console.log(`🔑 key generation success. Output to ./${output}`);
11
+ }
12
+ catch (error) {
13
+ throw error;
14
+ }
15
+ finally {
16
+ console.groupEnd();
17
+ }
18
+ }
@@ -0,0 +1,13 @@
1
+ import { program } from 'commander';
2
+ import base from './genkey-base.js';
3
+ import { WORKSPACE_DIRECTORY } from '../lib/constants.js';
4
+ export default function command() {
5
+ program
6
+ .command('genkey')
7
+ .description('Generate SSL key for localhost. (Require mkcert)')
8
+ .option('-o, --output <output>', 'Output directory.', WORKSPACE_DIRECTORY)
9
+ .action(action);
10
+ }
11
+ export async function action(options) {
12
+ await base(options);
13
+ }
@@ -3,24 +3,21 @@ import fs from 'fs-extra';
3
3
  import path from 'path';
4
4
  import packer from '@kintone/plugin-packer';
5
5
  import { outputManifest } from '../../lib/plugin-manifest.js';
6
- import { WORKSPACE_DIRECTORY } from '../../lib/constants.js';
6
+ import { PLUGIN_WORKSPACE_DIRECTORY } from '../../lib/constants.js';
7
7
  import { getContentsZipBuffer, outputContentsZip } from '../../lib/zip.js';
8
8
  import { copyPluginContents } from '../../lib/plugin-contents.js';
9
9
  export default function command() {
10
- program
11
- .command('init')
12
- .description('generate private.ppk and kitting config')
13
- .action(action);
10
+ program.command('init').description('generate private.ppk and kitting config').action(action);
14
11
  }
15
12
  export async function action() {
16
- console.group('🚀 Executing plugin initialization setup');
13
+ console.group('🍳 Executing plugin initialization setup');
17
14
  try {
18
15
  const manifest = await outputManifest('dev');
19
16
  console.log('📝 manifest.json generated');
20
17
  await copyPluginContents();
21
18
  console.log('📁 contents copied');
22
19
  let privateKey;
23
- const keyPath = path.join(WORKSPACE_DIRECTORY, 'private.ppk');
20
+ const keyPath = path.join(PLUGIN_WORKSPACE_DIRECTORY, 'private.ppk');
24
21
  if (fs.existsSync(keyPath)) {
25
22
  privateKey = await fs.readFile(keyPath, 'utf8');
26
23
  }
@@ -28,13 +25,13 @@ export async function action() {
28
25
  const buffer = await getContentsZipBuffer();
29
26
  const output = await packer(buffer, privateKey);
30
27
  if (!privateKey) {
31
- await fs.writeFile(path.join(WORKSPACE_DIRECTORY, 'private.ppk'), output.privateKey);
28
+ await fs.writeFile(path.join(PLUGIN_WORKSPACE_DIRECTORY, 'private.ppk'), output.privateKey);
32
29
  console.log('🔐 private.ppk generated');
33
30
  }
34
31
  else {
35
32
  console.log('🔐 private.ppk already exists. The existing private.ppk will be used.');
36
33
  }
37
- await fs.writeFile(path.join(WORKSPACE_DIRECTORY, 'plugin.zip'), output.plugin);
34
+ await fs.writeFile(path.join(PLUGIN_WORKSPACE_DIRECTORY, 'plugin.zip'), output.plugin);
38
35
  console.log('📦 plugin.zip generated');
39
36
  console.log('✨ Plugin initialization setup completed! zip file path is ./.plugin/plugin.zip');
40
37
  }
@@ -0,0 +1,27 @@
1
+ import { program } from 'commander';
2
+ import { PLUGIN_CONTENTS_DIRECTORY } from '../lib/constants.js';
3
+ import { buildWithWebpack } from '../lib/webpack.js';
4
+ import path from 'path';
5
+ export default function command() {
6
+ program
7
+ .command('build')
8
+ .description("Build the project for production. (It's a wrapper of webpack build command.)")
9
+ .action(action);
10
+ }
11
+ export async function action() {
12
+ console.group('🍳 Build the project for production');
13
+ try {
14
+ await buildWithWebpack({
15
+ mode: 'plugin',
16
+ srcRoot: path.resolve('src'),
17
+ distRoot: PLUGIN_CONTENTS_DIRECTORY,
18
+ });
19
+ console.log('✨ Build success.');
20
+ }
21
+ catch (error) {
22
+ throw error;
23
+ }
24
+ finally {
25
+ console.groupEnd();
26
+ }
27
+ }
@@ -1,26 +1,20 @@
1
1
  import { program } from 'commander';
2
- import { importPluginConfig } from '../../lib/import.js';
3
- import express from 'express';
4
- import { createServer } from 'https';
2
+ import { importPluginConfig } from '../lib/import.js';
5
3
  import path from 'path';
6
- import { DEFAULT_PORT, DEVELOPMENT_DIRECTORY, WORKSPACE_DIRECTORY, } from '../../lib/constants.js';
4
+ import { DEFAULT_PORT, PLUGIN_DEVELOPMENT_DIRECTORY, PLUGIN_WORKSPACE_DIRECTORY, } from '../lib/constants.js';
7
5
  import fs from 'fs-extra';
8
- import { outputManifest } from '../../lib/plugin-manifest.js';
9
- import { copyPluginContents } from '../../lib/plugin-contents.js';
6
+ import { outputManifest } from '../lib/plugin-manifest.js';
7
+ import { copyPluginContents } from '../lib/plugin-contents.js';
10
8
  import chokider from 'chokidar';
11
- import { generateCert } from '../../lib/cert.js';
12
- import { getContentsZipBuffer, getZipFileNameSuffix, outputContentsZip, } from '../../lib/zip.js';
9
+ import { getContentsZipBuffer, getZipFileNameSuffix, outputContentsZip } from '../lib/zip.js';
13
10
  import packer from '@kintone/plugin-packer';
14
- import { uploadZip } from '../../lib/utils.js';
15
- import { buildWithEsbuild } from '../../lib/esbuild.js';
11
+ import { uploadZip } from '../lib/utils.js';
12
+ import base from './dev-base.js';
16
13
  export default function command() {
17
- program
18
- .command('dev')
19
- .description('Start development server.')
20
- .action(action);
14
+ program.command('dev').description('Start development server.').action(action);
21
15
  }
22
16
  export async function action() {
23
- console.group('🚀 Start development server');
17
+ console.group('🍳 Start development server');
24
18
  try {
25
19
  const config = await importPluginConfig();
26
20
  const port = config.server?.port ?? DEFAULT_PORT;
@@ -69,38 +63,23 @@ export async function action() {
69
63
  watcher.on('unlink', contentsListener);
70
64
  await outputContentsZip(manifest);
71
65
  const buffer = await getContentsZipBuffer();
72
- const pluginPrivateKey = await fs.readFile(path.join(WORKSPACE_DIRECTORY, 'private.ppk'), 'utf8');
66
+ const pluginPrivateKey = await fs.readFile(path.join(PLUGIN_WORKSPACE_DIRECTORY, 'private.ppk'), 'utf8');
73
67
  const output = await packer(buffer, pluginPrivateKey);
74
68
  const zipFileName = `plugin${getZipFileNameSuffix('dev')}.zip`;
75
- await fs.writeFile(path.join(WORKSPACE_DIRECTORY, zipFileName), output.plugin);
69
+ await fs.writeFile(path.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName), output.plugin);
76
70
  uploadZip('dev').then(({ stdout, stderr }) => {
77
71
  console.log(stdout);
78
72
  console.error(stderr);
79
73
  });
80
- const app = express();
81
- app.use(express.static(DEVELOPMENT_DIRECTORY));
82
- const privateKeyPath = path.join(WORKSPACE_DIRECTORY, 'localhost-key.pem');
83
- const certificatePath = path.join(WORKSPACE_DIRECTORY, 'localhost-cert.pem');
84
- if (!fs.existsSync(privateKeyPath) || !fs.existsSync(certificatePath)) {
85
- await generateCert(WORKSPACE_DIRECTORY);
86
- console.log('🔑 Certificate generated');
87
- }
88
- const privateKey = fs.readFileSync(privateKeyPath);
89
- const certificate = fs.readFileSync(certificatePath);
90
- const server = createServer({ key: privateKey, cert: certificate }, app);
91
- const res = server.listen(port);
92
- buildWithEsbuild({
93
- entryPoints: ['desktop', 'config'].map((dir) => ({
94
- in: path.join('src', dir, 'index.ts'),
95
- out: dir,
96
- })),
97
- outdir: DEVELOPMENT_DIRECTORY,
98
- });
99
- res.on('error', (error) => {
100
- console.error(error);
101
- });
102
- res.on('listening', () => {
103
- console.log(`🚀 Server started! https://localhost:${port}`);
74
+ const entryPoints = ['desktop', 'config'].map((dir) => ({
75
+ in: path.join('src', dir, 'index.ts'),
76
+ out: dir,
77
+ }));
78
+ base({
79
+ port,
80
+ entryPoints,
81
+ certDir: PLUGIN_WORKSPACE_DIRECTORY,
82
+ staticDir: PLUGIN_DEVELOPMENT_DIRECTORY,
104
83
  });
105
84
  }
106
85
  catch (error) {
@@ -0,0 +1,12 @@
1
+ import { program } from 'commander';
2
+ import base from './genkey-base.js';
3
+ import { PLUGIN_WORKSPACE_DIRECTORY } from '../lib/constants.js';
4
+ export default function command() {
5
+ program
6
+ .command('genkey')
7
+ .description('Generate SSL key for localhost. (Require mkcert)')
8
+ .action(action);
9
+ }
10
+ export async function action() {
11
+ await base({ output: PLUGIN_WORKSPACE_DIRECTORY });
12
+ }
@@ -1,12 +1,12 @@
1
1
  import { program } from 'commander';
2
- import { outputManifest } from '../../lib/plugin-manifest.js';
2
+ import { outputManifest } from '../lib/plugin-manifest.js';
3
3
  import fs from 'fs-extra';
4
4
  import path from 'path';
5
- import { WORKSPACE_DIRECTORY } from '../../lib/constants.js';
5
+ import { PLUGIN_WORKSPACE_DIRECTORY } from '../lib/constants.js';
6
6
  import packer from '@kintone/plugin-packer';
7
- import { getContentsZipBuffer, getZipFileNameSuffix, outputContentsZip, } from '../../lib/zip.js';
8
- import { copyPluginContents } from '../../lib/plugin-contents.js';
9
- import { isEnv } from '../../lib/utils.js';
7
+ import { getContentsZipBuffer, getZipFileNameSuffix, outputContentsZip } from '../lib/zip.js';
8
+ import { copyPluginContents } from '../lib/plugin-contents.js';
9
+ import { isEnv } from '../lib/utils.js';
10
10
  export default function command() {
11
11
  program
12
12
  .command('zip')
@@ -15,7 +15,7 @@ export default function command() {
15
15
  .action(action);
16
16
  }
17
17
  async function action(options) {
18
- console.group('🚀 Executing plugin zip generation');
18
+ console.group('🍳 Executing plugin zip generation');
19
19
  try {
20
20
  const { env } = options;
21
21
  if (!isEnv(env)) {
@@ -27,10 +27,10 @@ async function action(options) {
27
27
  console.log(`📝 manifest.json generated (${env})`);
28
28
  await outputContentsZip(manifest);
29
29
  const buffer = await getContentsZipBuffer();
30
- const privateKey = await fs.readFile(path.join(WORKSPACE_DIRECTORY, 'private.ppk'), 'utf8');
30
+ const privateKey = await fs.readFile(path.join(PLUGIN_WORKSPACE_DIRECTORY, 'private.ppk'), 'utf8');
31
31
  const output = await packer(buffer, privateKey);
32
32
  const zipFileName = `plugin${getZipFileNameSuffix(env)}.zip`;
33
- await fs.writeFile(path.join(WORKSPACE_DIRECTORY, zipFileName), output.plugin);
33
+ await fs.writeFile(path.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName), output.plugin);
34
34
  console.log('📦 plugin.zip generated');
35
35
  console.log(`✨ Plugin zip generation completed! zip file path is ./.plugin/${zipFileName}`);
36
36
  }
@@ -3,12 +3,9 @@ import { createServer, build } from 'vite';
3
3
  import { importPluginConfig } from '../../lib/import.js';
4
4
  import { getViteConfig } from '../../lib/vite.js';
5
5
  import chokidar from 'chokidar';
6
- import { DEVELOPMENT_DIRECTORY } from '../../lib/constants.js';
6
+ import { PLUGIN_DEVELOPMENT_DIRECTORY } from '../../lib/constants.js';
7
7
  export default function command() {
8
- program
9
- .command('dev')
10
- .description('Start development server.')
11
- .action(action);
8
+ program.command('dev').description('Start development server.').action(action);
12
9
  }
13
10
  export async function action() {
14
11
  console.group('🚀 Start development server');
@@ -34,7 +31,7 @@ export async function action() {
34
31
  watcher.on('unlink', listener);
35
32
  const server = await createServer({
36
33
  ...viteConfig,
37
- root: DEVELOPMENT_DIRECTORY,
34
+ root: PLUGIN_DEVELOPMENT_DIRECTORY,
38
35
  });
39
36
  await server.listen();
40
37
  server.printUrls();
package/dist/index.js CHANGED
@@ -1,20 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import { program } from 'commander';
3
- import build from './commands/build/index.js';
4
- import dev from './commands/dev/index.js';
5
- import genkey from './commands/genkey/index.js';
6
- import init from './commands/init/index.js';
7
- import manifest from './commands/manifest/index.js';
8
- import test from './commands/test/index.js';
3
+ import build from './commands/build-base.js';
4
+ import dev from './commands/dev.js';
5
+ import genkey from './commands/genkey.js';
9
6
  import upload from './commands/upload/index.js';
10
- import zip from './commands/zip/index.js';
11
7
  program.name('k2').version('0.1.0').description('');
12
8
  build();
13
9
  dev();
14
10
  genkey();
15
- init();
16
- manifest();
17
- test();
18
11
  upload();
19
- zip();
20
12
  program.parse(process.argv);
@@ -1,5 +1,11 @@
1
1
  import path from 'path';
2
- export const WORKSPACE_DIRECTORY = '.plugin';
3
- export const CONTENTS_DIRECTORY = path.join(WORKSPACE_DIRECTORY, 'contents');
2
+ export const WORKSPACE_DIRECTORY = '.k2';
4
3
  export const DEVELOPMENT_DIRECTORY = path.join(WORKSPACE_DIRECTORY, 'dev');
4
+ /** kintoneプラグインの一時ファイルを管理するフォルダ */
5
+ export const PLUGIN_WORKSPACE_DIRECTORY = '.plugin';
6
+ /** kintoneプラグインのcontents.zipに格納するファイルを管理するフォルダ */
7
+ export const PLUGIN_CONTENTS_DIRECTORY = path.join(PLUGIN_WORKSPACE_DIRECTORY, 'contents');
8
+ /** kintoneプラグインの開発時、ローカルサーバーに反映するファイルを管理するフォルダ */
9
+ export const PLUGIN_DEVELOPMENT_DIRECTORY = path.join(PLUGIN_WORKSPACE_DIRECTORY, 'dev');
10
+ /** ローカルサーバーのデフォルトポート番号 */
5
11
  export const DEFAULT_PORT = 32767;
@@ -25,9 +25,7 @@ export const getSassPlugin = () => {
25
25
  pluginName,
26
26
  errors: [
27
27
  {
28
- text: error instanceof Error
29
- ? error.message
30
- : JSON.stringify(error),
28
+ text: error instanceof Error ? error.message : JSON.stringify(error),
31
29
  pluginName,
32
30
  location: { file: args.path, namespace: pluginName },
33
31
  },
@@ -1,10 +1,12 @@
1
1
  import fs from 'fs-extra';
2
2
  import path from 'path';
3
- import { CONTENTS_DIRECTORY } from './constants.js';
3
+ import { PLUGIN_CONTENTS_DIRECTORY } from './constants.js';
4
4
  import htmlMinifier from 'html-minifier';
5
5
  export const copyPluginContents = async () => {
6
- await fs.copySync(path.join('src', 'contents'), path.join(CONTENTS_DIRECTORY), { overwrite: true });
7
- const html = await fs.readFile(path.join(CONTENTS_DIRECTORY, 'config.html'), 'utf8');
6
+ await fs.copySync(path.join('src', 'contents'), path.join(PLUGIN_CONTENTS_DIRECTORY), {
7
+ overwrite: true,
8
+ });
9
+ const html = await fs.readFile(path.join(PLUGIN_CONTENTS_DIRECTORY, 'config.html'), 'utf8');
8
10
  const minified = htmlMinifier.minify(html, {
9
11
  minifyCSS: true,
10
12
  collapseWhitespace: true,
@@ -15,5 +17,5 @@ export const copyPluginContents = async () => {
15
17
  removeTagWhitespace: true,
16
18
  useShortDoctype: true,
17
19
  });
18
- await fs.writeFile(path.join(CONTENTS_DIRECTORY, 'config.html'), minified);
20
+ await fs.writeFile(path.join(PLUGIN_CONTENTS_DIRECTORY, 'config.html'), minified);
19
21
  };
@@ -1,4 +1,4 @@
1
- import { CONTENTS_DIRECTORY } from './constants.js';
1
+ import { PLUGIN_CONTENTS_DIRECTORY } from './constants.js';
2
2
  import { importPluginConfig } from './import.js';
3
3
  import fs from 'fs-extra';
4
4
  import path from 'path';
@@ -19,7 +19,7 @@ function merge(src, dst) {
19
19
  export const outputManifest = async (env, options) => {
20
20
  const config = options?.config || (await importPluginConfig());
21
21
  const merged = merge(config.manifest.base, config.manifest[env] || {});
22
- await fs.mkdirs(CONTENTS_DIRECTORY);
23
- await fs.writeJson(path.join(CONTENTS_DIRECTORY, 'manifest.json'), merged);
22
+ await fs.mkdirs(PLUGIN_CONTENTS_DIRECTORY);
23
+ await fs.writeJson(path.join(PLUGIN_CONTENTS_DIRECTORY, 'manifest.json'), merged);
24
24
  return merged;
25
25
  };
package/dist/lib/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import { WORKSPACE_DIRECTORY } from './constants.js';
1
+ import { PLUGIN_WORKSPACE_DIRECTORY } from './constants.js';
2
2
  import { exec } from './exec.js';
3
3
  import { getZipFileNameSuffix } from './zip.js';
4
4
  import { config } from 'dotenv';
@@ -16,7 +16,7 @@ KINTONE_PASSWORD
16
16
  `);
17
17
  }
18
18
  const zipFileName = `plugin${getZipFileNameSuffix(env)}.zip`;
19
- let command = `kintone-plugin-uploader ${WORKSPACE_DIRECTORY}/${zipFileName} --base-url ${KINTONE_BASE_URL} --username ${KINTONE_USERNAME} --password ${KINTONE_PASSWORD}`;
19
+ let command = `kintone-plugin-uploader ${PLUGIN_WORKSPACE_DIRECTORY}/${zipFileName} --base-url ${KINTONE_BASE_URL} --username ${KINTONE_USERNAME} --password ${KINTONE_PASSWORD}`;
20
20
  if (KINTONE_BASIC_AUTH_USERNAME && KINTONE_BASIC_AUTH_PASSWORD) {
21
21
  command += ` --basic-auth-username ${KINTONE_BASIC_AUTH_USERNAME} --basic-auth-password ${KINTONE_BASIC_AUTH_PASSWORD}`;
22
22
  }
package/dist/lib/vite.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import path from 'path';
2
2
  import fs from 'fs-extra';
3
- import { DEFAULT_PORT, DEVELOPMENT_DIRECTORY, WORKSPACE_DIRECTORY, } from './constants.js';
3
+ import { DEFAULT_PORT, PLUGIN_DEVELOPMENT_DIRECTORY, PLUGIN_WORKSPACE_DIRECTORY, } from './constants.js';
4
4
  import tsconfigPaths from 'vite-tsconfig-paths';
5
5
  export const getViteConfig = (config) => {
6
6
  return {
7
7
  configFile: false,
8
8
  build: {
9
- outDir: DEVELOPMENT_DIRECTORY,
9
+ outDir: PLUGIN_DEVELOPMENT_DIRECTORY,
10
10
  emptyOutDir: true,
11
11
  rollupOptions: {
12
12
  input: {
@@ -30,8 +30,8 @@ export const getViteConfig = (config) => {
30
30
  server: {
31
31
  port: config.server?.port ?? DEFAULT_PORT,
32
32
  https: {
33
- key: fs.readFileSync(path.join(WORKSPACE_DIRECTORY, 'localhost-key.pem')),
34
- cert: fs.readFileSync(path.join(WORKSPACE_DIRECTORY, 'localhost-cert.pem')),
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
35
  },
36
36
  },
37
37
  resolve: {
@@ -0,0 +1,86 @@
1
+ import { existsSync, readdirSync } from 'fs';
2
+ import MiniCssExtractPlugin from 'mini-css-extract-plugin';
3
+ import path from 'path';
4
+ import { cwd } from 'process';
5
+ import TerserPlugin from 'terser-webpack-plugin';
6
+ import webpack from 'webpack';
7
+ import chalk from 'chalk';
8
+ import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
9
+ export const buildWithWebpack = async (props) => {
10
+ const { mode, srcRoot, distRoot } = props;
11
+ /** @type { Record<string, string> } */
12
+ let entry = {};
13
+ if (mode === 'app') {
14
+ const appsRoot = path.join(srcRoot, 'apps');
15
+ const allProjects = readdirSync(appsRoot);
16
+ entry = allProjects.reduce((acc, dir) => {
17
+ for (const filename of ['index.ts', 'index.js', 'index.mjs']) {
18
+ if (existsSync(path.join(appsRoot, dir, filename))) {
19
+ return { ...acc, [dir]: path.join(appsRoot, dir, filename) };
20
+ }
21
+ }
22
+ return acc;
23
+ }, {});
24
+ }
25
+ else {
26
+ entry = {
27
+ desktop: path.join(srcRoot, 'desktop', 'index.ts'),
28
+ config: path.join(srcRoot, 'config', 'index.ts'),
29
+ };
30
+ }
31
+ const exclude = /node_modules/;
32
+ const styleLoader = MiniCssExtractPlugin.loader;
33
+ return new Promise((resolve, reject) => {
34
+ webpack({
35
+ mode: 'production',
36
+ target: ['web', 'es2023'],
37
+ entry,
38
+ resolve: {
39
+ extensions: ['.ts', '.tsx', '.js', '.json'],
40
+ fallback: {
41
+ path: false,
42
+ },
43
+ plugins: [new TsconfigPathsPlugin({ configFile: path.join(cwd(), 'tsconfig.json') })],
44
+ },
45
+ cache: { type: 'filesystem' },
46
+ output: {
47
+ filename: '[name].js',
48
+ path: path.resolve(cwd(), ...distRoot.split(/[\\\/]/g)),
49
+ },
50
+ module: {
51
+ rules: [
52
+ { test: /\.tsx?$/, exclude, loader: 'ts-loader' },
53
+ { test: /\.css$/, use: [styleLoader, 'css-loader'] },
54
+ {
55
+ test: /\.scss$/,
56
+ use: [
57
+ styleLoader,
58
+ 'css-loader',
59
+ { loader: 'sass-loader', options: { sassOptions: { outputStyle: 'expanded' } } },
60
+ ],
61
+ },
62
+ ],
63
+ },
64
+ plugins: [new MiniCssExtractPlugin()],
65
+ optimization: {
66
+ minimize: true,
67
+ minimizer: [new TerserPlugin({ extractComments: false })],
68
+ },
69
+ }, (err, stats) => {
70
+ if (err) {
71
+ reject(err);
72
+ }
73
+ else {
74
+ if (stats?.compilation.errors.length) {
75
+ reject([
76
+ chalk.red('⚠ 本番用ビルドでエラーが発生しました'),
77
+ ...stats.compilation.errors.map((error) => error.message),
78
+ ].join('\n'));
79
+ }
80
+ else {
81
+ resolve();
82
+ }
83
+ }
84
+ });
85
+ });
86
+ };
package/dist/lib/zip.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import archiver from 'archiver';
2
2
  import fs from 'fs-extra';
3
3
  import path from 'path';
4
- import { CONTENTS_DIRECTORY, WORKSPACE_DIRECTORY } from './constants.js';
4
+ import { PLUGIN_CONTENTS_DIRECTORY, PLUGIN_WORKSPACE_DIRECTORY } from './constants.js';
5
5
  export const outputContentsZip = async (manifest) => {
6
6
  const archive = archiver('zip', { zlib: { level: 9 } });
7
- const outputZipPath = path.join(WORKSPACE_DIRECTORY, 'contents.zip');
7
+ const outputZipPath = path.join(PLUGIN_WORKSPACE_DIRECTORY, 'contents.zip');
8
8
  const outputZipStream = fs.createWriteStream(outputZipPath);
9
9
  const filterLocalContent = (file) => {
10
10
  return !/^https?:\/\//.test(file);
11
11
  };
12
- archive.file(path.join(CONTENTS_DIRECTORY, 'manifest.json'), {
12
+ archive.file(path.join(PLUGIN_CONTENTS_DIRECTORY, 'manifest.json'), {
13
13
  name: 'manifest.json',
14
14
  });
15
15
  if (!manifest.config) {
@@ -28,7 +28,7 @@ export const outputContentsZip = async (manifest) => {
28
28
  ]),
29
29
  ];
30
30
  targetFiles.forEach((file) => {
31
- const filePath = path.join(CONTENTS_DIRECTORY, file);
31
+ const filePath = path.join(PLUGIN_CONTENTS_DIRECTORY, file);
32
32
  if (!fs.existsSync(filePath)) {
33
33
  throw new Error(`${filePath} does not exist`);
34
34
  }
@@ -38,7 +38,7 @@ export const outputContentsZip = async (manifest) => {
38
38
  await archive.finalize();
39
39
  };
40
40
  export const getContentsZipBuffer = async () => {
41
- const outputZipPath = path.join(WORKSPACE_DIRECTORY, 'contents.zip');
41
+ const outputZipPath = path.join(PLUGIN_WORKSPACE_DIRECTORY, 'contents.zip');
42
42
  return fs.readFile(outputZipPath);
43
43
  };
44
44
  export const getZipFileNameSuffix = (env) => {
package/dist/plugin.js CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import { program } from 'commander';
3
- import build from './commands/build/index.js';
4
- import dev from './commands/dev/index.js';
5
- import genkey from './commands/genkey/index.js';
3
+ import build from './commands/plugin-build.js';
4
+ import dev from './commands/plugin-dev.js';
5
+ import genkey from './commands/plugin-genkey.js';
6
6
  import init from './commands/init/index.js';
7
7
  import manifest from './commands/manifest/index.js';
8
8
  import test from './commands/test/index.js';
9
9
  import upload from './commands/upload/index.js';
10
- import zip from './commands/zip/index.js';
10
+ import zip from './commands/plugin-zip.js';
11
11
  program.name('plugin').version('0.0.1').description('');
12
12
  build();
13
13
  dev();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konomi-app/k2",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "kintone sdk",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -30,14 +30,22 @@
30
30
  "chalk": "^5",
31
31
  "chokidar": "^3",
32
32
  "commander": "^12",
33
+ "css-loader": "^7.1.2",
33
34
  "dotenv": "^16",
34
35
  "esbuild": "^0.21",
35
36
  "express": "^4",
36
37
  "fs-extra": "^11",
37
38
  "html-minifier": "^4",
39
+ "mini-css-extract-plugin": "^2.9.0",
38
40
  "sass": "^1",
41
+ "sass-loader": "^14.2.1",
42
+ "style-loader": "^4.0.0",
43
+ "terser-webpack-plugin": "^5.3.10",
44
+ "ts-loader": "^9.5.1",
45
+ "tsconfig-paths-webpack-plugin": "^4.1.0",
39
46
  "vite": "^5",
40
- "vite-tsconfig-paths": "^4"
47
+ "vite-tsconfig-paths": "^4",
48
+ "webpack": "^5.91.0"
41
49
  },
42
50
  "devDependencies": {
43
51
  "@types/archiver": "*",
package/types/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  /// <reference path="plugin.d.ts" />
2
+ /// <reference path="k2.d.ts" />
package/types/k2.d.ts ADDED
@@ -0,0 +1,38 @@
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
+ declare namespace K2 {
26
+ type Env = 'dev' | 'prod' | 'standalone';
27
+
28
+ /**
29
+ * 公開しているプラグインテンプレートで使用する設定ファイル
30
+ */
31
+ type Config = Record<string, any> & {
32
+ version?: 1;
33
+ server?: {
34
+ /** 0から65535までのポート番号 */
35
+ port?: number;
36
+ };
37
+ };
38
+ }
@@ -1,25 +0,0 @@
1
- import { program } from 'commander';
2
- import { generateCert } from '../../lib/cert.js';
3
- import { WORKSPACE_DIRECTORY } from '../../lib/constants.js';
4
- export default function command() {
5
- program
6
- .command('genkey')
7
- .description('Generate SSL key for localhost. (Require mkcert)')
8
- .option('-o, --output <output>', 'Output directory.', WORKSPACE_DIRECTORY)
9
- .action(action);
10
- }
11
- export async function action(options) {
12
- const { output } = options;
13
- console.group('🔑 Generate SSL key for localhost');
14
- try {
15
- const { stdout } = await generateCert(output);
16
- console.log(stdout);
17
- console.log('key generation success.');
18
- }
19
- catch (error) {
20
- throw error;
21
- }
22
- finally {
23
- console.groupEnd();
24
- }
25
- }