diff --git a/general/src/composables/package.json.ts b/general/src/composables/package.json.ts index 8169364..929f2ca 100644 --- a/general/src/composables/package.json.ts +++ b/general/src/composables/package.json.ts @@ -93,18 +93,26 @@ export default composable( const devDependencies = await fetchPackageVersions(DEV_DEPENDENCY_DICT); + const scripts: Record = { + '3': 'yarn && yarn-deduplicate && yarn', + lint: 'eslint --no-error-on-unmatched-pattern .', + 'lint-prettier': 'prettier --check .', + test: 'yarn lint-prettier && yarn lint', + }; + + for (const {name, alias} of packages) { + if (alias !== undefined && !scripts.hasOwnProperty(alias)) { + scripts[alias] = `yarn workspace ${name}`; + } + } + return [ json( 'package.json', { name, description, - scripts: { - '3': 'yarn && yarn-deduplicate && yarn', - lint: 'eslint --no-error-on-unmatched-pattern .', - 'lint-prettier': 'prettier --check .', - test: 'yarn lint-prettier && yarn lint', - }, + scripts, devDependencies, ...(packagesDir !== undefined ? { diff --git a/general/src/library/boilerplate.ts b/general/src/library/boilerplate.ts index f80ad86..a6a5912 100644 --- a/general/src/library/boilerplate.ts +++ b/general/src/library/boilerplate.ts @@ -84,6 +84,7 @@ export const Options = x.object({ export type Options = x.TypeOf; export interface ResolvedPackageOptions extends PackageOptions { + alias?: string; resolvedDir: string; packageJSONPath: string; } @@ -113,13 +114,16 @@ export function resolveOptions({ } resolvedPackages = (packages ?? []).map(packageOptions => { + const alias = packageOptions.name.replace(/^@[^/]+\//, ''); + const resolvedDir = Path.posix.join( packagesDir!, - packageOptions.dir || packageOptions.name.replace(/^@[^/]+/, ''), + packageOptions.dir || alias, ); return { ...packageOptions, + alias, resolvedDir, packageJSONPath: Path.posix.join(resolvedDir, 'package.json'), };