Skip to content

Commit

Permalink
feat(core): update generated README pages with more useful instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Feb 23, 2024
1 parent 8c6d8a6 commit 81605f5
Show file tree
Hide file tree
Showing 5 changed files with 529 additions and 470 deletions.
39 changes: 28 additions & 11 deletions packages/js/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ export async function libraryGeneratorInternal(
tree: Tree,
schema: LibraryGeneratorSchema
) {
const filesDir = join(__dirname, './files');

const tasks: GeneratorCallback[] = [];
tasks.push(
await jsInitGenerator(tree, {
Expand All @@ -73,7 +71,7 @@ export async function libraryGeneratorInternal(
);
const options = await normalizeOptions(tree, schema);

createFiles(tree, options, `${filesDir}/lib`);
createFiles(tree, options);

addProject(tree, options);

Expand Down Expand Up @@ -119,7 +117,7 @@ export async function libraryGeneratorInternal(
const jestCallback = await addJest(tree, options);
tasks.push(jestCallback);
if (options.bundler === 'swc' || options.bundler === 'rollup') {
replaceJestConfig(tree, options, `${filesDir}/jest-config`);
replaceJestConfig(tree, options);
}
} else if (
options.unitTestRunner === 'vitest' &&
Expand Down Expand Up @@ -419,14 +417,14 @@ function addBabelRc(tree: Tree, options: NormalizedSchema) {
writeJson(tree, join(options.projectRoot, filename), babelrc);
}

function createFiles(tree: Tree, options: NormalizedSchema, filesDir: string) {
function createFiles(tree: Tree, options: NormalizedSchema) {
const { className, name, propertyName } = names(
options.projectNames.projectFileName
);

createProjectTsConfigJson(tree, options);

generateFiles(tree, filesDir, options.projectRoot, {
generateFiles(tree, join(__dirname, './files/lib'), options.projectRoot, {
...options,
dot: '.',
className,
Expand All @@ -441,6 +439,28 @@ function createFiles(tree: Tree, options: NormalizedSchema, filesDir: string) {
hasUnitTestRunner: options.unitTestRunner !== 'none',
});

if (!options.rootProject) {
generateFiles(
tree,
join(__dirname, './files/readme'),
options.projectRoot,
{
...options,
dot: '.',
className,
name,
propertyName,
js: !!options.js,
cliCommand: 'nx',
strict: undefined,
tmpl: '',
offsetFromRoot: offsetFromRoot(options.projectRoot),
buildable: options.bundler && options.bundler !== 'none',
hasUnitTestRunner: options.unitTestRunner !== 'none',
}
);
}

if (options.bundler === 'swc' || options.bundler === 'rollup') {
addSwcDependencies(tree);
addSwcConfig(
Expand Down Expand Up @@ -539,11 +559,8 @@ async function addJest(
});
}

function replaceJestConfig(
tree: Tree,
options: NormalizedSchema,
filesDir: string
) {
function replaceJestConfig(tree: Tree, options: NormalizedSchema) {
const filesDir = join(__dirname, './files/jest-config');
// the existing config has to be deleted otherwise the new config won't overwrite it
const existingJestConfig = joinPathFragments(
filesDir,
Expand Down

0 comments on commit 81605f5

Please sign in to comment.