Skip to content

Commit

Permalink
feat(core): prompt for linter for react
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Nov 15, 2024
1 parent 195ae51 commit e36b91f
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/generated/packages/workspace/generators/new.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"linter": {
"description": "The tool to use for running lint checks.",
"type": "string",
"enum": ["eslint"],
"enum": ["eslint", "none"],
"default": "eslint"
},
"packageManager": {
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/workspace/generators/preset.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"linter": {
"description": "The tool to use for running lint checks.",
"type": "string",
"enum": ["eslint"],
"enum": ["eslint", "none"],
"default": "eslint"
},
"routing": {
Expand Down
24 changes: 24 additions & 0 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface ReactArguments extends BaseArguments {
nextAppDir: boolean;
nextSrcDir: boolean;
e2eTestRunner: 'none' | 'cypress' | 'playwright';
linter?: 'none' | 'eslint';
formatter?: 'none' | 'prettier';
}

Expand Down Expand Up @@ -470,6 +471,27 @@ async function determineFormatterOptions(args: {
return reply.prettier === 'Yes' ? 'prettier' : 'none';
}

async function determineLinterOptions(args: { interactive?: boolean }) {
const reply = await enquirer.prompt<{ eslint: 'Yes' | 'No' }>([
{
name: 'eslint',
message: `Would you like to use ESLint?`,
type: 'autocomplete',
choices: [
{
name: 'Yes',
},
{
name: 'No',
},
],
initial: 1,
skip: !args.interactive || isCI(),
},
]);
return reply.eslint === 'Yes' ? 'eslint' : 'none';
}

async function determineNoneOptions(
parsedArgs: yargs.Arguments<NoneArguments>
): Promise<Partial<NoneArguments>> {
Expand Down Expand Up @@ -647,6 +669,7 @@ async function determineReactOptions(
style = reply.style;
}

const linter = await determineLinterOptions(parsedArgs);
const formatter = await determineFormatterOptions(parsedArgs);

return {
Expand All @@ -657,6 +680,7 @@ async function determineReactOptions(
nextAppDir,
nextSrcDir,
e2eTestRunner,
linter,
formatter,
};
}
Expand Down
11 changes: 11 additions & 0 deletions packages/js/src/utils/typescript/ts-solution-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@nx/devkit';
import { FsTree } from 'nx/src/generators/tree';
import { isUsingPackageManagerWorkspaces } from '../package-manager-workspaces';
import { relative } from 'node:path/posix';

export function isUsingTypeScriptPlugin(tree: Tree): boolean {
const nxJson = readNxJson(tree);
Expand Down Expand Up @@ -113,6 +114,8 @@ export function updateTsconfigFiles(
const offset = offsetFromRoot(projectRoot);
const tsconfig = `${projectRoot}/${runtimeTsconfigFileName}`;
const tsconfigSpec = `${projectRoot}/tsconfig.spec.json`;
const e2eRoot = `${projectRoot}-e2e`;
const tsconfigE2E = `${e2eRoot}/tsconfig.json`;

if (tree.exists(tsconfig)) {
updateJson(tree, tsconfig, (json) => {
Expand Down Expand Up @@ -151,6 +154,14 @@ export function updateTsconfigFiles(
});
}

if (tree.exists(tsconfigE2E)) {
// tsconfig.json for e2e projects need to have references array
updateJson(tree, tsconfigE2E, (json) => {
json.references ??= [];
return json;
});
}

if (tree.exists('tsconfig.json')) {
updateJson(tree, 'tsconfig.json', (json) => {
const projectPath = './' + projectRoot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,7 @@ describe('app (legacy)', () => {
"**/*.cy.jsx",
"**/*.d.ts",
],
"references": [],
}
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,7 @@ describe('app', () => {
"src/**/*.test.js",
"src/**/*.d.ts",
],
"references": [],
}
`);
});
Expand Down
30 changes: 23 additions & 7 deletions packages/react/src/generators/application/lib/add-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,29 @@ export async function addE2e(
const { configurationGenerator } = ensurePackage<
typeof import('@nx/playwright')
>('@nx/playwright', nxVersion);
addProjectConfiguration(tree, options.e2eProjectName, {
projectType: 'application',
root: options.e2eProjectRoot,
sourceRoot: joinPathFragments(options.e2eProjectRoot, 'src'),
targets: {},
implicitDependencies: [options.projectName],
});
if (options.isUsingTsSolutionConfig) {
writeJson(
tree,
joinPathFragments(options.e2eProjectRoot, 'package.json'),
{
name: options.e2eProjectName,
version: '0.0.1',
private: true,
nx: {
name: options.e2eProjectName,
},
}
);
} else {
addProjectConfiguration(tree, options.e2eProjectName, {
projectType: 'application',
root: options.e2eProjectRoot,
sourceRoot: joinPathFragments(options.e2eProjectRoot, 'src'),
targets: {},
implicitDependencies: [options.projectName],
});
}

const e2eTask = await configurationGenerator(tree, {
project: options.e2eProjectName,
skipFormat: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ describe('Remix Application', () => {
"src/**/*.test.js",
"src/**/*.d.ts",
],
"references": [],
}
`);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/workspace/src/generators/new/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"linter": {
"description": "The tool to use for running lint checks.",
"type": "string",
"enum": ["eslint"],
"enum": ["eslint", "none"],
"default": "eslint"
},
"packageManager": {
Expand Down
2 changes: 1 addition & 1 deletion packages/workspace/src/generators/preset/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"linter": {
"description": "The tool to use for running lint checks.",
"type": "string",
"enum": ["eslint"],
"enum": ["eslint", "none"],
"default": "eslint"
},
"routing": {
Expand Down

0 comments on commit e36b91f

Please sign in to comment.