@grafana/create-plugin 2.11.2 → 2.12.0-canary.658.dabaee1.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.
Files changed (62) hide show
  1. package/dist/bin/run.js +13 -18
  2. package/dist/commands/generate/prettify-files.js +15 -70
  3. package/dist/commands/generate/print-success-message.js +28 -31
  4. package/dist/commands/generate/prompt-user.js +23 -91
  5. package/dist/commands/generate/update-go-sdk-and-packages.js +36 -105
  6. package/dist/commands/generate.command.js +122 -240
  7. package/dist/commands/index.js +5 -21
  8. package/dist/commands/migrate.command.js +71 -134
  9. package/dist/commands/provisioning.command.js +30 -85
  10. package/dist/commands/types.js +1 -2
  11. package/dist/commands/update.command.js +44 -97
  12. package/dist/commands/version.command.js +16 -57
  13. package/dist/constants.js +37 -32
  14. package/dist/utils/tests/utils.files.test.js +21 -23
  15. package/dist/utils/tests/utils.handlebars.test.js +24 -26
  16. package/dist/utils/tests/utils.npm.test.js +103 -95
  17. package/dist/utils/tests/utils.plugin.test.js +11 -13
  18. package/dist/utils/tests/utils.templates.test.js +16 -18
  19. package/dist/utils/utils.config.js +30 -32
  20. package/dist/utils/utils.console.js +25 -31
  21. package/dist/utils/utils.files.js +38 -104
  22. package/dist/utils/utils.handlebars.js +30 -65
  23. package/dist/utils/utils.npm.js +75 -118
  24. package/dist/utils/utils.os.js +3 -7
  25. package/dist/utils/utils.packageManager.js +31 -37
  26. package/dist/utils/utils.packagejson.js +13 -22
  27. package/dist/utils/utils.path.js +7 -14
  28. package/dist/utils/utils.plugin.js +6 -13
  29. package/dist/utils/utils.templates.js +58 -80
  30. package/dist/utils/utils.version.js +9 -11
  31. package/package.json +20 -6
  32. package/src/bin/run.ts +2 -2
  33. package/src/commands/generate/prettify-files.ts +1 -1
  34. package/src/commands/generate/print-success-message.ts +4 -4
  35. package/src/commands/generate/prompt-user.ts +2 -2
  36. package/src/commands/generate/update-go-sdk-and-packages.ts +2 -2
  37. package/src/commands/generate.command.ts +15 -15
  38. package/src/commands/index.ts +5 -5
  39. package/src/commands/migrate.command.ts +6 -6
  40. package/src/commands/provisioning.command.ts +6 -6
  41. package/src/commands/types.ts +1 -1
  42. package/src/commands/update.command.ts +5 -5
  43. package/src/commands/version.command.ts +5 -2
  44. package/src/constants.ts +4 -1
  45. package/src/utils/tests/utils.files.test.ts +2 -2
  46. package/src/utils/tests/utils.handlebars.test.ts +2 -2
  47. package/src/utils/tests/utils.npm.test.ts +43 -34
  48. package/src/utils/tests/utils.plugin.test.ts +2 -2
  49. package/src/utils/tests/utils.templates.test.ts +2 -2
  50. package/src/utils/utils.config.ts +3 -3
  51. package/src/utils/utils.console.ts +16 -11
  52. package/src/utils/utils.files.ts +3 -3
  53. package/src/utils/utils.handlebars.ts +3 -3
  54. package/src/utils/utils.npm.ts +3 -3
  55. package/src/utils/utils.packageManager.ts +3 -3
  56. package/src/utils/utils.packagejson.ts +5 -5
  57. package/src/utils/utils.path.ts +3 -3
  58. package/src/utils/utils.plugin.ts +2 -3
  59. package/src/utils/utils.templates.ts +10 -10
  60. package/src/utils/utils.version.ts +5 -2
  61. package/tsconfig.json +5 -0
  62. package/vitest.config.ts +10 -0
@@ -1,18 +1,27 @@
1
+ import { vi } from 'vitest';
1
2
  import {
2
3
  updateNpmDependencies,
3
4
  getUpdatableNpmDependencies,
4
5
  hasNpmDependenciesToUpdate,
5
6
  getPackageJsonUpdatesAsText,
6
7
  updatePackageJson,
7
- } from '../utils.npm';
8
-
9
- import { getPackageJson, getLatestPackageJson, writePackageJson } from '../utils.packagejson';
10
-
11
- jest.mock('../utils.packagejson.ts');
8
+ } from '../utils.npm.js';
9
+
10
+ const mocks = vi.hoisted(() => {
11
+ return {
12
+ getPackageJson: vi.fn(),
13
+ getLatestPackageJson: vi.fn(),
14
+ writePackageJson: vi.fn(),
15
+ };
16
+ });
12
17
 
