Skip to content

Commit 889be7f

Browse files
authored
fix(cli): allow retrieving scalprum config from an external file in export-dynamic-plugin. (janus-idp#1598)
Signed-off-by: David Festal <[email protected]>
1 parent 921cdaa commit 889be7f

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

packages/cli/src/commands/export-dynamic-plugin/frontend.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,22 @@ export async function frontend(
3636
const {
3737
name,
3838
version,
39-
scalprum: scalprumExternal,
39+
scalprum: scalprumInline,
4040
files,
4141
} = await fs.readJson(paths.resolveTarget('package.json'));
4242

43-
let scalprum = scalprumExternal;
44-
if (scalprum === undefined) {
43+
let scalprum: any = undefined;
44+
45+
if (opts.scalprumConfig) {
46+
const scalprumConfigFile = paths.resolveTarget(opts.scalprumConfig);
47+
Task.log(
48+
`Using external scalprum config file: ${chalk.cyan(scalprumConfigFile)}`,
49+
);
50+
scalprum = await fs.readJson(scalprumConfigFile);
51+
} else if (scalprumInline) {
52+
Task.log(`Using scalprum config inlined in the 'package.json'`);
53+
scalprum = scalprumInline;
54+
} else {
4555
let scalprumName;
4656
if (name.includes('/')) {
4757
const fragments = name.split('/');
@@ -55,10 +65,10 @@ export async function frontend(
5565
PluginRoot: './src/index.ts',
5666
},
5767
};
58-
console.log(`No scalprum config. Using default dynamic UI configuration:`);
59-
console.log(JSON.stringify(scalprum, null, 2));
60-
console.log(
61-
`If you wish to change the defaults, add "scalprum" configuration to plugin "package.json" file.`,
68+
Task.log(`No scalprum config. Using default dynamic UI configuration:`);
69+
Task.log(chalk.cyan(JSON.stringify(scalprum, null, 2)));
70+
Task.log(
71+
`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.`,
6272
);
6373
}
6474

@@ -79,6 +89,12 @@ export async function frontend(
7989
}
8090

8191
await fs.mkdirs(target);
92+
await fs.writeFile(
93+
path.join(target, '.gitignore'),
94+
`
95+
*
96+
`,
97+
);
8298

8399
await productionPack({
84100
packageDir: paths.targetDir,

packages/cli/src/commands/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ export function registerScriptCommand(program: Command) {
133133
true,
134134
)
135135
.option('--no-in-place', undefined, false)
136+
.option(
137+
'--scalprum-config <file>',
138+
'Allows retrieving scalprum configuration from an external JSON file, instead of using a `scalprum` field of the `package.json`. Frontend plugins only.',
139+
)
136140
.action(lazy(() => import('./export-dynamic-plugin').then(m => m.command)));
137141

138142
command

0 commit comments

Comments
 (0)