@grafana/create-plugin 3.5.0 → 3.6.0-canary.669.68b0597.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/commands/generate.command.js +2 -2
- package/dist/commands/update.command.js +6 -1
- package/dist/utils/utils.packagejson.js +2 -2
- package/dist/utils/utils.prettifyFiles.js +31 -0
- package/package.json +2 -2
- package/src/commands/generate.command.ts +2 -2
- package/src/commands/update.command.ts +9 -1
- package/src/utils/utils.packagejson.ts +2 -2
- package/src/utils/utils.prettifyFiles.ts +48 -0
- package/dist/commands/generate/prettify-files.js +0 -17
- package/src/commands/generate/prettify-files.ts +0 -21
|
@@ -11,7 +11,7 @@ import { getPackageManagerFromUserAgent, getPackageManagerInstallCmd } from '../
|
|
|
11
11
|
import { getExportPath } from '../utils/utils.path.js';
|
|
12
12
|
import { renderTemplateFromFile } from '../utils/utils.templates.js';
|
|
13
13
|
import { getVersion } from '../utils/utils.version.js';
|
|
14
|
-
import { prettifyFiles } from '
|
|
14
|
+
import { prettifyFiles } from '../utils/utils.prettifyFiles.js';
|
|
15
15
|
import { printGenerateSuccessMessage } from './generate/print-success-message.js';
|
|
16
16
|
import { promptUser } from './generate/prompt-user.js';
|
|
17
17
|
import { updateGoSdkAndModules } from './generate/update-go-sdk-and-packages.js';
|
|
@@ -36,7 +36,7 @@ export const generate = async (argv) => {
|
|
|
36
36
|
if (answers.hasBackend) {
|
|
37
37
|
await execPostScaffoldFunction(updateGoSdkAndModules, exportPath);
|
|
38
38
|
}
|
|
39
|
-
await execPostScaffoldFunction(prettifyFiles, exportPath);
|
|
39
|
+
await execPostScaffoldFunction(prettifyFiles, { targetPath: exportPath });
|
|
40
40
|
printGenerateSuccessMessage(answers);
|
|
41
41
|
};
|
|
42
42
|
function getTemplateData(answers) {
|
|
@@ -3,9 +3,10 @@ import { TEXT, UDPATE_CONFIG } from '../constants.js';
|
|
|
3
3
|
import { compileTemplateFiles, getTemplateData } from '../utils/utils.templates.js';
|
|
4
4
|
import { confirmPrompt, selectPrompt, printMessage, printSuccessMessage, printRedBox } from '../utils/utils.console.js';
|
|
5
5
|
import { updatePackageJson, hasNpmDependenciesToUpdate, getPackageJsonUpdatesAsText, updateNpmScripts, writePackageManagerInPackageJson, } from '../utils/utils.npm.js';
|
|
6
|
-
import { getPackageManagerWithFallback } from '../utils/utils.packageManager.js';
|
|
7
6
|
import { isGitDirectory, isGitDirectoryClean } from '../utils/utils.git.js';
|
|
8
7
|
import { isPluginDirectory } from '../utils/utils.plugin.js';
|
|
8
|
+
import { getPackageManagerWithFallback } from '../utils/utils.packageManager.js';
|
|
9
|
+
import { prettifyFiles } from '../utils/utils.prettifyFiles.js';
|
|
9
10
|
export const update = async (argv) => {
|
|
10
11
|
try {
|
|
11
12
|
if (!(await isGitDirectory()) && !argv.force) {
|
|
@@ -38,6 +39,8 @@ In case you want to proceed as is please use the ${chalk.bold('--force')} flag.)
|
|
|
38
39
|
if (await confirmPrompt(TEXT.updateConfigPrompt)) {
|
|
39
40
|
compileTemplateFiles(UDPATE_CONFIG.filesToOverride, getTemplateData());
|
|
40
41
|
printSuccessMessage(TEXT.overrideFilesSuccess);
|
|
42
|
+
const prettifyMsg = await prettifyFiles({ targetPath: '.config', projectRoot: '.' });
|
|
43
|
+
printMessage(prettifyMsg);
|
|
41
44
|
}
|
|
42
45
|
else {
|
|
43
46
|
printMessage(TEXT.overrideFilesAborted);
|
|
@@ -78,6 +81,8 @@ In case you want to proceed as is please use the ${chalk.bold('--force')} flag.)
|
|
|
78
81
|
}
|
|
79
82
|
const packageManager = getPackageManagerWithFallback();
|
|
80
83
|
writePackageManagerInPackageJson(packageManager);
|
|
84
|
+
const prettifyMsg = await prettifyFiles({ targetPath: '.config', projectRoot: '.' });
|
|
85
|
+
printMessage(prettifyMsg);
|
|
81
86
|
printSuccessMessage(TEXT.updateCommandSuccess);
|
|
82
87
|
}
|
|
83
88
|
catch (error) {
|
|
@@ -3,8 +3,8 @@ import { TEMPLATE_PATHS } from '../constants.js';
|
|
|
3
3
|
import { readJsonFile } from './utils.files.js';
|
|
4
4
|
import { getTemplateData, renderTemplateFromFile } from './utils.templates.js';
|
|
5
5
|
import fs from 'node:fs';
|
|
6
|
-
export function getPackageJson() {
|
|
7
|
-
return readJsonFile(path.join(
|
|
6
|
+
export function getPackageJson(rootPath = process.cwd()) {
|
|
7
|
+
return readJsonFile(path.join(rootPath, 'package.json'));
|
|
8
8
|
}
|
|
9
9
|
export function getLatestPackageJson() {
|
|
10
10
|
const packageJsonPath = path.join(TEMPLATE_PATHS.common, '_package.json');
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { exec as nodeExec } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import { getPackageJson } from './utils.packagejson.js';
|
|
5
|
+
const exec = promisify(nodeExec);
|
|
6
|
+
export async function prettifyFiles(options) {
|
|
7
|
+
const targetPath = options.targetPath ?? process.cwd();
|
|
8
|
+
const projectRoot = options.projectRoot ?? targetPath;
|
|
9
|
+
if (!isPrettierUsed(projectRoot)) {
|
|
10
|
+
return 'Prettify skipped, because it is not used in this project.';
|
|
11
|
+
}
|
|
12
|
+
if (!fs.existsSync(targetPath)) {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
const prettierVersion = getPrettierVersion(projectRoot);
|
|
16
|
+
try {
|
|
17
|
+
let command = `npx -y prettier@${prettierVersion} . --write`;
|
|
18
|
+
await exec(command, { cwd: targetPath });
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
throw new Error('There was a problem running prettier on the plugin files. Please run `npx -y prettier@2 . --write` manually in your plugin directory.');
|
|
22
|
+
}
|
|
23
|
+
return 'Successfully ran prettier against new plugin.';
|
|
24
|
+
}
|
|
25
|
+
function isPrettierUsed(projectRoot) {
|
|
26
|
+
return Boolean(getPrettierVersion(projectRoot));
|
|
27
|
+
}
|
|
28
|
+
function getPrettierVersion(projectRoot) {
|
|
29
|
+
const packageJson = getPackageJson(projectRoot);
|
|
30
|
+
return packageJson.devDependencies?.prettier || packageJson.dependencies?.prettier;
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/create-plugin",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0-canary.669.68b0597.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"directory": "packages/create-plugin",
|
|
6
6
|
"url": "https://github.com/grafana/plugin-tools"
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
"engines": {
|
|
87
87
|
"node": ">=20"
|
|
88
88
|
},
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "68b05979a4745baaf52da1de8a5e4c002ecb5ca6"
|
|
90
90
|
}
|
|
@@ -12,7 +12,7 @@ import { getPackageManagerFromUserAgent, getPackageManagerInstallCmd } from '../
|
|
|
12
12
|
import { getExportPath } from '../utils/utils.path.js';
|
|
13
13
|
import { renderTemplateFromFile } from '../utils/utils.templates.js';
|
|
14
14
|
import { getVersion } from '../utils/utils.version.js';
|
|
15
|
-
import { prettifyFiles } from '
|
|
15
|
+
import { prettifyFiles } from '../utils/utils.prettifyFiles.js';
|
|
16
16
|
import { printGenerateSuccessMessage } from './generate/print-success-message.js';
|
|
17
17
|
import { promptUser } from './generate/prompt-user.js';
|
|
18
18
|
import { updateGoSdkAndModules } from './generate/update-go-sdk-and-packages.js';
|
|
@@ -45,7 +45,7 @@ export const generate = async (argv: minimist.ParsedArgs) => {
|
|
|
45
45
|
if (answers.hasBackend) {
|
|
46
46
|
await execPostScaffoldFunction(updateGoSdkAndModules, exportPath);
|
|
47
47
|
}
|
|
48
|
-
await execPostScaffoldFunction(prettifyFiles, exportPath);
|
|
48
|
+
await execPostScaffoldFunction(prettifyFiles, { targetPath: exportPath });
|
|
49
49
|
|
|
50
50
|
printGenerateSuccessMessage(answers);
|
|
51
51
|
};
|
|
@@ -10,9 +10,10 @@ import {
|
|
|
10
10
|
updateNpmScripts,
|
|
11
11
|
writePackageManagerInPackageJson,
|
|
12
12
|
} from '../utils/utils.npm.js';
|
|
13
|
-
import { getPackageManagerWithFallback } from '../utils/utils.packageManager.js';
|
|
14
13
|
import { isGitDirectory, isGitDirectoryClean } from '../utils/utils.git.js';
|
|
15
14
|
import { isPluginDirectory } from '../utils/utils.plugin.js';
|
|
15
|
+
import { getPackageManagerWithFallback } from '../utils/utils.packageManager.js';
|
|
16
|
+
import { prettifyFiles } from '../utils/utils.prettifyFiles.js';
|
|
16
17
|
|
|
17
18
|
export const update = async (argv: minimist.ParsedArgs) => {
|
|
18
19
|
try {
|
|
@@ -58,7 +59,11 @@ In case you want to proceed as is please use the ${chalk.bold('--force')} flag.)
|
|
|
58
59
|
// -----------------------------------
|
|
59
60
|
if (await confirmPrompt(TEXT.updateConfigPrompt)) {
|
|
60
61
|
compileTemplateFiles(UDPATE_CONFIG.filesToOverride, getTemplateData());
|
|
62
|
+
|
|
61
63
|
printSuccessMessage(TEXT.overrideFilesSuccess);
|
|
64
|
+
|
|
65
|
+
const prettifyMsg = await prettifyFiles({ targetPath: '.config', projectRoot: '.' });
|
|
66
|
+
printMessage(prettifyMsg);
|
|
62
67
|
} else {
|
|
63
68
|
printMessage(TEXT.overrideFilesAborted);
|
|
64
69
|
process.exit(0);
|
|
@@ -110,6 +115,9 @@ In case you want to proceed as is please use the ${chalk.bold('--force')} flag.)
|
|
|
110
115
|
const packageManager = getPackageManagerWithFallback();
|
|
111
116
|
writePackageManagerInPackageJson(packageManager);
|
|
112
117
|
|
|
118
|
+
const prettifyMsg = await prettifyFiles({ targetPath: '.config', projectRoot: '.' });
|
|
119
|
+
printMessage(prettifyMsg);
|
|
120
|
+
|
|
113
121
|
// 4. Summary
|
|
114
122
|
// -------------
|
|
115
123
|
printSuccessMessage(TEXT.updateCommandSuccess);
|
|
@@ -10,8 +10,8 @@ export type PackageJson = {
|
|
|
10
10
|
devDependencies: Record<string, string>;
|
|
11
11
|
packageManager?: string;
|
|
12
12
|
} & Record<string, any>;
|
|
13
|
-
export function getPackageJson(): PackageJson {
|
|
14
|
-
return readJsonFile(path.join(
|
|
13
|
+
export function getPackageJson(rootPath = process.cwd()): PackageJson {
|
|
14
|
+
return readJsonFile(path.join(rootPath, 'package.json'));
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// Returns with a package.json that is generated based on the latest templates
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { exec as nodeExec } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import { getPackageJson } from './utils.packagejson.js';
|
|
5
|
+
|
|
6
|
+
const exec = promisify(nodeExec);
|
|
7
|
+
|
|
8
|
+
type PrettifyFilesArgs = {
|
|
9
|
+
// The path where we want to prettify files, defaults to the CWD
|
|
10
|
+
targetPath?: string;
|
|
11
|
+
|
|
12
|
+
// In case the `targetPath` would be set to a subdirectory, e.g. `.config/`. Defaults to `targetPath`.
|
|
13
|
+
projectRoot?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export async function prettifyFiles(options: PrettifyFilesArgs) {
|
|
17
|
+
const targetPath = options.targetPath ?? process.cwd();
|
|
18
|
+
const projectRoot = options.projectRoot ?? targetPath;
|
|
19
|
+
|
|
20
|
+
if (!isPrettierUsed(projectRoot)) {
|
|
21
|
+
return 'Prettify skipped, because it is not used in this project.';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!fs.existsSync(targetPath)) {
|
|
25
|
+
return '';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const prettierVersion = getPrettierVersion(projectRoot);
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
let command = `npx -y prettier@${prettierVersion} . --write`;
|
|
32
|
+
await exec(command, { cwd: targetPath });
|
|
33
|
+
} catch (error) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
'There was a problem running prettier on the plugin files. Please run `npx -y prettier@2 . --write` manually in your plugin directory.'
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return 'Successfully ran prettier against new plugin.';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isPrettierUsed(projectRoot?: string) {
|
|
42
|
+
return Boolean(getPrettierVersion(projectRoot));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getPrettierVersion(projectRoot?: string) {
|
|
46
|
+
const packageJson = getPackageJson(projectRoot);
|
|
47
|
+
return packageJson.devDependencies?.prettier || packageJson.dependencies?.prettier;
|
|
48
|
+
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { exec as nodeExec } from 'node:child_process';
|
|
2
|
-
import { promisify } from 'node:util';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
const exec = promisify(nodeExec);
|
|
5
|
-
export async function prettifyFiles(exportPath) {
|
|
6
|
-
if (!fs.existsSync(exportPath)) {
|
|
7
|
-
return '';
|
|
8
|
-
}
|
|
9
|
-
try {
|
|
10
|
-
let command = 'npx -y prettier@2 . --write';
|
|
11
|
-
await exec(command, { cwd: exportPath });
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
throw new Error('There was a problem running prettier on the plugin files. Please run `npx -y prettier@2 . --write` manually in your plugin directory.');
|
|
15
|
-
}
|
|
16
|
-
return 'Successfully ran prettier against new plugin.';
|
|
17
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { exec as nodeExec } from 'node:child_process';
|
|
2
|
-
import { promisify } from 'node:util';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
|
|
5
|
-
const exec = promisify(nodeExec);
|
|
6
|
-
|
|
7
|
-
export async function prettifyFiles(exportPath: string) {
|
|
8
|
-
if (!fs.existsSync(exportPath)) {
|
|
9
|
-
return '';
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
let command = 'npx -y prettier@2 . --write';
|
|
14
|
-
await exec(command, { cwd: exportPath });
|
|
15
|
-
} catch (error) {
|
|
16
|
-
throw new Error(
|
|
17
|
-
'There was a problem running prettier on the plugin files. Please run `npx -y prettier@2 . --write` manually in your plugin directory.'
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
return 'Successfully ran prettier against new plugin.';
|
|
21
|
-
}
|