Skip to content

Commit

Permalink
Add workspace shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
vilicvane committed Aug 3, 2023
1 parent 8dadede commit 877636c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 14 additions & 6 deletions general/src/composables/package.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,26 @@ export default composable<ResolvedOptions>(

const devDependencies = await fetchPackageVersions(DEV_DEPENDENCY_DICT);

const scripts: Record<string, string> = {
'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
? {
Expand Down
6 changes: 5 additions & 1 deletion general/src/library/boilerplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const Options = x.object({
export type Options = x.TypeOf<typeof Options>;

export interface ResolvedPackageOptions extends PackageOptions {
alias?: string;
resolvedDir: string;
packageJSONPath: string;
}
Expand Down Expand Up @@ -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'),
};
Expand Down

0 comments on commit 877636c

Please sign in to comment.