feat(js): added a minimal option to the library generator (#13561)
This commit is contained in:
parent
c956435133
commit
8c1d035b0b
@ -122,6 +122,11 @@
|
||||
"type": "boolean",
|
||||
"description": "Whether to skip TypeScript type checking for SWC compiler.",
|
||||
"default": false
|
||||
},
|
||||
"minimal": {
|
||||
"type": "boolean",
|
||||
"description": "Generate a library with a minimal setup. No README.md generated.",
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"required": ["name"],
|
||||
|
||||
@ -1100,4 +1100,56 @@ describe('lib', () => {
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('--minimal', () => {
|
||||
it('should generate a README.md when minimal is set to false', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
minimal: false,
|
||||
});
|
||||
|
||||
expect(tree.exists('libs/my-lib/README.md')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not generate a README.md when minimal is set to true', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
minimal: true,
|
||||
});
|
||||
|
||||
expect(tree.exists('libs/my-lib/README.md')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should generate a README.md and add it to the build assets when buildable is true and minimal is false', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
bundler: 'tsc',
|
||||
minimal: false,
|
||||
});
|
||||
|
||||
expect(tree.exists('libs/my-lib/README.md')).toBeTruthy();
|
||||
|
||||
const project = readProjectConfiguration(tree, 'my-lib');
|
||||
expect(project.targets.build.options.assets).toStrictEqual([
|
||||
'libs/my-lib/*.md',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not generate a README.md when both bundler and minimal are set', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
bundler: 'tsc',
|
||||
minimal: true,
|
||||
});
|
||||
|
||||
expect(tree.exists('libs/my-lib/README.md')).toBeFalsy();
|
||||
|
||||
const project = readProjectConfiguration(tree, 'my-lib');
|
||||
expect(project.targets.build.options.assets).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -158,9 +158,7 @@ function addProject(
|
||||
outputPath,
|
||||
main: `${options.projectRoot}/src/index` + (options.js ? '.js' : '.ts'),
|
||||
tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
|
||||
// TODO(jack): assets for rollup have validation that we need to fix (assets must be under <project-root>/src)
|
||||
assets:
|
||||
options.bundler === 'rollup' ? [] : [`${options.projectRoot}/*.md`],
|
||||
assets: [],
|
||||
},
|
||||
};
|
||||
|
||||
@ -173,6 +171,17 @@ function addProject(
|
||||
projectConfiguration.targets.build.options.skipTypeCheck = true;
|
||||
}
|
||||
|
||||
if (
|
||||
!options.minimal &&
|
||||
// TODO(jack): assets for rollup have validation that we need to fix (assets must be under <project-root>/src)
|
||||
options.bundler !== 'rollup'
|
||||
) {
|
||||
projectConfiguration.targets.build.options.assets ??= [];
|
||||
projectConfiguration.targets.build.options.assets.push(
|
||||
joinPathFragments(options.projectRoot, '*.md')
|
||||
);
|
||||
}
|
||||
|
||||
if (options.publishable) {
|
||||
const publishScriptPath = addMinimalPublishScript(tree);
|
||||
|
||||
@ -305,6 +314,10 @@ function createFiles(tree: Tree, options: NormalizedSchema, filesDir: string) {
|
||||
tree.delete(packageJsonPath);
|
||||
}
|
||||
|
||||
if (options.minimal) {
|
||||
tree.delete(join(options.projectRoot, 'README.md'));
|
||||
}
|
||||
|
||||
updateTsConfig(tree, options);
|
||||
}
|
||||
|
||||
@ -441,6 +454,8 @@ function normalizeOptions(
|
||||
const importPath =
|
||||
options.importPath || getImportPath(npmScope, projectDirectory);
|
||||
|
||||
options.minimal ??= false;
|
||||
|
||||
return {
|
||||
...options,
|
||||
fileName,
|
||||
|
||||
@ -122,6 +122,11 @@
|
||||
"type": "boolean",
|
||||
"description": "Whether to skip TypeScript type checking for SWC compiler.",
|
||||
"default": false
|
||||
},
|
||||
"minimal": {
|
||||
"type": "boolean",
|
||||
"description": "Generate a library with a minimal setup. No README.md generated.",
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"required": ["name"],
|
||||
|
||||
1
packages/js/src/utils/schema.d.ts
vendored
1
packages/js/src/utils/schema.d.ts
vendored
@ -31,6 +31,7 @@ export interface LibraryGeneratorSchema {
|
||||
compiler?: Compiler;
|
||||
bundler?: Bundler;
|
||||
skipTypeCheck?: boolean;
|
||||
minimal?: boolean;
|
||||
}
|
||||
|
||||
export interface ExecutorOptions {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user