@konomi-app/k2 0.6.0 → 0.7.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.
@@ -21,22 +21,7 @@ export async function action(options) {
21
21
  const port = config.server?.port ?? DEFAULT_PORT;
22
22
  const manifest = await getManifest({ config, port });
23
23
  console.log(`📝 manifest.json generated`);
24
- Promise.all([
25
- watchContentsAndUploadZip({ manifest, ppkPath }),
26
- watchCss(config),
27
- async () => {
28
- const entryPoints = ['desktop', 'config'].map((dir) => ({
29
- in: path.join('src', dir, 'index.ts'),
30
- out: dir,
31
- }));
32
- base({
33
- port,
34
- entryPoints,
35
- certDir: PLUGIN_WORKSPACE_DIRECTORY,
36
- staticDir: PLUGIN_DEVELOPMENT_DIRECTORY,
37
- });
38
- },
39
- ]);
24
+ Promise.all([watchContentsAndUploadZip({ manifest, ppkPath }), watchCss(config), build(port)]);
40
25
  }
41
26
  catch (error) {
42
27
  throw error;
@@ -45,3 +30,15 @@ export async function action(options) {
45
30
  console.groupEnd();
46
31
  }
47
32
  }
33
+ async function build(port) {
34
+ const entryPoints = ['desktop', 'config'].map((dir) => ({
35
+ in: path.join('src', dir, 'index.ts'),
36
+ out: dir,
37
+ }));
38
+ base({
39
+ port,
40
+ entryPoints,
41
+ certDir: PLUGIN_WORKSPACE_DIRECTORY,
42
+ staticDir: PLUGIN_DEVELOPMENT_DIRECTORY,
43
+ });
44
+ }
@@ -5,14 +5,26 @@ import tailwindcss from 'tailwindcss';
5
5
  import { PLUGIN_DEVELOPMENT_DIRECTORY } from '../../lib/constants.js';
6
6
  import { esmImport } from '../../lib/import.js';
7
7
  import chokidar from 'chokidar';
