Commit 78566de7 by Carl Bergquist Committed by GitHub

adds template for backend datasource (#23864)

parent 6f02b515
import { prompt } from 'inquirer'; import { prompt } from 'inquirer';
import path from 'path'; import path from 'path';
import { Task, TaskRunner } from './task';
import { promptConfirm } from '../utils/prompt'; import { promptConfirm } from '../utils/prompt';
import { import {
getPluginIdFromName,
verifyGitExists,
promptPluginType,
fetchTemplate, fetchTemplate,
promptPluginDetails,
formatPluginDetails, formatPluginDetails,
getPluginIdFromName,
prepareJsonFiles, prepareJsonFiles,
promptPluginDetails,
promptPluginType,
removeGitFiles, removeGitFiles,
verifyGitExists,
} from './plugin/create'; } from './plugin/create';
import { Task, TaskRunner } from './task';
interface PluginCreateOptions { interface PluginCreateOptions {
name?: string; name?: string;
...@@ -38,7 +37,7 @@ const pluginCreateRunner: TaskRunner<PluginCreateOptions> = async ({ name }) => ...@@ -38,7 +37,7 @@ const pluginCreateRunner: TaskRunner<PluginCreateOptions> = async ({ name }) =>
} while ((await prompt<{ confirm: boolean }>(promptConfirm('confirm', 'Is that ok?'))).confirm === false); } while ((await prompt<{ confirm: boolean }>(promptConfirm('confirm', 'Is that ok?'))).confirm === false);
// 5. Update json files (package.json, src/plugin.json) // 5. Update json files (package.json, src/plugin.json)
await prepareJsonFiles({ pluginDetails, pluginPath: destPath }); await prepareJsonFiles({ type: type, pluginDetails, pluginPath: destPath });
// 6. Remove cloned repository .git dir // 6. Remove cloned repository .git dir
await removeGitFiles(destPath); await removeGitFiles(destPath);
......
import chalk from 'chalk';
import commandExists from 'command-exists'; import commandExists from 'command-exists';
import { readFileSync, promises as fs } from 'fs'; import { promises as fs, readFileSync } from 'fs';
import { prompt } from 'inquirer'; import { prompt } from 'inquirer';
import kebabCase from 'lodash/kebabCase'; import kebabCase from 'lodash/kebabCase';
import path from 'path'; import path from 'path';
import gitPromise from 'simple-git/promise'; import gitPromise from 'simple-git/promise';
import { promptConfirm, promptInput } from '../../utils/prompt';
import { useSpinner } from '../../utils/useSpinner';
import { rmdir } from '../../utils/rmdir'; import { rmdir } from '../../utils/rmdir';
import { promptInput, promptConfirm } from '../../utils/prompt'; import { useSpinner } from '../../utils/useSpinner';
import chalk from 'chalk';
const simpleGit = gitPromise(process.cwd()); const simpleGit = gitPromise(process.cwd());
...@@ -21,12 +20,13 @@ interface PluginDetails { ...@@ -21,12 +20,13 @@ interface PluginDetails {
keywords: string; keywords: string;
} }
type PluginType = 'angular-panel' | 'react-panel' | 'datasource-plugin'; type PluginType = 'angular-panel' | 'react-panel' | 'datasource-plugin' | 'backend-datasource-plugin';
const RepositoriesPaths = { const RepositoriesPaths = {
'angular-panel': 'https://github.com/grafana/simple-angular-panel.git', 'angular-panel': 'https://github.com/grafana/simple-angular-panel.git',
'react-panel': 'https://github.com/grafana/simple-react-panel.git', 'react-panel': 'https://github.com/grafana/simple-react-panel.git',
'datasource-plugin': 'https://github.com/grafana/simple-datasource.git', 'datasource-plugin': 'https://github.com/grafana/simple-datasource.git',
'backend-datasource-plugin': 'https://github.com/grafana/simple-datasource-backend.git',
}; };
export const getGitUsername = async () => { export const getGitUsername = async () => {
...@@ -64,6 +64,7 @@ export const promptPluginType = async () => ...@@ -64,6 +64,7 @@ export const promptPluginType = async () =>
{ name: 'Angular panel', value: 'angular-panel' }, { name: 'Angular panel', value: 'angular-panel' },
{ name: 'React panel', value: 'react-panel' }, { name: 'React panel', value: 'react-panel' },
{ name: 'Datasource plugin', value: 'datasource-plugin' }, { name: 'Datasource plugin', value: 'datasource-plugin' },
{ name: 'Backend datasource plugin', value: 'backend-datasource-plugin' },
], ],
}, },
]); ]);
...@@ -100,9 +101,9 @@ export const fetchTemplate = useSpinner<{ type: PluginType; dest: string }>( ...@@ -100,9 +101,9 @@ export const fetchTemplate = useSpinner<{ type: PluginType; dest: string }>(
} }
); );
export const prepareJsonFiles = useSpinner<{ pluginDetails: PluginDetails; pluginPath: string }>( export const prepareJsonFiles = useSpinner<{ type: PluginType; pluginDetails: PluginDetails; pluginPath: string }>(
'Saving package.json and plugin.json files', 'Saving package.json and plugin.json files',
async ({ pluginDetails, pluginPath }) => { async ({ type, pluginDetails, pluginPath }) => {
const packageJsonPath = path.resolve(pluginPath, 'package.json'); const packageJsonPath = path.resolve(pluginPath, 'package.json');
const pluginJsonPath = path.resolve(pluginPath, 'src/plugin.json'); const pluginJsonPath = path.resolve(pluginPath, 'src/plugin.json');
const packageJson: any = JSON.parse(readFileSync(packageJsonPath, 'utf8')); const packageJson: any = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
...@@ -115,6 +116,12 @@ export const prepareJsonFiles = useSpinner<{ pluginDetails: PluginDetails; plugi ...@@ -115,6 +116,12 @@ export const prepareJsonFiles = useSpinner<{ pluginDetails: PluginDetails; plugi
pluginJson.name = pluginDetails.name; pluginJson.name = pluginDetails.name;
pluginJson.id = pluginId; pluginJson.id = pluginId;
if (type === 'backend-datasource-plugin') {
pluginJson.backend = true;
pluginJson.executable = 'gpx_' + pluginDetails.name;
}
pluginJson.info = { pluginJson.info = {
...pluginJson.info, ...pluginJson.info,
description: pluginDetails.description, description: pluginDetails.description,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment