@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.
- package/dist/bin/run.js +13 -18
- package/dist/commands/generate/prettify-files.js +15 -70
- package/dist/commands/generate/print-success-message.js +28 -31
- package/dist/commands/generate/prompt-user.js +23 -91
- package/dist/commands/generate/update-go-sdk-and-packages.js +36 -105
- package/dist/commands/generate.command.js +122 -240
- package/dist/commands/index.js +5 -21
- package/dist/commands/migrate.command.js +71 -134
- package/dist/commands/provisioning.command.js +30 -85
- package/dist/commands/types.js +1 -2
- package/dist/commands/update.command.js +44 -97
- package/dist/commands/version.command.js +16 -57
- package/dist/constants.js +37 -32
- package/dist/utils/tests/utils.files.test.js +21 -23
- package/dist/utils/tests/utils.handlebars.test.js +24 -26
- package/dist/utils/tests/utils.npm.test.js +103 -95
- package/dist/utils/tests/utils.plugin.test.js +11 -13
- package/dist/utils/tests/utils.templates.test.js +16 -18
- package/dist/utils/utils.config.js +30 -32
- package/dist/utils/utils.console.js +25 -31
- package/dist/utils/utils.files.js +38 -104
- package/dist/utils/utils.handlebars.js +30 -65
- package/dist/utils/utils.npm.js +75 -118
- package/dist/utils/utils.os.js +3 -7
- package/dist/utils/utils.packageManager.js +31 -37
- package/dist/utils/utils.packagejson.js +13 -22
- package/dist/utils/utils.path.js +7 -14
- package/dist/utils/utils.plugin.js +6 -13
- package/dist/utils/utils.templates.js +58 -80
- package/dist/utils/utils.version.js +9 -11
- package/package.json +20 -6
- package/src/bin/run.ts +2 -2
- package/src/commands/generate/prettify-files.ts +1 -1
- package/src/commands/generate/print-success-message.ts +4 -4
- package/src/commands/generate/prompt-user.ts +2 -2
- package/src/commands/generate/update-go-sdk-and-packages.ts +2 -2
- package/src/commands/generate.command.ts +15 -15
- package/src/commands/index.ts +5 -5
- package/src/commands/migrate.command.ts +6 -6
- package/src/commands/provisioning.command.ts +6 -6
- package/src/commands/types.ts +1 -1
- package/src/commands/update.command.ts +5 -5
- package/src/commands/version.command.ts +5 -2
- package/src/constants.ts +4 -1
- package/src/utils/tests/utils.files.test.ts +2 -2
- package/src/utils/tests/utils.handlebars.test.ts +2 -2
- package/src/utils/tests/utils.npm.test.ts +43 -34
- package/src/utils/tests/utils.plugin.test.ts +2 -2
- package/src/utils/tests/utils.templates.test.ts +2 -2
- package/src/utils/utils.config.ts +3 -3
- package/src/utils/utils.console.ts +16 -11
- package/src/utils/utils.files.ts +3 -3
- package/src/utils/utils.handlebars.ts +3 -3
- package/src/utils/utils.npm.ts +3 -3
- package/src/utils/utils.packageManager.ts +3 -3
- package/src/utils/utils.packagejson.ts +5 -5
- package/src/utils/utils.path.ts +3 -3
- package/src/utils/utils.plugin.ts +2 -3
- package/src/utils/utils.templates.ts +10 -10
- package/src/utils/utils.version.ts +5 -2
- package/tsconfig.json +5 -0
- 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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
224
|
-
|
|
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
|
-
|
|
256
|
-
|
|
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
|
-
|
|
289
|
-
|
|
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
|
-
|
|
311
|
-
|
|
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
|
-
|
|
343
|
-
|
|
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
|
-
|
|
376
|
-
|
|
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
|
-
|
|
408
|
-
|
|
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
|
-
|
|
430
|
-
|
|
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(
|
|
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
|
-
|
|
473
|
-
|
|
481
|
+
mocks.getPackageJson.mockReturnValue(packageJson);
|
|
482
|
+
mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
|
|
474
483
|
|
|
475
484
|
updatePackageJson();
|
|
476
485
|
//should have the combined content
|
|
477
|
-
expect(
|
|
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
|
-
|
|
516
|
-
|
|
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(
|
|
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
|
-
|
|
559
|
-
|
|
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(
|
|
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,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
34
|
-
name: '
|
|
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
|
|
41
|
+
return question['confirmPrompt'];
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
export function selectPrompt(message: string, choices: string[]): Promise<string> {
|
|
42
|
-
const
|
|
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
|
|
52
|
+
return question['selectPrompt'];
|
|
48
53
|
}
|
package/src/utils/utils.files.ts
CHANGED
|
@@ -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) => {
|
package/src/utils/utils.npm.ts
CHANGED
|
@@ -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>;
|
package/src/utils/utils.path.ts
CHANGED
|
@@ -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