-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app-builder): allow passing custom root command via command line
- Loading branch information
1 parent
c5bf728
commit 44689f6
Showing
11 changed files
with
70 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {type OneOrMore, toArray} from '@myparcel/ts-utils'; | ||
import {type PdkBuilderConfig} from '../types'; | ||
|
||
export const createCommand = (config: PdkBuilderConfig, command: OneOrMore<string>): string => { | ||
const resolvedRootCommand = toArray(config.rootCommand ?? []); | ||
const resolvedCommand = toArray(command ?? []); | ||
|
||
return [...resolvedRootCommand, ...resolvedCommand].filter(Boolean).join(' '); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
import {type LiftoffEnv} from 'liftoff'; | ||
import {type PdkBuilderConfig, type ResolvedPdkBuilderConfig} from '../types'; | ||
import {type AnyCommandArgs, type PdkBuilderConfig, type ResolvedPdkBuilderConfig} from '../types'; | ||
import {type ParsedCommand} from './parseCommand'; | ||
|
||
const configCache = new Map<string, PdkBuilderConfig>(); | ||
|
||
export async function resolveConfig(env: LiftoffEnv): Promise<ResolvedPdkBuilderConfig> { | ||
export async function resolveConfig( | ||
env: LiftoffEnv, | ||
args?: ParsedCommand<AnyCommandArgs>, | ||
): Promise<ResolvedPdkBuilderConfig> { | ||
if (!env.configPath) { | ||
throw new Error('No config file found.'); | ||
} | ||
|
||
if (configCache.has(env.configPath)) { | ||
return configCache.get(env.configPath) as ResolvedPdkBuilderConfig; | ||
return {...configCache.get(env.configPath), ...args} as ResolvedPdkBuilderConfig; | ||
} | ||
|
||
const imported = await import(env.configPath); | ||
|
||
configCache.set(env.configPath, imported.default); | ||
const resolvedConfig = { | ||
...imported.default, | ||
...args, | ||
}; | ||
|
||
return imported.default; | ||
configCache.set(env.configPath, resolvedConfig); | ||
|
||
return resolvedConfig; | ||
} |