fix plugin:diff
This commit is contained in:
@@ -228,10 +228,10 @@ export default async (cmd: Command) => {
|
||||
? `@${cmd.scope.replace(/^@/, '')}/plugin-${answers.id}`
|
||||
: `plugin-${answers.id}`;
|
||||
const scopeName = cmd.scope ? `@${cmd.scope.replace(/^@/, '')}` : '';
|
||||
const registryURL =
|
||||
const npmRegistry =
|
||||
cmd.npmRegistry && cmd.scope
|
||||
? `"${scopeName}:registry": "${cmd.npmRegistry}",`
|
||||
: null;
|
||||
? `"${scopeName}:registry": "${cmd.npmRegistry}"`
|
||||
: '';
|
||||
const privatePackage = cmd.private === false ? false : true;
|
||||
|
||||
const appPackage = paths.resolveTargetRoot('packages/app');
|
||||
@@ -261,7 +261,7 @@ export default async (cmd: Command) => {
|
||||
scopeName,
|
||||
name,
|
||||
privatePackage,
|
||||
registryURL,
|
||||
npmRegistry,
|
||||
});
|
||||
|
||||
Task.section('Moving to final location');
|
||||
|
||||
@@ -30,6 +30,9 @@ import { version as backstageVersion } from '../../lib/version';
|
||||
export type PluginData = {
|
||||
id: string;
|
||||
name: string;
|
||||
privatePackage: string;
|
||||
version: string;
|
||||
npmRegistry: string;
|
||||
};
|
||||
|
||||
const fileHandlers = [
|
||||
@@ -62,14 +65,9 @@ export default async (cmd: Command) => {
|
||||
promptFunc = yesPromptFunc;
|
||||
}
|
||||
|
||||
const { version } = await fs.readJson(paths.resolveTargetRoot('lerna.json'));
|
||||
|
||||
const data = await readPluginData();
|
||||
const privatePackage = false;
|
||||
const templateFiles = await diffTemplateFiles('default-plugin', {
|
||||
version,
|
||||
backstageVersion,
|
||||
privatePackage,
|
||||
...data,
|
||||
});
|
||||
await handleAllFiles(fileHandlers, templateFiles, promptFunc);
|
||||
@@ -79,9 +77,19 @@ export default async (cmd: Command) => {
|
||||
// Reads templating data from the existing plugin
|
||||
async function readPluginData(): Promise<PluginData> {
|
||||
let name: string;
|
||||
let privatePackage: string;
|
||||
let version: string;
|
||||
let npmRegistry: string;
|
||||
try {
|
||||
const pkg = require(paths.resolveTarget('package.json'));
|
||||
name = pkg.name;
|
||||
privatePackage = pkg.private;
|
||||
version = pkg.version;
|
||||
const scope = name.split('/')[0];
|
||||
if (`${scope}:registry` in pkg.publishConfig) {
|
||||
const registryURL = pkg.publishConfig[`${scope}:registry`];
|
||||
npmRegistry = `"${scope}:registry" : "${registryURL}"`;
|
||||
} else npmRegistry = '';
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to read target package, ${error}`);
|
||||
}
|
||||
@@ -98,5 +106,5 @@ async function readPluginData(): Promise<PluginData> {
|
||||
|
||||
const id = pluginIdMatch[1];
|
||||
|
||||
return { id, name };
|
||||
return { id, name, privatePackage, version, npmRegistry };
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
"license": "Apache-2.0",
|
||||
"private": {{privatePackage}},
|
||||
"publishConfig": {
|
||||
{{{registryURL}}}
|
||||
{{#if npmRegistry}} {{{npmRegistry}}},
|
||||
{{/if}}
|
||||
"access": "public",
|
||||
"main": "dist/index.esm.js",
|
||||
"types": "dist/index.d.ts"
|
||||
|
||||
Reference in New Issue
Block a user