@notegen/plugin-cli 0.1.0 → 0.1.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.
@@ -1,4 +1,4 @@
1
- import { PLUGIN_API_VERSION } from '@notegen/plugin-api';
1
+ import { PLUGIN_API_VERSION, isValidPluginMenuCondition } from '@notegen/plugin-api';
2
2
  import { compare as compareSemver, valid as validSemver } from 'semver';
3
3
  import { fail } from './diagnostics.js';
4
4
  import { hasControlCharacter, packagePathCollisionKey, utf8ByteLength, validatePackagePath, } from './path-rules.js';
@@ -311,7 +311,7 @@ function validateContributions(value, pluginId) {
311
311
  for (const [index, rawCommand] of commands.entries()) {
312
312
  const path = `$.contributes.commands[${index}]`;
313
313
  const command = objectValue(rawCommand, path);
314
- assertAllowedKeys(command, ['id', 'title', 'description', 'icon', 'suggestedShortcut'], path);
314
+ assertAllowedKeys(command, ['id', 'title', 'description', 'icon', 'suggestedShortcut', 'keywords'], path);
315
315
  const id = validateNamespacedId(required(command, 'id', path), pluginId, `${path}.id`);
316
316
  if (commandIds.has(id))
317
317
  fail('manifest.duplicate-command', `Command ${id} is declared more than once`, `${path}.id`);
@@ -370,30 +370,34 @@ function validateContributions(value, pluginId) {
370
370
  fail('manifest.unknown-command', `${path}.command is not declared`, `${path}.command`);
371
371
  }
372
372
  }
373
+ for (const raw of (contributes.commands ?? [])) {
374
+ const command = objectValue(raw, '$.contributes.commands');
375
+ if (command.keywords !== undefined && (!Array.isArray(command.keywords) || command.keywords.length > 20 || command.keywords.some(word => typeof word !== 'string' || word.length < 1 || word.length > 80)))
376
+ fail('manifest.invalid-keywords', 'Invalid command keywords', '$.contributes.commands');
377
+ }
373
378
  const menus = Object.hasOwn(contributes, 'menus')
374
379
  ? arrayValue(contributes.menus, '$.contributes.menus')
375
380
  : [];
376
381
  if (menus.length > 100)
377
382
  fail('manifest.too-many-contributions', 'A plugin may declare at most 100 menu items', '$.contributes.menus');
378
- const menuLocations = new Set(['editor/slash', 'editor/context', 'file/context', 'mobile/writing/overflow']);
383
+ const menuLocations = new Set(['editor/slash', 'editor/context', 'editor/selection', 'editor/toolbar', 'tab/context', 'file/context', 'mobile/writing/overflow']);
379
384
  for (const [index, rawMenu] of menus.entries()) {
380
385
  const path = `$.contributes.menus[${index}]`;
381
386
  const menu = objectValue(rawMenu, path);
382
- assertAllowedKeys(menu, ['location', 'command', 'when', 'group'], path);
387
+ assertAllowedKeys(menu, ['location', 'command', 'when', 'group', 'order', 'icon', 'enableWhen'], path);
383
388
  const location = stringValue(required(menu, 'location', path), `${path}.location`);
384
389
  const command = stringValue(required(menu, 'command', path), `${path}.command`);
385
390
  if (!menuLocations.has(location) || !commandIds.has(command)) {
386
391
  fail('manifest.invalid-menu', `${path} must use a supported location and declared command`, path);
387
392
  }
388
- if (Object.hasOwn(menu, 'when')) {
389
- const condition = stringValue(menu.when, `${path}.when`);
390
- const afterEditor = condition.startsWith('editor') ? condition.slice('editor'.length).trimStart() : '';
391
- const supported = utf8ByteLength(condition) <= 240
392
- && afterEditor.startsWith('==')
393
- && afterEditor.slice(2).trimStart() === 'markdown';
394
- if (!supported)
395
- fail('manifest.invalid-menu-condition', `${path}.when is unsupported`, `${path}.when`);
393
+ for (const key of ['when', 'enableWhen']) {
394
+ if (Object.hasOwn(menu, key) && !isValidPluginMenuCondition(stringValue(menu[key], `${path}.${key}`)))
395
+ fail('manifest.invalid-menu-condition', `${path}.${key} is unsupported`, `${path}.${key}`);
396
396
  }
397
+ if (menu.order !== undefined && (typeof menu.order !== 'number' || !Number.isInteger(menu.order) || Math.abs(menu.order) > 10000))
398
+ fail('manifest.invalid-menu-order', 'Invalid menu order', path);
399
+ if (menu.icon !== undefined && (typeof menu.icon !== 'string' || !ICON_PATTERN.test(menu.icon) || menu.icon.length > 80))
400
+ fail('manifest.invalid-menu-icon', 'Invalid menu icon', path);
397
401
  if (Object.hasOwn(menu, 'group')) {
398
402
  const group = stringValue(menu.group, `${path}.group`);
399
403
  if (group.length === 0 || utf8ByteLength(group) > 80 || hasControlCharacter(group)) {
@@ -36,7 +36,7 @@ function templateFiles(options) {
36
36
  name: options.name,
37
37
  description: options.description ?? 'Show statistics for the active NoteGen editor.',
38
38
  version: '0.1.0',
39
- apiVersion: options.apiVersion ?? '^0.1.0',
39
+ apiVersion: options.apiVersion ?? '^0.1.1',
40
40
  minAppVersion: options.minAppVersion ?? '0.37.0',
41
41
  platforms: ['desktop'],
42
42
  entry: 'dist/main.js',
@@ -58,7 +58,7 @@ function templateFiles(options) {
58
58
  name: options.name,
59
59
  description: options.description ?? 'A NoteGen command plugin.',
60
60
  version: '0.1.0',
61
- apiVersion: options.apiVersion ?? '^0.1.0',
61
+ apiVersion: options.apiVersion ?? '^0.1.1',
62
62
  minAppVersion: options.minAppVersion ?? '0.37.0',
63
63
  platforms: ['desktop'],
64
64
  entry: 'dist/main.js',
@@ -90,8 +90,8 @@ function templateFiles(options) {
90
90
  scripts,
91
91
  notegen: { source: 'src/main.ts' },
92
92
  devDependencies: {
93
- '@notegen/plugin-api': '^0.1.0',
94
- '@notegen/plugin-cli': '^0.1.0',
93
+ '@notegen/plugin-api': '^0.1.1',
94
+ '@notegen/plugin-cli': '^0.1.1',
95
95
  typescript: '^5.8.3',
96
96
  },
97
97
  packageManager: packageManager === 'pnpm' ? 'pnpm@10.20.0' : undefined,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notegen/plugin-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Create, validate, build, package, sign, and verify NoteGen plugins.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -45,7 +45,7 @@
45
45
  "semver": "^7.8.5",
46
46
  "yauzl": "^3.4.0",
47
47
  "yazl": "^3.3.1",
48
- "@notegen/plugin-api": "^0.1.0"
48
+ "@notegen/plugin-api": "^0.1.1"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "^20.19.43",