13
- const getPackageJsonMock = getPackageJson as jest.Mock;
14
- const getLatestPackageJsonMock = getLatestPackageJson as jest.Mock;
15
- const writePackageJsonMock = writePackageJson as jest.Mock;
18
+ vi.mock('../utils.packagejson.js', async () => {
19
+ return {
20
+ getPackageJson: mocks.getPackageJson,
21
+ getLatestPackageJson: mocks.getLatestPackageJson,
22
+ writePackageJson: mocks.writePackageJson,
23
+ };
24
+ });
16
25
 
17
26
  describe('Utils / NPM', () => {
18
27
  describe('getUpdatableNpmDependencies()', () => {
@@ -220,8 +229,8 @@ describe('Utils / NPM', () => {
220
229
  };
221
230
 
222
231
  // same package.json for existing and latest
223
- getPackageJsonMock.mockReturnValue(packageJson);
224
- getLatestPackageJsonMock.mockReturnValue(packageJson);
232
+ mocks.getPackageJson.mockReturnValue(packageJson);
233
+ mocks.getLatestPackageJson.mockReturnValue(packageJson);
225
234
 
226
235
  const result = hasNpmDependenciesToUpdate();
227
236
  expect(result).toBe(false);
@@ -252,8 +261,8 @@ describe('Utils / NPM', () => {
252
261
  scripts: {},
253
262
  };
254
263
 
255
- getPackageJsonMock.mockReturnValue(packageJson);
256
- getLatestPackageJsonMock.mockReturnValue(latestPackageJson);
264
+ mocks.getPackageJson.mockReturnValue(packageJson);
265
+ mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
257
266
 
258
267
  const result = hasNpmDependenciesToUpdate();
259
268
  expect(result).toBe(true);
@@ -285,8 +294,8 @@ describe('Utils / NPM', () => {
285
294
  scripts: {},
286
295
  };
287
296
 
288
- getPackageJsonMock.mockReturnValue(packageJson);
289
- getLatestPackageJsonMock.mockReturnValue(latestPackageJson);
297
+ mocks.getPackageJson.mockReturnValue(packageJson);
298
+ mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
290
299
 
291
300
  const result = hasNpmDependenciesToUpdate({ devOnly: true });
292
301
  expect(result).toBe(false);
@@ -307,8 +316,8 @@ describe('Utils / NPM', () => {
307
316
  scripts: {},
308
317
  };
309
318
 
310
- getPackageJsonMock.mockReturnValue(packageJson);
311
- getLatestPackageJsonMock.mockReturnValue(packageJson);
319
+ mocks.getPackageJson.mockReturnValue(packageJson);
320
+ mocks.getLatestPackageJson.mockReturnValue(packageJson);
312
321
 
313
322
  const result = getPackageJsonUpdatesAsText();
314
323
  expect(result).toBe('');
@@ -339,8 +348,8 @@ describe('Utils / NPM', () => {
339
348
  scripts: {},
340
349
  };
341
350
 
342
- getPackageJsonMock.mockReturnValue(packageJson);
343
- getLatestPackageJsonMock.mockReturnValue(latestPackageJson);
351
+ mocks.getPackageJson.mockReturnValue(packageJson);
352
+ mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
344
353
 
345
354
  const result = getPackageJsonUpdatesAsText();
346
355
  expect(result).toContain('sass');
@@ -372,8 +381,8 @@ describe('Utils / NPM', () => {
372
381
  scripts: {},
373
382
  };
374
383
 
375
- getPackageJsonMock.mockReturnValue(packageJson);
376
- getLatestPackageJsonMock.mockReturnValue(latestPackageJson);
384
+ mocks.getPackageJson.mockReturnValue(packageJson);
385
+ mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
377
386
 
378
387
  const result = getPackageJsonUpdatesAsText({ devOnly: true });
379
388
  expect(result).toBe('');
@@ -404,8 +413,8 @@ describe('Utils / NPM', () => {
404
413
  scripts: {},
405
414
  };
406
415
 
407
- getPackageJsonMock.mockReturnValue(packageJson);
408
- getLatestPackageJsonMock.mockReturnValue(latestPackageJson);
416
+ mocks.getPackageJson.mockReturnValue(packageJson);
417
+ mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
409
418
 
410
419
  const result = getPackageJsonUpdatesAsText({ devOnly: true });
411
420
  expect(result).toContain('sass');
@@ -426,12 +435,12 @@ describe('Utils / NPM', () => {
426
435
  scripts: {},
427
436
  };
428
437
 
429
- getPackageJsonMock.mockReturnValue(packageJson);
430
- getLatestPackageJsonMock.mockReturnValue(packageJson);
438
+ mocks.getPackageJson.mockReturnValue(packageJson);
439
+ mocks.getLatestPackageJson.mockReturnValue(packageJson);
431
440
 
432
441
  updatePackageJson();
433
442
  //should have the same original content
434
- expect(writePackageJsonMock).toHaveBeenCalledWith({
443
+ expect(mocks.writePackageJson).toHaveBeenCalledWith({
435
444
  dependencies: {
436
445
  '@grafana/ui': '10.0.0',
437
446
  react: '18.2.0',
@@ -469,12 +478,12 @@ describe('Utils / NPM', () => {
469
478
  scripts: {},
470
479
  };
471
480
 
472
- getPackageJsonMock.mockReturnValue(packageJson);
473
- getLatestPackageJsonMock.mockReturnValue(latestPackageJson);
481
+ mocks.getPackageJson.mockReturnValue(packageJson);
482
+ mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
474
483
 
475
484
  updatePackageJson();
476
485
  //should have the combined content
477
- expect(writePackageJsonMock).toHaveBeenCalledWith({
486
+ expect(mocks.writePackageJson).toHaveBeenCalledWith({
478
487
  dependencies: {
479
488
  '@grafana/ui': '10.0.0',
480
489
  react: '18.2.1', //changed
@@ -512,12 +521,12 @@ describe('Utils / NPM', () => {
512
521
  scripts: {},
513
522
  };
514
523
 
515
- getPackageJsonMock.mockReturnValue(packageJson);
516
- getLatestPackageJsonMock.mockReturnValue(latestPackageJson);
524
+ mocks.getPackageJson.mockReturnValue(packageJson);
525
+ mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
517
526
 
518
527
  updatePackageJson({ devOnly: true });
519
528
  //should have the combined content
520
- expect(writePackageJsonMock).toHaveBeenCalledWith({
529
+ expect(mocks.writePackageJson).toHaveBeenCalledWith({
521
530
  dependencies: {
522
531
  '@grafana/ui': '10.0.0',
523
532
  react: '18.2.0',
@@ -555,12 +564,12 @@ describe('Utils / NPM', () => {
555
564
  scripts: {},
556
565
  };
557
566
 
558
- getPackageJsonMock.mockReturnValue(packageJson);
559
- getLatestPackageJsonMock.mockReturnValue(latestPackageJson);
567
+ mocks.getPackageJson.mockReturnValue(packageJson);
568
+ mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
560
569
 
561
570
  updatePackageJson({ devOnly: true });
562
571
  //should have the combined content
563
- expect(writePackageJsonMock).toHaveBeenCalledWith({
572
+ expect(mocks.writePackageJson).toHaveBeenCalledWith({
564
573
  dependencies: {
565
574
  '@grafana/ui': '10.0.0',
566
575
  react: '18.2.0', //changed but devOnly so should not be changed in the file
@@ -1,5 +1,5 @@
1
- import { FIXTURES_PATH, TEMPLATE_PATHS } from '../../constants';
2
- import { getPluginJson } from '../utils.plugin';
1
+ import { FIXTURES_PATH, TEMPLATE_PATHS } from '../../constants.js';
2
+ import { getPluginJson } from '../utils.plugin.js';
3
3
 
4
4
  describe('Utils / Plugins', () => {
5
5
  describe('getPluginJson()', () => {
@@ -1,5 +1,5 @@
1
- import { PLUGIN_TYPES } from '../../constants';
2
- import { getTemplateFiles } from '../utils.templates';
1
+ import { PLUGIN_TYPES } from '../../constants.js';
2
+ import { getTemplateFiles } from '../utils.templates.js';
3
3
 
4
4
  describe('Utils / Templates', () => {
5
5
  describe('getTemplateFiles()', () => {
@@ -1,6 +1,6 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { getVersion } from './utils.version';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { getVersion } from './utils.version.js';
4
4
 
5
5
  type FeatureFlags = {
6
6
  bundleGrafanaUI: boolean;
@@ -1,7 +1,9 @@
1
- const { marked } = require('marked');
2
- const chalk = require('chalk');
3
- const TerminalRenderer = require('marked-terminal');
4
- const { Confirm, Select } = require('enquirer');
1
+ import { marked } from 'marked';
2
+ import chalk from 'chalk';
3
+ import TerminalRenderer from 'marked-terminal';
4
+ import Enquirer from 'enquirer';
5
+
6
+ const { prompt } = Enquirer;
5
7
 
6
8
  marked.setOptions({
7
9
  renderer: new TerminalRenderer({
@@ -29,20 +31,23 @@ export function printError(error: string) {
29
31
  console.error(displayAsMarkdown(`\n❌ ${error}`));
30
32
  }
31
33
 
32
- export function confirmPrompt(message: string): Promise<boolean> {
33
- const prompt = new Confirm({
34
- name: 'question',
34
+ export async function confirmPrompt(message: string): Promise<boolean> {
35
+ const question: Record<string, boolean> = await prompt({
36
+ name: 'confirmPrompt',
37
+ type: 'confirm',
35
38
  message: displayAsMarkdown(message),
36
39
  });
37
40
 
38
- return prompt.run();
41
+ return question['confirmPrompt'];
39
42
  }
40
43
 
41
- export function selectPrompt(message: string, choices: string[]): Promise<string> {
42
- const prompt = new Select({
44
+ export async function selectPrompt(message: string, choices: string[]): Promise<string> {
45
+ const question: Record<string, string> = await prompt({
46
+ name: 'selectPrompt',
47
+ type: 'select',
43
48
  choices,
44
49
  message: displayAsMarkdown(message),
45
50
  });
46
51
 
47
- return prompt.run();
52
+ return question['selectPrompt'];
48
53
  }
@@ -1,6 +1,6 @@
1
- import path from 'path';
2
- import fs from 'fs';
3
- import { TEMPLATE_PATHS } from '../constants';
1
+ import path from 'node:path';
2
+ import fs from 'node:fs';
3
+ import { TEMPLATE_PATHS } from '../constants.js';
4
4
  import { access, constants } from 'fs/promises';
5
5
 
6
6
  // Removes common template files from the list in case they have a plugin-specific override
@@ -3,9 +3,9 @@ import * as changeCase from 'change-case';
3
3
  import titleCase from 'title-case';
4
4
  import upperCase from 'upper-case';
5
5
  import lowerCase from 'lower-case';
6
- import { PARTIALS_DIR, PLUGIN_TYPES } from '../constants';
7
- import { readFileSync, readdirSync } from 'fs';
8
- import { basename, join } from 'path';
6
+ import { PARTIALS_DIR, PLUGIN_TYPES } from '../constants.js';
7
+ import { readFileSync, readdirSync } from 'node:fs';
8
+ import { basename, join } from 'node:path';
9
9
 
10
10
  // Why? The `{#if}` expression in Handlebars unfortunately only accepts a boolean, which makes it hard to compare values in templates.
11
11
  export const ifEq = (a: any, b: any, options: HelperOptions) => {
@@ -1,7 +1,7 @@
1
1
  import semver from 'semver';
2
- import { GRAFANA_FE_PACKAGES } from '../constants';
3
- import { getPackageJson, writePackageJson, getLatestPackageJson } from './utils.packagejson';
4
- import { PackageManager } from './utils.packageManager';
2
+ import { GRAFANA_FE_PACKAGES } from '../constants.js';
3
+ import { getPackageJson, writePackageJson, getLatestPackageJson } from './utils.packagejson.js';
4
+ import { PackageManager } from './utils.packageManager.js';
5
5
 
6
6
  type UpdateSummary = Record<string, { prev: string | null; next: string | null }>;
7
7
 
@@ -1,7 +1,7 @@
1
- import { basename } from 'path';
2
- import { spawnSync } from 'child_process';
1
+ import { basename } from 'node:path';
2
+ import { spawnSync } from 'node:child_process';
3
3
  import { sync as findUpSync } from 'find-up';
4
- import { getPackageJson } from './utils.packagejson';
4
+ import { getPackageJson } from './utils.packagejson.js';
5
5
 
6
6
  const NPM_LOCKFILE = 'package-lock.json';
7
7
  const PNPM_LOCKFILE = 'pnpm-lock.yaml';
@@ -1,8 +1,8 @@
1
- import path from 'path';
2
- import { TEMPLATE_PATHS } from '../constants';
3
- import { readJsonFile } from './utils.files';
4
- import { getTemplateData, renderTemplateFromFile } from './utils.templates';
5
- import fs from 'fs';
1
+ import path from 'node:path';
2
+ import { TEMPLATE_PATHS } from '../constants.js';
3
+ import { readJsonFile } from './utils.files.js';
4
+ import { getTemplateData, renderTemplateFromFile } from './utils.templates.js';
5
+ import fs from 'node:fs';
6
6
 
7
7
  export type PackageJson = {
8
8
  scripts: Record<string, string>;
@@ -1,6 +1,6 @@
1
- import path from 'path';
2
- import { PLUGIN_TYPES, IS_DEV, DEV_EXPORT_DIR } from '../constants';
3
- import { normalizeId } from './utils.handlebars';
1
+ import path from 'node:path';
2
+ import { PLUGIN_TYPES, IS_DEV, DEV_EXPORT_DIR } from '../constants.js';
3
+ import { normalizeId } from './utils.handlebars.js';
4
4
 
5
5
  export function getExportPath(pluginName: string, orgName: string, pluginType: PLUGIN_TYPES): string {
6
6
  if (IS_DEV) {
@@ -1,9 +1,8 @@
1
- import path from 'path';
2
- import { readJsonFile } from './utils.files';
1
+ import path from 'node:path';
2
+ import { readJsonFile } from './utils.files.js';
3
3
 
4
4
  export function getPluginJson(srcDir?: string) {
5
5
  const srcPath = srcDir || path.join(process.cwd(), 'src');
6
6
  const pluginJsonPath = path.join(srcPath, 'plugin.json');
7
-
8
7
  return readJsonFile(pluginJsonPath);
9
8
  }
@@ -1,15 +1,15 @@
1
1
  import glob from 'glob';
2
- import path from 'path';
3
- import fs from 'fs';
2
+ import path from 'node:path';
3
+ import fs from 'node:fs';
4
4
  import mkdirp from 'mkdirp';
5
- import { filterOutCommonFiles, isFile, isFileStartingWith } from './utils.files';
6
- import { renderHandlebarsTemplate } from './utils.handlebars';
7
- import { getPluginJson } from './utils.plugin';
8
- import { TEMPLATE_PATHS, EXPORT_PATH_PREFIX, EXTRA_TEMPLATE_VARIABLES } from '../constants';
9
- import { getPackageManagerWithFallback } from './utils.packageManager';
10
- import { getExportFileName } from '../utils/utils.files';
11
- import { getVersion } from './utils.version';
12
- import { getConfig } from './utils.config';
5
+ import { filterOutCommonFiles, isFile, isFileStartingWith } from './utils.files.js';
6
+ import { renderHandlebarsTemplate } from './utils.handlebars.js';
7
+ import { getPluginJson } from './utils.plugin.js';
8
+ import { TEMPLATE_PATHS, EXPORT_PATH_PREFIX, EXTRA_TEMPLATE_VARIABLES } from '../constants.js';
9
+ import { getPackageManagerWithFallback } from './utils.packageManager.js';
10
+ import { getExportFileName } from '../utils/utils.files.js';
11
+ import { getVersion } from './utils.version.js';
12
+ import { getConfig } from './utils.config.js';
13
13
 
14
14
  /**
15
15
  *
@@ -1,5 +1,8 @@
1
- import { readFileSync } from 'fs';
2
- import { resolve } from 'path';
1
+ import { readFileSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ const __dirname = fileURLToPath(new URL('.', import.meta.url));
3
6
 
4
7
  export function getVersion(): string {
5
8
  const packageJsonPath = resolve(__dirname, '..', '..', 'package.json');
package/tsconfig.json CHANGED
@@ -1,5 +1,10 @@
1
1
  {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
2
3
  "compilerOptions": {
4
+ "lib": ["es2023", "dom"],
5
+ "module": "node16",
6
+ "target": "es2022",
7
+ "moduleResolution": "node16",
3
8
  "outDir": "./dist"
4
9
  },
5
10
  "exclude": ["node_modules", "templates"],
@@ -0,0 +1,10 @@
1
+ import { resolve } from 'path';
2
+ import { defineConfig } from 'vitest/config';
3
+
4
+ export default defineConfig({
5
+ test: {
6
+ root: resolve(__dirname),
7
+ globals: true,
8
+ include: ['**/*.test.ts'],
9
+ },
10
+ });