-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
--root
cli option and make basic js api work
- Loading branch information
1 parent
17f7c6e
commit 824dfe9
Showing
17 changed files
with
225 additions
and
75 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,26 @@ | ||
import { type RsbuildInstance, createRsbuild } from '@rsbuild/core'; | ||
import { composeRsbuildEnvironments, pruneEnvironments } from '../config'; | ||
import type { RslibConfig } from '../types/config'; | ||
import { getAbsolutePath } from '../utils/helper'; | ||
import type { BuildOptions } from './commands'; | ||
|
||
export async function build( | ||
config: RslibConfig, | ||
options: Pick<BuildOptions, 'root' | 'lib' | 'watch'> = {}, | ||
): Promise<RsbuildInstance> { | ||
const cwd = process.cwd(); | ||
options.root = options.root ? getAbsolutePath(cwd, options.root) : cwd; | ||
|
||
const environments = await composeRsbuildEnvironments(config, options.root); | ||
const rsbuildInstance = await createRsbuild({ | ||
rsbuildConfig: { | ||
environments: pruneEnvironments(environments, options.lib), | ||
}, | ||
}); | ||
|
||
await rsbuildInstance.build({ | ||
watch: options.watch, | ||
}); | ||
|
||
return rsbuildInstance; | ||
} |
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,19 @@ | ||
import { loadConfig } from '../config'; | ||
import type { RslibConfig } from '../types'; | ||
import { getAbsolutePath } from '../utils/helper'; | ||
import type { CommonOptions } from './commands'; | ||
|
||
export async function getRslibConfig( | ||
options: CommonOptions, | ||
): Promise<{ root: string; rslibConfig: RslibConfig }> { | ||
const cwd = process.cwd(); | ||
const root = options.root ? getAbsolutePath(cwd, options.root) : cwd; | ||
|
||
const rslibConfig = await loadConfig({ | ||
cwd: root, | ||
path: options.config, | ||
envMode: options.envMode, | ||
}); | ||
|
||
return { root, rslibConfig }; | ||
} |
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,32 @@ | ||
import { type RsbuildInstance, createRsbuild } from '@rsbuild/core'; | ||
import { composeRsbuildEnvironments, pruneEnvironments } from '../config'; | ||
import type { RslibConfig } from '../types/config'; | ||
import { getAbsolutePath } from '../utils/helper'; | ||
import type { InspectOptions } from './commands'; | ||
|
||
export async function inspect( | ||
config: RslibConfig, | ||
options: Pick< | ||
InspectOptions, | ||
'root' | 'lib' | 'mode' | 'output' | 'verbose' | ||
> = {}, | ||
): Promise<RsbuildInstance> { | ||
const cwd = process.cwd(); | ||
options.root = options.root ? getAbsolutePath(cwd, options.root) : cwd; | ||
|
||
const environments = await composeRsbuildEnvironments(config, options.root); | ||
const rsbuildInstance = await createRsbuild({ | ||
rsbuildConfig: { | ||
environments: pruneEnvironments(environments, options.lib), | ||
}, | ||
}); | ||
|
||
await rsbuildInstance.inspectConfig({ | ||
mode: options.mode, | ||
verbose: options.verbose, | ||
outputPath: options.output, | ||
writeToDisk: true, | ||
}); | ||
|
||
return rsbuildInstance; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.