8
+ import chalk from 'chalk';
8
9
  async function buildTailwindCSS(params) {
9
10
  const { inputFile, outputFileName, config } = params;
10
11
  const inputPath = path.resolve(inputFile);
11
12
  const outputPath = path.join(PLUGIN_DEVELOPMENT_DIRECTORY, outputFileName);
12
13
  const css = await fs.readFile(inputPath, 'utf8');
13
- const watcher = chokidar.watch(config.content ?? ['./src/**/*.{ts,tsx}'], { ignored: /node_modules/, persistent: true });
14
- const listener = async () => {
14
+ const watcher = chokidar.watch([...(config.content ?? ['./src/**/*.{ts,tsx}']), inputPath], {
15
+ ignored: /node_modules/,
16
+ persistent: true,
17
+ awaitWriteFinish: {
18
+ stabilityThreshold: 2000,
19
+ pollInterval: 100,
20
+ },
21
+ });
22
+ let initialScanComplete = false;
23
+ const listener = async (type, path) => {
15
24
  try {
25
+ if (type === 'add' && !initialScanComplete) {
26
+ return;
27
+ }
16
28
  const result = await postcss([tailwindcss(config)]).process(css, {
17
29
  from: inputPath,
18
30
  to: outputPath,
@@ -21,16 +33,22 @@ async function buildTailwindCSS(params) {
21
33
  if (result.map) {
22
34
  await fs.writeFile(`${outputPath}.map`, result.map.toString());
23
35
  }
24
- console.log(`🎨 Successfully built Tailwind CSS to ${outputPath}`);
36
+ console.log(chalk.hex('#e5e7eb')(`${new Date().toLocaleTimeString()} `) +
37
+ chalk.cyan(`[css] `) +
38
+ outputFileName +
39
+ (type === 'init' ? ' init' : ` rebuilt`));
25
40
  }
26
41
  catch (error) {
27
42
  console.error('Error building Tailwind CSS:', error);
28
43
  }
29
44
  };
30
- await listener();
31
- watcher.on('change', listener);
32
- watcher.on('add', listener);
33
- watcher.on('unlink', listener);
45
+ await listener('init');
46
+ watcher.on('ready', () => {
47
+ initialScanComplete = true;
48
+ });
49
+ watcher.on('change', (path) => listener('change', path));
50
+ watcher.on('add', (path) => listener('add', path));
51
+ watcher.on('unlink', () => listener('unlink'));
34
52
  }
35
53
  export const watchCss = async (pluginConfig) => {
36
54
  if (!pluginConfig.tailwind?.css || !pluginConfig.tailwind?.config) {
@@ -39,8 +57,8 @@ export const watchCss = async (pluginConfig) => {
39
57
  const { css, config: configPath } = pluginConfig.tailwind;
40
58
  const configPathForDesktop = typeof configPath === 'string' ? configPath : configPath.desktop;
41
59
  const configPathForConfig = typeof configPath === 'string' ? configPath : configPath.config;
42
- const desktopConfig = await esmImport(path.resolve(configPathForDesktop));
43
- const configConfig = await esmImport(path.resolve(configPathForConfig));
60
+ const desktopConfig = (await esmImport(path.resolve(configPathForDesktop))).default;
61
+ const configConfig = (await esmImport(path.resolve(configPathForConfig))).default;
44
62
  const inputFile = path.resolve(css);
45
63
  return Promise.all([
46
64
  buildTailwindCSS({ inputFile, outputFileName: 'desktop.css', config: desktopConfig }),
@@ -6,15 +6,23 @@ import path from 'path';
6
6
  import { PLUGIN_WORKSPACE_DIRECTORY } from '../../lib/constants.js';
7
7
  import { uploadZip } from '../../lib/utils.js';
8
8
  import chokider from 'chokidar';
9
+ import chalk from 'chalk';
9
10
  export const watchContentsAndUploadZip = async (params) => {
10
11
  const { manifest, ppkPath } = params;
12
+ let initialScanComplete = false;
11
13
  const contentsListener = async () => {
12
14
  try {
15
+ if (!initialScanComplete) {
16
+ return;
17
+ }
13
18
  await copyPluginContents();
14
- console.log('📁 contents updated');
19
+ console.log(chalk.hex('#e5e7eb')(`${new Date().toLocaleTimeString()} `) +
20
+ chalk.cyan(`[contents] `) +
21
+ `updated`);
15
22
  }
16
23
  catch (error) {
17
- console.error('📁 contents update failed');
24
+ console.error('Error copying plugin contents:', error);
25
+ return;
18
26
  }
19
27
  await outputContentsZip(manifest);
20
28
  const buffer = await getContentsZipBuffer();
@@ -22,15 +30,20 @@ export const watchContentsAndUploadZip = async (params) => {
22
30
  const output = await packer(buffer, pluginPrivateKey);
23
31
  const zipFileName = `plugin${getZipFileNameSuffix('dev')}.zip`;
24
32
  await fs.writeFile(path.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName), output.plugin);
25
- console.log(`📤 uploading ${zipFileName} to your kintone`);
33
+ console.log(chalk.hex('#e5e7eb')(`${new Date().toLocaleTimeString()} `) +
34
+ chalk.cyan(`[upload] `) +
35
+ `start uploading`);
26
36
  await uploadZip('dev');
27
- console.log('📤 Plugin uploaded');
37
+ console.log(chalk.hex('#e5e7eb')(`${new Date().toLocaleTimeString()} `) + chalk.cyan(`[upload] `) + `done`);
28
38
  };
29
- await contentsListener();
30
39
  const contentsWatcher = chokider.watch(['src/contents/**/*'], {
31
40
  ignored: /node_modules/,
32
41
  persistent: true,
33
42
  });
43
+ contentsWatcher.on('ready', () => {
44
+ initialScanComplete = true;
45
+ contentsListener();
46
+ });
34
47
  contentsWatcher.on('change', contentsListener);
35
48
  contentsWatcher.on('add', contentsListener);
36
49
  contentsWatcher.on('unlink', contentsListener);
@@ -43,9 +43,9 @@ export const getEsbuildContext = async (params) => {
43
43
  plugins: [
44
44
  {
45
45
  name: 'on-end',
46
- setup: ({ onEnd }) => onEnd(() => console.log(chalk.hex('#d1d5db')(`${new Date().toLocaleTimeString()} `) +
47
- chalk.cyan(`[content] `) +
48
- `Compiled successfully.`)),
46
+ setup: ({ onEnd }) => onEnd(() => console.log(chalk.hex('#e5e7eb')(`${new Date().toLocaleTimeString()} `) +
47
+ chalk.cyan(`[js] `) +
48
+ `rebuilt`)),
49
49
  },
50
50
  getSassPlugin(),
51
51
  ],
package/dist/plugin.js CHANGED
@@ -8,7 +8,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
10
  import zip from './commands/plugin-zip.js';
11
- program.name('plugin').version('0.0.1').description('');
11
+ program.name('plugin').version('0.7.0').description('');
12
12
  build();
13
13
  dev();
14
14
  genkey();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konomi-app/k2",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "kintone sdk",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -56,4 +56,4 @@
56
56
  "@types/html-minifier": "^4",
57
57
  "typescript": "*"
58
58
  }
59
- }
59
+ }