-
-
Notifications
You must be signed in to change notification settings - Fork 57
feat: cli bin init and NX integrated #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 @@ | ||
| { | ||
| "$schema": "./node_modules/nx/schemas/nx-schema.json", | ||
| "namedInputs": { | ||
| "default": ["{projectRoot}/src/**/*"], | ||
| "build": [ | ||
| "default", | ||
| "!{projectRoot}/**/*.{md,mdx}", | ||
| "{projectRoot}/tsconfig.json", | ||
| "{projectRoot}/package.json", | ||
| "{projectRoot}/modern.config.*", | ||
| "{projectRoot}/scripts/**/*" | ||
| ], | ||
| "prebundle": [ | ||
| "{projectRoot}/package.json", | ||
| "{projectRoot}/prebundle.config.mjs" | ||
| ] | ||
| }, | ||
| "targetDefaults": { | ||
| "build": { | ||
| "cache": true, | ||
| "dependsOn": ["^build", "prebundle"], | ||
| "inputs": ["build", "^build"], | ||
| "outputs": ["{projectRoot}/dist", "{projectRoot}/dist-types"] | ||
| }, | ||
| "prebundle": { | ||
| "cache": true, | ||
| "inputs": ["prebundle"], | ||
| "outputs": ["{projectRoot}/compiled"] | ||
| } | ||
| }, | ||
| "defaultBase": "main" | ||
| } |
This file contains hidden or 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 hidden or 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,8 +1,14 @@ | ||
| #!/usr/bin/env node | ||
| import { runCli } from '../dist/index.js'; | ||
| import { logger, prepareCli, runCli } from '../dist/index.js'; | ||
|
|
||
| async function main() { | ||
| runCli(); | ||
| prepareCli(); | ||
|
|
||
| try { | ||
| runCli(); | ||
| } catch (err) { | ||
| logger.error(err); | ||
| } | ||
| } | ||
|
|
||
| main(); |
This file contains hidden or 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 hidden or 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 hidden or 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,27 @@ | ||
| // @ts-check | ||
| import { join } from 'node:path'; | ||
| import fs from 'fs-extra'; | ||
|
|
||
| /** | ||
| * Tip: please add the prebundled packages to `tsconfig.json#paths`. | ||
| */ | ||
|
|
||
| /** @type {import('prebundle').Config} */ | ||
| export default { | ||
| externals: { | ||
| typescript: 'typescript', | ||
| }, | ||
| dependencies: [ | ||
| 'commander', | ||
| { | ||
| name: 'picocolors', | ||
| beforeBundle({ depPath }) { | ||
| const typesFile = join(depPath, 'types.ts'); | ||
| // Fix type bundle | ||
| if (fs.existsSync(typesFile)) { | ||
| fs.renameSync(typesFile, join(depPath, 'types.d.ts')); | ||
| } | ||
| }, | ||
| }, | ||
| ], | ||
| }; |
This file contains hidden or 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 hidden or 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,27 @@ | ||
| import { logger } from '../shared/logger'; | ||
|
|
||
| function initNodeEnv() { | ||
| if (!process.env.NODE_ENV) { | ||
| const command = process.argv[2] ?? ''; | ||
| process.env.NODE_ENV = ['build'].includes(command) | ||
| ? 'production' | ||
| : 'development'; | ||
| } | ||
| } | ||
|
|
||
| export function prepareCli() { | ||
| initNodeEnv(); | ||
|
|
||
| // Print a blank line to keep the greet log nice. | ||
| // Some package managers automatically output a blank line, some do not. | ||
| const { npm_execpath } = process.env; | ||
| if ( | ||
| !npm_execpath || | ||
| npm_execpath.includes('npx-cli.js') || | ||
| npm_execpath.includes('.bun') | ||
| ) { | ||
| console.log(); | ||
| } | ||
|
|
||
| logger.greet(` ${`Rslib v${RSLIB_VERSION}`}\n`); | ||
| } |
This file contains hidden or 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 @@ | ||
| declare const RSLIB_VERSION; |
This file contains hidden or 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,8 +1,10 @@ | ||
| /** | ||
| * The project structure and implementation of Rslib is a placeholder. | ||
| * Only to setup the basic infrastructure workflow. | ||
| */ | ||
|
|
||
| export { build } from './build'; | ||
| export { runCli } from './cli'; | ||
| export { runCli } from './cli/commands'; | ||
| export { prepareCli } from './cli/prepare'; | ||
|
|
||
| export type { RslibConfig } from './types'; | ||
|
|
||
| export * from './shared/logger'; | ||
| export * from './shared/utils'; | ||
|
|
||
| export const version = RSLIB_VERSION; | ||
This file contains hidden or 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,39 @@ | ||
| import { type Logger, logger } from 'rslog'; | ||
| import { color } from './utils'; | ||
|
|
||
| // setup the logger level | ||
| if (process.env.DEBUG) { | ||
| logger.level = 'verbose'; | ||
| } | ||
|
|
||
| export const isDebug = () => { | ||
| if (!process.env.DEBUG) { | ||
| return false; | ||
| } | ||
|
|
||
| logger.level = 'verbose'; // support `process.env.DEBUG` in e2e | ||
| const values = process.env.DEBUG.toLocaleLowerCase().split(','); | ||
| return ['rslib', 'rsbuild', 'builder', '*'].some((key) => | ||
| values.includes(key), | ||
| ); | ||
| }; | ||
|
|
||
| function getTime() { | ||
| const now = new Date(); | ||
| const hours = String(now.getHours()).padStart(2, '0'); | ||
| const minutes = String(now.getMinutes()).padStart(2, '0'); | ||
| const seconds = String(now.getSeconds()).padStart(2, '0'); | ||
|
|
||
| return `${hours}:${minutes}:${seconds}`; | ||
| } | ||
|
|
||
| export const debug = (message: string | (() => string)) => { | ||
| if (isDebug()) { | ||
| const result = typeof message === 'string' ? message : message(); | ||
| const time = color.gray(`${getTime()}`); | ||
| logger.debug(`${time} ${result}`); | ||
| } | ||
| }; | ||
|
|
||
| export { logger }; | ||
| export type { Logger }; |
This file contains hidden or 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,3 @@ | ||
| import color from 'picocolors'; | ||
|
|
||
| export { color }; |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.