<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> This PR address a few things: 1. When we generate an app or a library using the new TS Solution they are not added to the workspaces/packages option. 2. Currently, when we use `pnpm` to generate a workspace the `pnpm-workspace.yaml` looks like below which is not correct ``` packages: - packages/** ``` ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> 1. Libraries and apps should be referenced correctly out of the box so that they can be symlinked after installation. 2. The intended `pnpm-workspace.yaml` should look similar to: ``` packages: - 'packages/**' - 'demo' ``` ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> --------- Co-authored-by: Jack Hsu <jack.hsu@gmail.com>
119 lines
3.2 KiB
TypeScript
119 lines
3.2 KiB
TypeScript
import {
|
|
formatFiles,
|
|
GeneratorCallback,
|
|
joinPathFragments,
|
|
runTasksInSerial,
|
|
Tree,
|
|
} from '@nx/devkit';
|
|
import { initGenerator as jsInitGenerator } from '@nx/js';
|
|
import {
|
|
addProjectToTsSolutionWorkspace,
|
|
updateTsconfigFiles,
|
|
} from '@nx/js/src/utils/typescript/ts-solution-setup';
|
|
|
|
import { addLinting } from '../../utils/add-linting';
|
|
import { addJest } from '../../utils/add-jest';
|
|
|
|
import { normalizeOptions } from './lib/normalize-options';
|
|
import initGenerator from '../init/init';
|
|
import { addProject } from './lib/add-project';
|
|
import { createApplicationFiles } from './lib/create-application-files';
|
|
import { addEasScripts } from './lib/add-eas-scripts';
|
|
import { addE2e } from './lib/add-e2e';
|
|
import { Schema } from './schema';
|
|
import { ensureDependencies } from '../../utils/ensure-dependencies';
|
|
import { initRootBabelConfig } from '../../utils/init-root-babel-config';
|
|
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';
|
|
|
|
export async function expoApplicationGenerator(
|
|
host: Tree,
|
|
schema: Schema
|
|
): Promise<GeneratorCallback> {
|
|
return await expoApplicationGeneratorInternal(host, {
|
|
addPlugin: false,
|
|
...schema,
|
|
});
|
|
}
|
|
|
|
export async function expoApplicationGeneratorInternal(
|
|
host: Tree,
|
|
schema: Schema
|
|
): Promise<GeneratorCallback> {
|
|
const tasks: GeneratorCallback[] = [];
|
|
const jsInitTask = await jsInitGenerator(host, {
|
|
...schema,
|
|
skipFormat: true,
|
|
addTsPlugin: schema.useTsSolution,
|
|
formatter: schema.formatter,
|
|
});
|
|
|
|
const options = await normalizeOptions(host, schema);
|
|
|
|
tasks.push(jsInitTask);
|
|
const initTask = await initGenerator(host, { ...options, skipFormat: true });
|
|
tasks.push(initTask);
|
|
if (!options.skipPackageJson) {
|
|
tasks.push(ensureDependencies(host));
|
|
}
|
|
initRootBabelConfig(host);
|
|
|
|
await createApplicationFiles(host, options);
|
|
addProject(host, options);
|
|
|
|
const lintTask = await addLinting(host, {
|
|
...options,
|
|
projectRoot: options.appProjectRoot,
|
|
tsConfigPaths: [
|
|
joinPathFragments(options.appProjectRoot, 'tsconfig.app.json'),
|
|
],
|
|
});
|
|
tasks.push(lintTask);
|
|
|
|
const jestTask = await addJest(
|
|
host,
|
|
options.unitTestRunner,
|
|
options.projectName,
|
|
options.appProjectRoot,
|
|
options.js,
|
|
options.skipPackageJson,
|
|
options.addPlugin
|
|
);
|
|
tasks.push(jestTask);
|
|
const e2eTask = await addE2e(host, options);
|
|
tasks.push(e2eTask);
|
|
addEasScripts(host);
|
|
|
|
updateTsconfigFiles(
|
|
host,
|
|
options.appProjectRoot,
|
|
'tsconfig.app.json',
|
|
{
|
|
jsx: 'react-jsx',
|
|
module: 'esnext',
|
|
moduleResolution: 'bundler',
|
|
noUnusedLocals: false,
|
|
},
|
|
options.linter === 'eslint'
|
|
? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
|
|
: undefined
|
|
);
|
|
|
|
// If we are using the new TS solution
|
|
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
|
if (options.useTsSolution) {
|
|
addProjectToTsSolutionWorkspace(host, options.appProjectRoot);
|
|
}
|
|
|
|
if (!options.skipFormat) {
|
|
await formatFiles(host);
|
|
}
|
|
|
|
tasks.push(() => {
|
|
logShowProjectCommand(options.projectName);
|
|
});
|
|
|
|
return runTasksInSerial(...tasks);
|
|
}
|
|
|
|
export default expoApplicationGenerator;
|