-
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: cli bin init and NX integrated (#14)
- Loading branch information
1 parent
16c28b3
commit 553bef9
Showing
16 changed files
with
925 additions
and
40 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
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 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,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 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,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 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,27 @@ | ||
import { logger } from '../utils/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 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 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 * from './utils/logger'; | ||
export * from './utils/helper'; | ||
|
||
export type { RslibConfig } from './types'; | ||
|
||
export const version = RSLIB_VERSION; |
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,3 @@ | ||
import color from 'picocolors'; | ||
|
||
export { color }; |
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,39 @@ | ||
import { type Logger, logger } from 'rslog'; | ||
import { color } from './helper'; | ||
|
||
// 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 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.