Commit 78566de7 by Carl Bergquist Committed by GitHub

adds template for backend datasource (#23864)

parent 6f02b515
import { prompt } from 'inquirer';
import path from 'path';
import { Task, TaskRunner } from './task';
import { promptConfirm } from '../utils/prompt';
import {
getPluginIdFromName,
verifyGitExists,
promptPluginType,
fetchTemplate,
promptPluginDetails,
formatPluginDetails,
getPluginIdFromName,
prepareJsonFiles,
promptPluginDetails,
promptPluginType,
removeGitFiles,
verifyGitExists,
} from './plugin/create';
import { Task, TaskRunner } from './task';
interface PluginCreateOptions {
name?: string;
......@@ -38,7 +37,7 @@ const pluginCreateRunner: TaskRunner<PluginCreateOptions> = async ({ name }) =>
} while ((await prompt<{ confirm: boolean }>(promptConfirm('confirm', 'Is that ok?'))).confirm === false);
// 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
await removeGitFiles(destPath);
......
import chalk from 'chalk';
import commandExists from 'command-exists';
import { readFileSync, promises as fs } from 'fs';
import { promises as fs, readFileSync } from 'fs';
import { prompt } from 'inquirer';
import kebabCase from 'lodash/kebabCase';
import path from 'path';
import gitPromise from 'simple-git/promise';
import { useSpinner } from '../../utils/useSpinner';
import { promptConfirm, promptInput } from '../../utils/prompt';
import { rmdir } from '../../utils/rmdir';
import { promptInput, promptConfirm } from '../../utils/prompt';
import chalk from 'chalk';
import { useSpinner } from '../../utils/useSpinner';
const simpleGit = gitPromise(process.cwd());
......@@ -21,12 +20,13 @@ interface PluginDetails {
keywords: string;
}
type PluginType = 'angular-panel' | 'react-panel' | 'datasource-plugin';
type PluginType = 'angular-panel' | 'react-panel' | 'datasource-plugin' | 'backend-datasource-plugin';
const RepositoriesPaths = {
'angular-panel': 'https://github.com/grafana/simple-angular-panel.git',
'react-panel': 'https://github.com/grafana/simple-react-panel.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 () => {
......@@ -64,6 +64,7 @@ export const promptPluginType = async () =>
{ name: 'Angular panel', value: 'angular-panel' },
{ name: 'React panel', value: 'react-panel' },
{ 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 }>(
}
);
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',
async ({ pluginDetails, pluginPath }) => {
async ({ type, pluginDetails, pluginPath }) => {
const packageJsonPath = path.resolve(pluginPath, 'package.json');
const pluginJsonPath = path.resolve(pluginPath, 'src/plugin.json');
const packageJson: any = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
......@@ -115,6 +116,12 @@ export const prepareJsonFiles = useSpinner<{ pluginDetails: PluginDetails; plugi
pluginJson.name = pluginDetails.name;
pluginJson.id = pluginId;
if (type === 'backend-datasource-plugin') {
pluginJson.backend = true;
pluginJson.executable = 'gpx_' + pluginDetails.name;
}
pluginJson.info = {
...pluginJson.info,
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