Skip to content

Commit

Permalink
feat(js): adding simpleName option to library generator
Browse files Browse the repository at this point in the history
closed #15564
  • Loading branch information
ashley-hunter authored and AgentEnder committed Mar 31, 2023
1 parent bfea455 commit 2e961e2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
5 changes: 5 additions & 0 deletions docs/generated/packages/js/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@
"type": "boolean",
"description": "Generate a library with a minimal setup. No README.md generated.",
"default": false
},
"simpleName": {
"description": "Don't include the directory in the generated file name.",
"type": "boolean",
"default": false
}
},
"required": ["name"],
Expand Down
16 changes: 16 additions & 0 deletions packages/js/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1152,4 +1152,20 @@ describe('lib', () => {
expect(project.targets.build.options.assets).toEqual([]);
});
});

describe('--simpleName', () => {
it('should generate a simple name', async () => {
await libraryGenerator(tree, {
...defaultOptions,
name: 'myLib',
simpleName: true,
});

expect(tree.exists('libs/my-lib/src/index.ts')).toBeTruthy();
expect(tree.read('libs/my-lib/src/index.ts', 'utf-8')).toContain(
`export * from './lib/my-lib';`
);
expect(tree.exists('libs/my-lib/src/lib/my-lib.ts')).toBeTruthy();
});
});
});
11 changes: 6 additions & 5 deletions packages/js/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import {
} from '@nrwl/devkit';
import { getImportPath } from 'nx/src/utils/path';

import {
getRelativePathToRootTsConfig,
updateRootTsConfig,
} from '../../utils/typescript/ts-config';
import { join } from 'path';
import { addMinimalPublishScript } from '../../utils/minimal-publish-script';
import { Bundler, LibraryGeneratorSchema } from '../../utils/schema';
import { addSwcConfig } from '../../utils/swc/add-swc-config';
import { addSwcDependencies } from '../../utils/swc/add-swc-dependencies';
import {
getRelativePathToRootTsConfig,
updateRootTsConfig,
} from '../../utils/typescript/ts-config';
import {
esbuildVersion,
nxVersion,
Expand Down Expand Up @@ -451,7 +451,8 @@ function normalizeOptions(

const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-');
const fileName = getCaseAwareFileName({
fileName: options.simpleModuleName ? name : projectName,
fileName:
options.simpleName || options.simpleModuleName ? name : projectName,
pascalCaseFiles: options.pascalCaseFiles,
});

Expand Down
5 changes: 5 additions & 0 deletions packages/js/src/generators/library/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@
"type": "boolean",
"description": "Generate a library with a minimal setup. No README.md generated.",
"default": false
},
"simpleName": {
"description": "Don't include the directory in the generated file name.",
"type": "boolean",
"default": false
}
},
"required": ["name"],
Expand Down
1 change: 1 addition & 0 deletions packages/js/src/utils/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface LibraryGeneratorSchema {
bundler?: Bundler;
skipTypeCheck?: boolean;
minimal?: boolean;
simpleName?: boolean;
}

export interface ExecutorOptions {
Expand Down

0 comments on commit 2e961e2

Please sign in to comment.