@favware/rollup-type-bundler
Advanced tools
Comparing version 0.0.1-next.7197883.0 to 0.0.1-next.7953008.0
@@ -10,2 +10,3 @@ #!/usr/bin/env node | ||
import { fileExistsAsync } from '#lib/promisified'; | ||
import { doActionAndLog } from '#lib/utils'; | ||
import { cyan } from 'colorette'; | ||
@@ -20,3 +21,3 @@ import { Command } from 'commander'; | ||
.version(packageJson.version) | ||
.requiredOption('-d, --dist <dist>', 'The dist directory to target') | ||
.option('-d, --dist <dist>', 'The dist directory to target') | ||
.option('-b, --build-script [buildScript]', 'The build script to call after cleaning your dist directory', 'build') | ||
@@ -35,4 +36,3 @@ .option('-v, --verbose', 'Print verbose information', false) | ||
const packageJsonPath = join(packageCwd, 'package.json'); | ||
const packageJsonExistsInCwd = await fileExistsAsync(packageJsonPath); | ||
logVerboseInfo(['Checking if package.json exists in the current working directory'], options.verbose); | ||
const packageJsonExistsInCwd = await doActionAndLog('Checking if package.json exists in the current working directory', fileExistsAsync(packageJsonPath)); | ||
if (!packageJsonExistsInCwd) { | ||
@@ -51,4 +51,3 @@ logVerboseError({ | ||
*/ | ||
logVerboseInfo(['Cleaning the configured "dist" path'], options.verbose); | ||
await cleanDist(options); | ||
await doActionAndLog('Cleaning the configured "dist" path', cleanDist(options)); | ||
/** | ||
@@ -59,4 +58,3 @@ |---------------------------------------------------------------------------------| | ||
*/ | ||
logVerboseInfo(['Compiling your TypeScript source code'], options.verbose); | ||
await buildCode(options); | ||
await doActionAndLog('Compiling your TypeScript source code', buildCode(options)); | ||
/** | ||
@@ -67,4 +65,3 @@ |-------------------------------------| | ||
*/ | ||
logVerboseInfo(['Bundling TypeScript types'], options.verbose); | ||
await bundleTypes(options); | ||
await doActionAndLog('Bundling TypeScript types', bundleTypes(options)); | ||
/** | ||
@@ -75,4 +72,3 @@ |-------------------------------------------------| | ||
*/ | ||
logVerboseInfo(['Cleaning extraneous types from the "dist" path'], options.verbose); | ||
await cleanExtraneousTypes(options); | ||
await doActionAndLog('Cleaning extraneous types from the "dist" path', cleanExtraneousTypes(options)); | ||
//# sourceMappingURL=cli.js.map |
@@ -22,4 +22,4 @@ import { indent, packageCwd } from '#lib/constants'; | ||
'An error occurred while building the TypeScript code', | ||
`${indent}If you provided a custom build script with "-b" or "--build-script", or through "buildScript" in a config file, then make that script actually exists in your "package.json"`, | ||
`${indent}If you did not provide this option, then make sure there is a script called "build" in your "package.json"` | ||
`${indent}If you provided a custom build script with "-b" or "--build-script", or through "buildScript" in a config file, then make that script actually exists in your "package.json".`, | ||
`${indent}If you did not provide this option, then make sure there is a script called "build" in your "package.json".` | ||
], | ||
@@ -32,3 +32,3 @@ verbose: options.verbose, | ||
].filter(Boolean), | ||
exitAfterLog: true | ||
logWithThrownError: true | ||
}); | ||
@@ -35,0 +35,0 @@ } |
import { fileExistsAsync } from '#lib/promisified'; | ||
import { join } from 'path'; | ||
import { rollup } from 'rollup'; | ||
import dts from 'rollup-plugin-dts'; | ||
import { fileURLToPath, URL } from 'url'; | ||
import { setTimeout as sleep } from 'timers/promises'; | ||
import { fileURLToPath } from 'url'; | ||
/** | ||
@@ -11,3 +12,3 @@ * Bundles all the TypeScript types with {@link rollup} | ||
export async function bundleTypes(options) { | ||
const typingsFile = fileURLToPath(new URL('index.d.ts', options.dist)); | ||
const typingsFile = join(fileURLToPath(options.dist), 'index.d.ts'); | ||
// Sleep repeated 1 second until the `index.d.ts` file exists | ||
@@ -14,0 +15,0 @@ do { |
@@ -16,3 +16,3 @@ import { rm } from 'fs/promises'; | ||
verboseText: ['The error message that was thrown is: ', error], | ||
exitAfterLog: true | ||
logWithThrownError: true | ||
}); | ||
@@ -19,0 +19,0 @@ } |
@@ -39,6 +39,6 @@ import { logVerboseError } from '#lib/logVerbose'; | ||
logVerboseError({ | ||
text: ['An error occurred while removing one or more of the extraneous types from the `dist` directory', 'Please remove them manually'], | ||
text: ['An error occurred while removing one or more of the extraneous types from the `dist` directory.', 'Please remove them manually'], | ||
verbose: options.verbose, | ||
verboseText: ['I was scanning this dist path: ', options.dist.toString(), 'Furthermore, the exact error that occurred is: ', err], | ||
exitAfterLog: true | ||
logWithThrownError: true | ||
}); | ||
@@ -45,0 +45,0 @@ } |
@@ -10,9 +10,9 @@ import { join } from 'path'; | ||
/** Path to the config file in .json format */ | ||
export const rollupTypeBundlerRcJsonPath = join(rollupTypeBundlerRcPath, '.json'); | ||
export const rollupTypeBundlerRcJsonPath = `${rollupTypeBundlerRcPath}.json`; | ||
/** Path to the config file in .yml format */ | ||
export const rollupTypeBundlerRcYmlPath = join(rollupTypeBundlerRcPath, '.yml'); | ||
export const rollupTypeBundlerRcYmlPath = `${rollupTypeBundlerRcPath}.yml`; | ||
/** Path to the config file in .yaml format */ | ||
export const rollupTypeBundlerRcYamlPath = join(rollupTypeBundlerRcPath, '.yaml'); | ||
export const rollupTypeBundlerRcYamlPath = `${rollupTypeBundlerRcPath}.yaml`; | ||
/** 4 spaces indent for logging */ | ||
export const indent = ' '.repeat(4); | ||
//# sourceMappingURL=constants.js.map |
@@ -5,3 +5,3 @@ /** | ||
*/ | ||
export declare function logVerboseError({ text, verbose, verboseText, exitAfterLog: exitOnLog }: LogVerboseErrorOptions): void; | ||
export declare function logVerboseError({ text, verbose, verboseText, exitAfterLog, logWithThrownError }: LogVerboseErrorOptions): void; | ||
export declare function logVerboseInfo(text: string[], verbose?: boolean): void; | ||
@@ -20,4 +20,6 @@ /** | ||
exitAfterLog?: boolean; | ||
/** Whether instead of using `console.error` this should use `throw new Error` */ | ||
logWithThrownError?: boolean; | ||
} | ||
export {}; | ||
//# sourceMappingURL=logVerbose.d.ts.map |
@@ -6,9 +6,14 @@ import { cyan, red } from 'colorette'; | ||
*/ | ||
export function logVerboseError({ text, verbose = false, verboseText = [], exitAfterLog: exitOnLog = false }) { | ||
let combinedText = text; | ||
export function logVerboseError({ text, verbose = false, verboseText = [], exitAfterLog = false, logWithThrownError = false }) { | ||
if (verbose) { | ||
combinedText = combinedText.concat(verboseText); | ||
text = text.concat(verboseText); | ||
} | ||
console.error(red(combinedText.join('\n'))); | ||
if (exitOnLog) { | ||
const message = red(text.join('\n')); | ||
if (logWithThrownError) { | ||
throw new Error(message); | ||
} | ||
else { | ||
console.error('\n', message); | ||
} | ||
if (exitAfterLog && !logWithThrownError) { | ||
process.exit(1); | ||
@@ -19,5 +24,5 @@ } | ||
if (verbose) { | ||
console.info(cyan(text.join('\n'))); | ||
console.log(cyan(text.join('\n'))); | ||
} | ||
} | ||
//# sourceMappingURL=logVerbose.js.map |
@@ -37,3 +37,4 @@ import { packageCwd, rollupTypeBundlerRcJsonPath, rollupTypeBundlerRcPath, rollupTypeBundlerRcYamlPath, rollupTypeBundlerRcYmlPath } from '#lib/constants'; | ||
err | ||
] | ||
], | ||
exitAfterLog: true | ||
}); | ||
@@ -61,3 +62,4 @@ } | ||
err | ||
] | ||
], | ||
exitAfterLog: true | ||
}); | ||
@@ -75,2 +77,11 @@ } | ||
const distPath = Reflect.get(options, 'dist'); | ||
if (!distPath) { | ||
logVerboseError({ | ||
text: [ | ||
'You did not provide a path to your "dist" folder. Please do so either with the "--dist" flag, or by creating a config file.', | ||
"For more information, see this project's README here: https://github.com/favware/rollup-type-bundler#usage " | ||
], | ||
exitAfterLog: true | ||
}); | ||
} | ||
return { | ||
@@ -77,0 +88,0 @@ ...options, |
@@ -13,2 +13,3 @@ /// <reference types="node" /> | ||
export declare function readJson<T>(pathLike: PathLike): Promise<T>; | ||
export declare function doActionAndLog<T>(preActionLog: string, action: Promise<T>): Promise<T>; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -0,1 +1,2 @@ | ||
import { cyan, green, red } from 'colorette'; | ||
import { readFile } from 'fs/promises'; | ||
@@ -17,2 +18,15 @@ import { load } from 'js-yaml'; | ||
} | ||
export async function doActionAndLog(preActionLog, action) { | ||
process.stdout.write(cyan(`${preActionLog}... `)); | ||
try { | ||
const returnValue = (await action); | ||
console.log(green('✅ Done')); | ||
return returnValue; | ||
} | ||
catch (error) { | ||
console.log(red('❌ Error')); | ||
console.error(error.message); | ||
process.exit(1); | ||
} | ||
} | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@favware/rollup-type-bundler", | ||
"version": "0.0.1-next.7197883.0", | ||
"version": "0.0.1-next.7953008.0", | ||
"description": "A small CLI tool to bundle types with rollup", | ||
@@ -5,0 +5,0 @@ "author": "@favware", |
@@ -8,3 +8,2 @@ <div align="center"> | ||
[![GitHub](https://img.shields.io/github/license/favware/rollup-type-bundler)](https://github.com/favware/rollup-type-bundler/blob/main/LICENSE) | ||
[![npm bundle size](https://img.shields.io/bundlephobia/min/@favware/rollup-type-bundler?logo=webpack&style=flat-square)](https://bundlephobia.com/result?p=@favware/rollup-type-bundler) | ||
[![npm](https://img.shields.io/npm/v/@favware/rollup-type-bundler?color=crimson&logo=npm)](https://www.npmjs.com/package/@favware/rollup-type-bundler) | ||
@@ -186,2 +185,3 @@ [![Depfu](https://badges.depfu.com/badges/97d09026f35f8886a8bca2e8c7caa533/count.svg)](https://depfu.com/github/favware/rollup-type-bundler?project_id=28226) | ||
<td align="center"><a href="https://favware.tech/"><img src="https://avatars3.githubusercontent.com/u/4019718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeroen Claassens</b></sub></a><br /><a href="https://github.com/favware/rollup-type-bundler/commits?author=Favna" title="Code">💻</a> <a href="#design-Favna" title="Design">🎨</a> <a href="#ideas-Favna" title="Ideas, Planning, & Feedback">🤔</a> <a href="#infra-Favna" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-Favna" title="Maintenance">🚧</a> <a href="#platform-Favna" title="Packaging/porting to new platform">📦</a> <a href="#projectManagement-Favna" title="Project Management">📆</a></td> | ||
<td align="center"><a href="https://github.com/Nytelife26"><img src="https://avatars.githubusercontent.com/u/22531310?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tyler J Russell</b></sub></a><br /><a href="https://github.com/favware/rollup-type-bundler/commits?author=Nytelife26" title="Documentation">📖</a></td> | ||
</tr> | ||
@@ -188,0 +188,0 @@ </table> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46081
447