Skip to content

Commit

Permalink
fix(cli): allow retrieving scalprum config from an external file in `…
Browse files Browse the repository at this point in the history
…export-dynamic-plugin`. (#1598)

Signed-off-by: David Festal <[email protected]>
  • Loading branch information
davidfestal authored May 2, 2024
1 parent 921cdaa commit 889be7f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
30 changes: 23 additions & 7 deletions packages/cli/src/commands/export-dynamic-plugin/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,22 @@ export async function frontend(
const {
name,
version,
scalprum: scalprumExternal,
scalprum: scalprumInline,
files,
} = await fs.readJson(paths.resolveTarget('package.json'));

let scalprum = scalprumExternal;
if (scalprum === undefined) {
let scalprum: any = undefined;

if (opts.scalprumConfig) {
const scalprumConfigFile = paths.resolveTarget(opts.scalprumConfig);
Task.log(
`Using external scalprum config file: ${chalk.cyan(scalprumConfigFile)}`,
);
scalprum = await fs.readJson(scalprumConfigFile);
} else if (scalprumInline) {
Task.log(`Using scalprum config inlined in the 'package.json'`);
scalprum = scalprumInline;
} else {
let scalprumName;
if (name.includes('/')) {
const fragments = name.split('/');
Expand All @@ -55,10 +65,10 @@ export async function frontend(
PluginRoot: './src/index.ts',
},
};
console.log(`No scalprum config. Using default dynamic UI configuration:`);
console.log(JSON.stringify(scalprum, null, 2));
console.log(
`If you wish to change the defaults, add "scalprum" configuration to plugin "package.json" file.`,
Task.log(`No scalprum config. Using default dynamic UI configuration:`);
Task.log(chalk.cyan(JSON.stringify(scalprum, null, 2)));
Task.log(
`If you wish to change the defaults, add "scalprum" configuration to plugin "package.json" file, or use the '--scalprum-config' option to specify an external config.`,
);
}

Expand All @@ -79,6 +89,12 @@ export async function frontend(
}

await fs.mkdirs(target);
await fs.writeFile(
path.join(target, '.gitignore'),
`
*
`,
);

await productionPack({
packageDir: paths.targetDir,
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ export function registerScriptCommand(program: Command) {
true,
)
.option('--no-in-place', undefined, false)
.option(
'--scalprum-config <file>',
'Allows retrieving scalprum configuration from an external JSON file, instead of using a `scalprum` field of the `package.json`. Frontend plugins only.',
)
.action(lazy(() => import('./export-dynamic-plugin').then(m => m.command)));

command
Expand Down

0 comments on commit 889be7f

Please sign in to comment.