@konomi-app/k2 1.2.0 → 1.3.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.
@@ -3,18 +3,23 @@ import fs from 'fs-extra';
3
3
  import path from 'path';
4
4
  import { WORKSPACE_DIRECTORY } from '../lib/constants.js';
5
5
  import { buildWithEsbuild } from '../lib/esbuild.js';
6
+ import { importK2Config } from '../lib/import.js';
7
+ import { getDefaultK2Config } from '../lib/k2.js';
8
+ import { buildTailwind } from './build-tailwind.js';
6
9
  export default function command() {
7
10
  program
8
11
  .command('esbuild-build')
9
12
  .option('-o, --outdir <outdir>', 'Output directory.', path.join(WORKSPACE_DIRECTORY, 'prod'))
10
13
  .option('-i, --input <input>', 'Input directory.', path.join('src', 'apps'))
14
+ .option('--config <config>', 'k2 config file path')
11
15
  .description("Build the project for production. (It's a wrapper of webpack build command.)")
12
16
  .action(action);
13
17
  }
14
18
  export async function action(options) {
15
19
  console.group('🍳 Build the project for production');
16
20
  try {
17
- const { outdir, input } = options;
21
+ const { outdir, input, config } = options;
22
+ const outDir = path.resolve(outdir);
18
23
  const allProjects = fs.readdirSync(path.resolve(input));
19
24
  const entryPoints = allProjects.reduce((acc, dir) => {
20
25
  for (const filename of ['index.ts', 'index.js', 'index.mjs']) {
@@ -25,13 +30,18 @@ export async function action(options) {
25
30
  return acc;
26
31
  }, {});
27
32
  console.log(`📁 ${Object.keys(entryPoints).length} entry points`);
28
- await buildWithEsbuild({
29
- entryPoints,
30
- outdir,
31
- sourcemap: false,
32
- minify: true,
33
- target: 'es2020',
34
- });
33
+ const k2Config = config ? await importK2Config(config) : getDefaultK2Config();
34
+ const fullConfig = { ...k2Config, outDir };
35
+ await Promise.allSettled([
36
+ buildWithEsbuild({
37
+ entryPoints,
38
+ outdir,
39
+ sourcemap: false,
40
+ minify: true,
41
+ legalComments: 'none',
42
+ }),
43
+ buildTailwind(fullConfig),
44
+ ]);
35
45
  console.log('✨ Build success.');
36
46
  }
37
47
  catch (error) {
@@ -5,6 +5,7 @@ import { PLUGIN_CONTENTS_DIRECTORY } from '../lib/constants.js';
5
5
  import { importPluginConfig } from '../lib/import.js';
6
6
  import { getTailwindConfig, outputCss } from '../lib/tailwind.js';
7
7
  import { buildWithEsbuild } from '../lib/esbuild.js';
8
+ import { lint } from '../lib/lint.js';
8
9
  export default function command() {
9
10
  program
10
11
  .command('esbuild')
@@ -15,13 +16,13 @@ export async function action() {
15
16
  console.group('🍳 Build the project for production');
16
17
  try {
17
18
  const config = await importPluginConfig();
19
+ if (config?.lint?.build) {
20
+ await lint();
21
+ console.log('✨ Lint success.');
22
+ }
18
23
  if (!fs.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
19
24
  await fs.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
20
25
  }
21
- const entries = {
22
- desktop: path.join('src', 'desktop', 'index.ts'),
23
- config: path.join('src', 'config', 'index.ts'),
24
- };
25
26
  if (config.tailwind?.css && config.tailwind?.config) {
26
27
  const tailwindConfig = await getTailwindConfig(config.tailwind);
27
28
  const inputFile = path.resolve(config.tailwind.css);
@@ -30,12 +31,14 @@ export async function action() {
30
31
  inputPath,
31
32
  outputPath: path.join(PLUGIN_CONTENTS_DIRECTORY, 'config.css'),
32
33
  config: tailwindConfig.config,
34
+ minify: true,
33
35
  });
34
36
  console.log('✨ Built config.css');
35
37
  await outputCss({
36
38
  inputPath,
37
39
  outputPath: path.join(PLUGIN_CONTENTS_DIRECTORY, 'desktop.css'),
38
- config: tailwindConfig.config,
40
+ config: tailwindConfig.desktop,
41
+ minify: true,
39
42
  });
40
43
  console.log('✨ Built desktop.css');
41
44
  }
@@ -48,6 +51,7 @@ export async function action() {
48
51
  outdir: PLUGIN_CONTENTS_DIRECTORY,
49
52
  minify: true,
50
53
  sourcemap: false,
54
+ legalComments: 'none',
51
55
  });
52
56
  console.log('✨ Built desktop.js and config.js');
53
57
  console.log('✨ Build success.');
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import viteDev from './commands/dev-vite.js';
7
7
  import genkey from './commands/genkey.js';
8
8
  import esbuildBuild from './commands/build-esbuild.js';
9
9
  import lint from './commands/lint.js';
10
- program.name('k2').version('0.9.0').description('k2 - 🍳 kintone kitchen 🍳');
10
+ program.name('k2').version('1.3.1').description('k2 - 🍳 kintone kitchen 🍳');
11
11
  build();
12
12
  viteBuild();
13
13
  esbuildBuild();
package/dist/lib/zip.js CHANGED
@@ -5,8 +5,22 @@ import invariant from 'tiny-invariant';
5
5
  import { PLUGIN_CONTENTS_DIRECTORY, PLUGIN_WORKSPACE_DIRECTORY } from './constants.js';
6
6
  export const outputContentsZip = async (manifest) => {
7
7
  const archive = archiver('zip', { zlib: { level: 9 } });
8
+ archive.on('warning', (error) => {
9
+ if (error.code === 'ENOENT') {
10
+ console.warn(error);
11
+ }
12
+ else {
13
+ throw error;
14
+ }
15
+ });
8
16
  const outputZipPath = path.join(PLUGIN_WORKSPACE_DIRECTORY, 'contents.zip');
9
17
  const outputZipStream = fs.createWriteStream(outputZipPath);
18
+ outputZipStream.on('close', () => {
19
+ console.log(`📦 ${archive.pointer()} total bytes`);
20
+ });
21
+ outputZipStream.on('end', function () {
22
+ console.log('📦 Data has been drained');
23
+ });
10
24
  const filterLocalContent = (file) => {
11
25
  return !/^https?:\/\//.test(file);
12
26
  };
@@ -24,17 +38,22 @@ export const outputContentsZip = async (manifest) => {
24
38
  ...(manifest.config.css || []).filter(filterLocalContent),
25
39
  ]),
26
40
  ];
27
- console.log('📁 Target files');
28
- console.dir(targetFiles);
29
- targetFiles.forEach((file) => {
41
+ console.group('📁 Target files');
42
+ targetFiles.forEach((file, i) => {
43
+ const prefix = i === targetFiles.length - 1 ? '└─' : '├─';
44
+ console.log(`${prefix} 📄 ${file}`);
45
+ });
46
+ console.groupEnd();
47
+ for (const file of targetFiles) {
30
48
  const filePath = path.join(PLUGIN_CONTENTS_DIRECTORY, file);
31
49
  if (!fs.existsSync(filePath)) {
32
50
  throw new Error(`${filePath} does not exist`);
33
51
  }
34
52
  archive.file(filePath, { name: file });
35
- });
53
+ }
36
54
  archive.pipe(outputZipStream);
37
55
  await archive.finalize();
56
+ await new Promise((resolve) => outputZipStream.on('close', resolve));
38
57
  };
39
58
  export const getContentsZipBuffer = async () => {
40
59
  const outputZipPath = path.join(PLUGIN_WORKSPACE_DIRECTORY, 'contents.zip');
package/dist/plugin.js CHANGED
@@ -10,7 +10,7 @@ import test from './commands/test/index.js';
10
10
  import upload from './commands/upload/index.js';
11
11
  import zip from './commands/plugin-zip.js';
12
12
  import lint from './commands/lint.js';
13
- program.name('plugin').version('0.9.0').description('🍳 kintone kitchen 🍳 for kintone plugin');
13
+ program.name('plugin').version('1.3.1').description('🍳 kintone kitchen 🍳 for kintone plugin');
14
14
  build();
15
15
  esbuild();
16
16
  dev();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konomi-app/k2",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "kintone sdk",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",