feat(nextjs): add --js flag support
This commit is contained in:
parent
70cbe71db4
commit
7f70f3a153
@ -54,6 +54,14 @@ Possible values: `cypress`, `none`
|
||||
|
||||
Test runner to use for end to end (e2e) tests
|
||||
|
||||
### js
|
||||
|
||||
Default: `false`
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Generate JavaScript files rather than TypeScript files.
|
||||
|
||||
### linter
|
||||
|
||||
Default: `eslint`
|
||||
|
||||
@ -54,6 +54,14 @@ Possible values: `cypress`, `none`
|
||||
|
||||
Test runner to use for end to end (e2e) tests
|
||||
|
||||
### js
|
||||
|
||||
Default: `false`
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Generate JavaScript files rather than TypeScript files.
|
||||
|
||||
### linter
|
||||
|
||||
Default: `eslint`
|
||||
|
||||
@ -54,6 +54,14 @@ Possible values: `cypress`, `none`
|
||||
|
||||
Test runner to use for end to end (e2e) tests
|
||||
|
||||
### js
|
||||
|
||||
Default: `false`
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Generate JavaScript files rather than TypeScript files.
|
||||
|
||||
### linter
|
||||
|
||||
Default: `eslint`
|
||||
|
||||
@ -280,6 +280,20 @@ describe('Next.js Applications', () => {
|
||||
|
||||
checkFilesExist(`dist/apps/${appName}/next.config.js`);
|
||||
}, 120000);
|
||||
|
||||
it('should support --js flag', async () => {
|
||||
const appName = uniq('app');
|
||||
|
||||
runCLI(`generate @nrwl/next:app ${appName} --no-interactive --js`);
|
||||
|
||||
checkFilesExist(`apps/${appName}/pages/index.js`);
|
||||
|
||||
await checkApp(appName, {
|
||||
checkUnitTest: true,
|
||||
checkLint: true,
|
||||
checkE2E: true,
|
||||
});
|
||||
}, 120000);
|
||||
});
|
||||
|
||||
async function checkApp(
|
||||
|
||||
@ -315,4 +315,26 @@ describe('app', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('--js', () => {
|
||||
it('generates JS files', async () => {
|
||||
const tree = await runSchematic(
|
||||
'app',
|
||||
{ name: 'myApp', js: true },
|
||||
appTree
|
||||
);
|
||||
|
||||
expect(tree.exists('apps/my-app/pages/index.js')).toBeTruthy();
|
||||
expect(tree.exists('apps/my-app/specs/index.spec.js')).toBeTruthy();
|
||||
expect(tree.exists('apps/my-app/index.d.js')).toBeFalsy();
|
||||
expect(tree.exists('apps/my-app/index.d.ts')).toBeFalsy();
|
||||
|
||||
const tsConfig = readJsonInTree(tree, 'apps/my-app/tsconfig.json');
|
||||
expect(tsConfig.compilerOptions.allowJs).toEqual(true);
|
||||
|
||||
const tsConfigApp = readJsonInTree(tree, 'apps/my-app/tsconfig.app.json');
|
||||
expect(tsConfigApp.include).toContain('**/*.js');
|
||||
expect(tsConfigApp.exclude).toContain('**/*.spec.js');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const withNx = require('@nrwl/next/plugins/with-nx');
|
||||
|
||||
<% if (style === 'less') { %>
|
||||
|
||||
@ -55,7 +55,7 @@ export function addProject(options: NormalizedSchema): Rule {
|
||||
normalize(options.appProjectRoot),
|
||||
join(normalize(options.appProjectRoot), 'tsconfig.json'),
|
||||
options.linter,
|
||||
[`${options.appProjectRoot}/**/*.{ts,tsx}`]
|
||||
[`${options.appProjectRoot}/**/*.{ts,tsx,js,jsx}`]
|
||||
);
|
||||
|
||||
json.projects[options.projectName] = {
|
||||
|
||||
@ -14,6 +14,10 @@ import {
|
||||
createStyleRules,
|
||||
} from './create-application-files.helpers';
|
||||
import { names, offsetFromRoot } from '@nrwl/devkit';
|
||||
import {
|
||||
toJS,
|
||||
updateTsConfigsToJs,
|
||||
} from '@nrwl/workspace/src/utils/rules/to-js';
|
||||
|
||||
export function createApplicationFiles(options: NormalizedSchema): Rule {
|
||||
return mergeWith(
|
||||
@ -41,7 +45,12 @@ export function createApplicationFiles(options: NormalizedSchema): Rule {
|
||||
options.unitTestRunner === 'none'
|
||||
? filter((file) => file !== `/specs/index.spec.tsx`)
|
||||
: noop(),
|
||||
options.js ? filter((file) => file !== `/index.d.ts`) : noop(),
|
||||
options.js ? toJS() : noop(),
|
||||
move(options.appProjectRoot),
|
||||
options.js
|
||||
? updateTsConfigsToJs({ projectRoot: options.appProjectRoot })
|
||||
: noop(),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ export interface NormalizedSchema extends Schema {
|
||||
parsedTags: string[];
|
||||
fileName: string;
|
||||
styledModule: null | string;
|
||||
js?: boolean;
|
||||
}
|
||||
|
||||
export function normalizeOptions(
|
||||
|
||||
@ -98,6 +98,11 @@
|
||||
"type": "string",
|
||||
"description": "Add tags to the application (used for linting)",
|
||||
"alias": "t"
|
||||
},
|
||||
"js": {
|
||||
"type": "boolean",
|
||||
"description": "Generate JavaScript files rather than TypeScript files.",
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"required": []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user