Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
diff --git a/src/bin.ts b/src/bin.ts index 3a0e511..0ff6df8 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -3,35 +3,19 @@ import typia from 'typia'; import { dirname, resolve } from 'pathe'; import { readPackageJSON, resolvePackageJSON } from 'pkg-types'; import type { JSR } from './type'; +import { getExclude, getInclude } from './utils'; const pkgJSONPath = await resolvePackageJSON(); const pkgJSON = await readPackageJSON(pkgJSONPath); const rootDir = dirname(pkgJSONPath); const jsrPath = resolve(rootDir, 'jsr.json'); -const isStartWithExclamation = typia.createIs<`!${string}`>(); -const { files } = pkgJSON; -const include = files == null ? ['dist'] : files.filter(file => isStartWithExclamation(file)); -const exclude = files == null - ? undefined - : files - .filter(file => !isStartWithExclamation(file)) - .map((file) => { - if (file.startsWith('!**/')) { - return file.slice(4); - } - if (file.startsWith('!')) { - return file.slice(1); - } - return file; - }); - const jsr = { name: pkgJSON.name as string, version: pkgJSON.version as string, publish: { - include, - exclude, + include: getInclude(pkgJSON), + exclude: getExclude(pkgJSON), }, exports: pkgJSON.exports, }; diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..d6fb053 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,44 @@ +import typia from 'typia'; +import type { PackageJson } from 'pkg-types'; +import { parse } from 'pathe'; + +const isStartWithExclamation = typia.createIs<`!${string}`>(); + +export function getInclude(pkgJSON: PackageJson): string[] | undefined { + const { files } = pkgJSON; + const include = files == null ? ['dist'] : files.filter(file => isStartWithExclamation(file)); + return include; +} + +export function getExclude(pkgJSON: PackageJson): string[] | undefined { + const { files } = pkgJSON; + const exclude = files == null + ? undefined + : files + .filter(file => !isStartWithExclamation(file)) + .map((file) => { + if (file.startsWith('!**/')) { + return file.slice(4); + } + if (file.startsWith('!')) { + return file.slice(1); + } + return file; + }); + return exclude; +} + +function convertDir(path: string, from: string, to: string): string { + const s = sep(path); +} + +export function getExports(pkgJSON: PackageJson): Record<string, string> | string | undefined { + const { exports } = pkgJSON; + if (exports == null) { + return; + } + if (typeof exports === 'string') { + return exports; + } + return exports; +}
- Loading branch information