Skip to content

Commit

Permalink
feat: use default library prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
bejewel-kyoungmin committed Sep 26, 2023
1 parent 75c30e7 commit 92bd04f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/lib/library/library.factory.ts
Expand Up @@ -13,6 +13,7 @@ import {
url,
} from '@angular-devkit/schematics';
import { parse } from 'jsonc-parser';
import { readFileSync } from 'fs';
import { normalizeToKebabOrSnakeCase } from '../../utils/formatting';
import {
DEFAULT_LANGUAGE,
Expand Down Expand Up @@ -43,6 +44,20 @@ export function main(options: LibraryOptions): Rule {
]);
}

function getDefaultLibraryPrefix(defaultLibraryPrefix = '@app') {
try {
const nestCliJson = JSON.parse(
readFileSync('./nest-cli.json', 'utf-8'),
);
if (nestCliJson.hasOwnProperty('defaultLibraryPrefix')) {
return nestCliJson['defaultLibraryPrefix'];
}
} catch (e) {
}

return defaultLibraryPrefix;
}

function transform(options: LibraryOptions): LibraryOptions {
const target: LibraryOptions = Object.assign({}, options);
const defaultSourceRoot =
Expand All @@ -58,7 +73,7 @@ function transform(options: LibraryOptions): LibraryOptions {
? join(normalize(defaultSourceRoot), target.path)
: normalize(defaultSourceRoot);

target.prefix = target.prefix || '@app';
target.prefix = target.prefix || getDefaultLibraryPrefix();
return target;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/library/schema.json
Expand Up @@ -16,7 +16,7 @@
"prefix": {
"type": "string",
"description": "The prefix of the library.",
"x-prompt": "What prefix would you like to use for the library (default: @app)?"
"x-prompt": "What prefix would you like to use for the library (default: defaultLibraryPrefix or @app)?"
},
"language": {
"type": "string",
Expand Down

0 comments on commit 92bd04f

Please sign in to comment.