1 | 'use strict';
|
2 |
|
3 | var configLoader = require('@backstage/config-loader');
|
4 | var config = require('@backstage/config');
|
5 | var index = require('./index-09611511.cjs.js');
|
6 | var getPackages = require('@manypkg/get-packages');
|
7 | var PackageGraph = require('./PackageGraph-5fbc300a.cjs.js');
|
8 |
|
9 | function isValidUrl(url) {
|
10 | try {
|
11 | new URL(url);
|
12 | return true;
|
13 | } catch {
|
14 | return false;
|
15 | }
|
16 | }
|
17 |
|
18 | async function loadCliConfig(options) {
|
19 | const configTargets = [];
|
20 | options.args.forEach((arg) => {
|
21 | if (!isValidUrl(arg)) {
|
22 | configTargets.push({ path: index.paths.resolveTarget(arg) });
|
23 | }
|
24 | });
|
25 | const { packages } = await getPackages.getPackages(index.paths.targetDir);
|
26 | let localPackageNames;
|
27 | if (options.fromPackage) {
|
28 | if (packages.length) {
|
29 | const graph = PackageGraph.PackageGraph.fromPackages(packages);
|
30 | localPackageNames = Array.from(graph.collectPackageNames([options.fromPackage], (node) => {
|
31 | if (node.name === "@backstage/cli") {
|
32 | return void 0;
|
33 | }
|
34 | return node.localDependencies.keys();
|
35 | }));
|
36 | } else {
|
37 | localPackageNames = [options.fromPackage];
|
38 | }
|
39 | } else {
|
40 | localPackageNames = packages.map((p) => p.packageJson.name);
|
41 | }
|
42 | const schema = await configLoader.loadConfigSchema({
|
43 | dependencies: localPackageNames,
|
44 | packagePaths: [index.paths.resolveTargetRoot("package.json")]
|
45 | });
|
46 | const { appConfigs } = await configLoader.loadConfig({
|
47 | experimentalEnvFunc: options.mockEnv ? async (name) => process.env[name] || "x" : void 0,
|
48 | configRoot: index.paths.targetRoot,
|
49 | configTargets
|
50 | });
|
51 | process.stderr.write(`Loaded config from ${appConfigs.map((c) => c.context).join(", ")}
|
52 | `);
|
53 | try {
|
54 | const frontendAppConfigs = schema.process(appConfigs, {
|
55 | visibility: options.fullVisibility ? ["frontend", "backend", "secret"] : ["frontend"],
|
56 | withFilteredKeys: options.withFilteredKeys,
|
57 | withDeprecatedKeys: options.withDeprecatedKeys
|
58 | });
|
59 | const frontendConfig = config.ConfigReader.fromConfigs(frontendAppConfigs);
|
60 | return {
|
61 | schema,
|
62 | appConfigs,
|
63 | frontendConfig,
|
64 | frontendAppConfigs
|
65 | };
|
66 | } catch (error) {
|
67 | const maybeSchemaError = error;
|
68 | if (maybeSchemaError.messages) {
|
69 | const messages = maybeSchemaError.messages.join("\n ");
|
70 | throw new Error(`Configuration does not match schema
|
71 |
|
72 | ${messages}`);
|
73 | }
|
74 | throw error;
|
75 | }
|
76 | }
|
77 |
|
78 | exports.loadCliConfig = loadCliConfig;
|
79 |
|