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",
|
"type": "boolean",
|
||||||
"description": "Whether to skip TypeScript type checking for SWC compiler.",
|
"description": "Whether to skip TypeScript type checking for SWC compiler.",
|
||||||
"default": false
|
"default": false
|
||||||
|
},
|
||||||
|
"minimal": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Generate a library with a minimal setup. No README.md generated.",
|
||||||
|
"default": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["name"],
|
"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,
|
outputPath,
|
||||||
main: `${options.projectRoot}/src/index` + (options.js ? '.js' : '.ts'),
|
main: `${options.projectRoot}/src/index` + (options.js ? '.js' : '.ts'),
|
||||||
tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
|
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: [],
|
||||||
assets:
|
|
||||||
options.bundler === 'rollup' ? [] : [`${options.projectRoot}/*.md`],
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -173,6 +171,17 @@ function addProject(
|
|||||||
projectConfiguration.targets.build.options.skipTypeCheck = true;
|
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) {
|
if (options.publishable) {
|
||||||
const publishScriptPath = addMinimalPublishScript(tree);
|
const publishScriptPath = addMinimalPublishScript(tree);
|
||||||
|
|
||||||
@ -305,6 +314,10 @@ function createFiles(tree: Tree, options: NormalizedSchema, filesDir: string) {
|
|||||||
tree.delete(packageJsonPath);
|
tree.delete(packageJsonPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.minimal) {
|
||||||
|
tree.delete(join(options.projectRoot, 'README.md'));
|
||||||
|
}
|
||||||
|
|
||||||
updateTsConfig(tree, options);
|
updateTsConfig(tree, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -441,6 +454,8 @@ function normalizeOptions(
|
|||||||
const importPath =
|
const importPath =
|
||||||
options.importPath || getImportPath(npmScope, projectDirectory);
|
options.importPath || getImportPath(npmScope, projectDirectory);
|
||||||
|
|
||||||
|
options.minimal ??= false;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...options,
|
...options,
|
||||||
fileName,
|
fileName,
|
||||||
|
|||||||
@ -122,6 +122,11 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Whether to skip TypeScript type checking for SWC compiler.",
|
"description": "Whether to skip TypeScript type checking for SWC compiler.",
|
||||||
"default": false
|
"default": false
|
||||||
|
},
|
||||||
|
"minimal": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Generate a library with a minimal setup. No README.md generated.",
|
||||||
|
"default": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["name"],
|
"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;
|
compiler?: Compiler;
|
||||||
bundler?: Bundler;
|
bundler?: Bundler;
|
||||||
skipTypeCheck?: boolean;
|
skipTypeCheck?: boolean;
|
||||||
|
minimal?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ExecutorOptions {
|
export interface ExecutorOptions {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user