cleanup(misc): rename oss preset to npm and update presets related docs (#6777)
This commit is contained in:
parent
2f3742b3b1
commit
ff202d323c
@ -20,7 +20,7 @@ Select `empty` when prompted:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
? What to create in the new workspace (Use arrow keys)
|
? What to create in the new workspace (Use arrow keys)
|
||||||
❯ empty [an empty workspace]
|
❯ empty [an empty workspace with a layout that works best for building apps]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Exploring your workspace
|
## Exploring your workspace
|
||||||
|
|||||||
@ -43,10 +43,10 @@ describe('create-nx-workspace', () => {
|
|||||||
expectNoAngularDevkit();
|
expectNoAngularDevkit();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to create an oss workspace', () => {
|
it('should be able to create an npm workspace', () => {
|
||||||
const wsName = uniq('oss');
|
const wsName = uniq('npm');
|
||||||
runCreateWorkspace(wsName, {
|
runCreateWorkspace(wsName, {
|
||||||
preset: 'oss',
|
preset: 'npm',
|
||||||
packageManager,
|
packageManager,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ describe('custom workspace layout', () => {
|
|||||||
it('should work', async () => {
|
it('should work', async () => {
|
||||||
const proj = uniq('custom-layout-proj');
|
const proj = uniq('custom-layout-proj');
|
||||||
const packageManager = getSelectedPackageManager();
|
const packageManager = getSelectedPackageManager();
|
||||||
runCreateWorkspace(proj, { preset: 'oss', packageManager });
|
runCreateWorkspace(proj, { preset: 'npm', packageManager });
|
||||||
packageInstall('@nrwl/react @nrwl/angular @nrwl/express');
|
packageInstall('@nrwl/react @nrwl/angular @nrwl/express');
|
||||||
|
|
||||||
const nxJson = readJson('nx.json');
|
const nxJson = readJson('nx.json');
|
||||||
|
|||||||
@ -34,7 +34,7 @@ export function Node() {
|
|||||||
title: 'Open Source Tool',
|
title: 'Open Source Tool',
|
||||||
content: [
|
content: [
|
||||||
'Create a workspace that puts emphasis on packages rather than',
|
'Create a workspace that puts emphasis on packages rather than',
|
||||||
'libs and apps by using the "oss" preset with "create-nx-workspace".\n\n',
|
'libs and apps by using the "npm" preset with "create-nx-workspace".\n\n',
|
||||||
'Use TypeScript to build out projects that can scale infinitely.',
|
'Use TypeScript to build out projects that can scale infinitely.',
|
||||||
].join(' '),
|
].join(' '),
|
||||||
},
|
},
|
||||||
|
|||||||
@ -19,7 +19,7 @@ import {
|
|||||||
|
|
||||||
export enum Preset {
|
export enum Preset {
|
||||||
Empty = 'empty',
|
Empty = 'empty',
|
||||||
OSS = 'oss',
|
NPM = 'npm',
|
||||||
WebComponents = 'web-components',
|
WebComponents = 'web-components',
|
||||||
Angular = 'angular',
|
Angular = 'angular',
|
||||||
AngularWithNest = 'angular-nest',
|
AngularWithNest = 'angular-nest',
|
||||||
@ -37,6 +37,11 @@ const presetOptions: { name: Preset; message: string }[] = [
|
|||||||
message:
|
message:
|
||||||
'empty [an empty workspace with a layout that works best for building apps]',
|
'empty [an empty workspace with a layout that works best for building apps]',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: Preset.NPM,
|
||||||
|
message:
|
||||||
|
'npm [an empty workspace set up to publish npm packages (similar to and compatible with yarn workspaces)]',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: Preset.React,
|
name: Preset.React,
|
||||||
message: 'react [a workspace with a single React application]',
|
message: 'react [a workspace with a single React application]',
|
||||||
@ -79,11 +84,6 @@ const presetOptions: { name: Preset; message: string }[] = [
|
|||||||
message:
|
message:
|
||||||
'angular-nest [a workspace with a full stack application (Angular + Nest)]',
|
'angular-nest [a workspace with a full stack application (Angular + Nest)]',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: Preset.OSS,
|
|
||||||
message:
|
|
||||||
'oss [an empty workspace with a layout that works best for open-source projects]',
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const tsVersion = 'TYPESCRIPT_VERSION';
|
const tsVersion = 'TYPESCRIPT_VERSION';
|
||||||
@ -280,7 +280,7 @@ function determinePreset(parsedArgs: any): Promise<Preset> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function determineAppName(preset: Preset, parsedArgs: any): Promise<string> {
|
function determineAppName(preset: Preset, parsedArgs: any): Promise<string> {
|
||||||
if (preset === Preset.Empty || preset === Preset.OSS) {
|
if (preset === Preset.Empty || preset === Preset.NPM) {
|
||||||
return Promise.resolve('');
|
return Promise.resolve('');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,7 +337,7 @@ function determineCli(
|
|||||||
function determineStyle(preset: Preset, parsedArgs: any) {
|
function determineStyle(preset: Preset, parsedArgs: any) {
|
||||||
if (
|
if (
|
||||||
preset === Preset.Empty ||
|
preset === Preset.Empty ||
|
||||||
preset === Preset.OSS ||
|
preset === Preset.NPM ||
|
||||||
preset === Preset.Nest ||
|
preset === Preset.Nest ||
|
||||||
preset === Preset.Express
|
preset === Preset.Express
|
||||||
) {
|
) {
|
||||||
|
|||||||
@ -10,10 +10,11 @@
|
|||||||
|
|
||||||
{{getting-started}}
|
{{getting-started}}
|
||||||
|
|
||||||
```angular [a workspace with a single Angular application]
|
```
|
||||||
? Workspace name (e.g., org name) happyorg ? What to create in the new workspace
|
? Workspace name (e.g., org name) happyorg
|
||||||
web components [a workspace with a single app built using web components] ?
|
? What to create in the new workspace web components [a workspace with a single app built using web components]
|
||||||
Application name myapp ? Default stylesheet format CSS
|
? Application name myapp
|
||||||
|
? Default stylesheet format CSS
|
||||||
```
|
```
|
||||||
|
|
||||||
If it's your first Nx project, the command will recommend you to install the `nx` package globally, so you can invoke `nx` directly without going through yarn or npm.
|
If it's your first Nx project, the command will recommend you to install the `nx` package globally, so you can invoke `nx` directly without going through yarn or npm.
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import { createTree } from '@nrwl/devkit/testing';
|
import { createTree } from '@nrwl/devkit/testing';
|
||||||
import { readJson, Tree, writeJson, PackageManager } from '@nrwl/devkit';
|
import { readJson, Tree, writeJson, PackageManager } from '@nrwl/devkit';
|
||||||
import { newGenerator, Preset, Schema } from './new';
|
import { newGenerator, Schema } from './new';
|
||||||
import { Linter } from '../../utils/lint';
|
import { Linter } from '../../utils/lint';
|
||||||
|
import { Preset } from '../utils/presets';
|
||||||
|
|
||||||
const defaultOptions: Omit<Schema, 'name' | 'directory' | 'appName'> = {
|
const defaultOptions: Omit<Schema, 'name' | 'directory' | 'appName'> = {
|
||||||
cli: 'nx',
|
cli: 'nx',
|
||||||
|
|||||||
@ -18,20 +18,7 @@ import { spawn, SpawnOptions } from 'child_process';
|
|||||||
|
|
||||||
import { workspaceGenerator } from '../workspace/workspace';
|
import { workspaceGenerator } from '../workspace/workspace';
|
||||||
import { nxVersion } from '../../utils/versions';
|
import { nxVersion } from '../../utils/versions';
|
||||||
|
import { Preset } from '../utils/presets';
|
||||||
export enum Preset {
|
|
||||||
Empty = 'empty',
|
|
||||||
OSS = 'oss',
|
|
||||||
WebComponents = 'web-components',
|
|
||||||
Angular = 'angular',
|
|
||||||
AngularWithNest = 'angular-nest',
|
|
||||||
React = 'react',
|
|
||||||
ReactWithExpress = 'react-express',
|
|
||||||
NextJs = 'next',
|
|
||||||
Gatsby = 'gatsby',
|
|
||||||
Nest = 'nest',
|
|
||||||
Express = 'express',
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Schema {
|
export interface Schema {
|
||||||
cli: 'nx' | 'angular';
|
cli: 'nx' | 'angular';
|
||||||
@ -155,8 +142,8 @@ async function initializeGitRepo(
|
|||||||
export async function newGenerator(host: Tree, options: Schema) {
|
export async function newGenerator(host: Tree, options: Schema) {
|
||||||
if (
|
if (
|
||||||
options.skipInstall &&
|
options.skipInstall &&
|
||||||
options.preset !== 'empty' &&
|
options.preset !== Preset.Empty &&
|
||||||
options.preset !== 'oss'
|
options.preset !== Preset.NPM
|
||||||
) {
|
) {
|
||||||
throw new Error(`Cannot select a preset when skipInstall is set to true.`);
|
throw new Error(`Cannot select a preset when skipInstall is set to true.`);
|
||||||
}
|
}
|
||||||
@ -220,7 +207,7 @@ const presetDependencies: Omit<
|
|||||||
Preset,
|
Preset,
|
||||||
{ dependencies: Record<string, string>; dev: Record<string, string> }
|
{ dependencies: Record<string, string>; dev: Record<string, string> }
|
||||||
>,
|
>,
|
||||||
Preset.Empty | Preset.OSS
|
Preset.Empty | Preset.NPM
|
||||||
> = {
|
> = {
|
||||||
[Preset.WebComponents]: { dependencies: {}, dev: { '@nrwl/web': nxVersion } },
|
[Preset.WebComponents]: { dependencies: {}, dev: { '@nrwl/web': nxVersion } },
|
||||||
[Preset.Angular]: { dependencies: { '@nrwl/angular': nxVersion }, dev: {} },
|
[Preset.Angular]: { dependencies: { '@nrwl/angular': nxVersion }, dev: {} },
|
||||||
@ -268,7 +255,7 @@ const presetDependencies: Omit<
|
|||||||
};
|
};
|
||||||
|
|
||||||
function addPresetDependencies(host: Tree, options: Schema) {
|
function addPresetDependencies(host: Tree, options: Schema) {
|
||||||
if (options.preset === Preset.Empty || options.preset === Preset.OSS) {
|
if (options.preset === Preset.Empty || options.preset === Preset.NPM) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { dependencies, dev } = presetDependencies[options.preset];
|
const { dependencies, dev } = presetDependencies[options.preset];
|
||||||
@ -292,7 +279,7 @@ function normalizeOptions(options: Schema): Schema {
|
|||||||
function setDefaultLinter(host: Tree, options: Schema) {
|
function setDefaultLinter(host: Tree, options: Schema) {
|
||||||
const { linter, preset } = options;
|
const { linter, preset } = options;
|
||||||
// Don't do anything if someone doesn't pick angular
|
// Don't do anything if someone doesn't pick angular
|
||||||
if (preset !== 'angular' && preset !== 'angular-nest') {
|
if (preset !== Preset.Angular && preset !== Preset.AngularWithNest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
|||||||
import { overrideCollectionResolutionForTesting } from '@nrwl/devkit/ngcli-adapter';
|
import { overrideCollectionResolutionForTesting } from '@nrwl/devkit/ngcli-adapter';
|
||||||
import { presetGenerator } from './preset';
|
import { presetGenerator } from './preset';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import { Preset } from '../utils/presets';
|
||||||
|
|
||||||
describe('preset', () => {
|
describe('preset', () => {
|
||||||
let tree: Tree;
|
let tree: Tree;
|
||||||
@ -40,10 +41,10 @@ describe('preset', () => {
|
|||||||
overrideCollectionResolutionForTesting(null);
|
overrideCollectionResolutionForTesting(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create files (preset = angular)', async () => {
|
it(`should create files (preset = ${Preset.Angular})`, async () => {
|
||||||
await presetGenerator(tree, {
|
await presetGenerator(tree, {
|
||||||
name: 'proj',
|
name: 'proj',
|
||||||
preset: 'angular',
|
preset: Preset.Angular,
|
||||||
cli: 'nx',
|
cli: 'nx',
|
||||||
style: 'css',
|
style: 'css',
|
||||||
linter: 'eslint',
|
linter: 'eslint',
|
||||||
@ -58,10 +59,10 @@ describe('preset', () => {
|
|||||||
).toBe('@nrwl/angular');
|
).toBe('@nrwl/angular');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create files (preset = web-components)', async () => {
|
it(`should create files (preset = ${Preset.WebComponents})`, async () => {
|
||||||
await presetGenerator(tree, {
|
await presetGenerator(tree, {
|
||||||
name: 'proj',
|
name: 'proj',
|
||||||
preset: 'web-components',
|
preset: Preset.WebComponents,
|
||||||
cli: 'nx',
|
cli: 'nx',
|
||||||
standaloneConfig: false,
|
standaloneConfig: false,
|
||||||
});
|
});
|
||||||
@ -71,10 +72,10 @@ describe('preset', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create files (preset = react)', async () => {
|
it(`should create files (preset = ${Preset.React})`, async () => {
|
||||||
await presetGenerator(tree, {
|
await presetGenerator(tree, {
|
||||||
name: 'proj',
|
name: 'proj',
|
||||||
preset: 'react',
|
preset: Preset.React,
|
||||||
style: 'css',
|
style: 'css',
|
||||||
linter: 'eslint',
|
linter: 'eslint',
|
||||||
cli: 'nx',
|
cli: 'nx',
|
||||||
@ -86,10 +87,10 @@ describe('preset', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create files (preset = next)', async () => {
|
it(`should create files (preset = ${Preset.NextJs})`, async () => {
|
||||||
await presetGenerator(tree, {
|
await presetGenerator(tree, {
|
||||||
name: 'proj',
|
name: 'proj',
|
||||||
preset: 'next',
|
preset: Preset.NextJs,
|
||||||
style: 'css',
|
style: 'css',
|
||||||
linter: 'eslint',
|
linter: 'eslint',
|
||||||
cli: 'nx',
|
cli: 'nx',
|
||||||
@ -101,10 +102,10 @@ describe('preset', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create files (preset = angular-nest)', async () => {
|
it(`should create files (preset = ${Preset.AngularWithNest})`, async () => {
|
||||||
await presetGenerator(tree, {
|
await presetGenerator(tree, {
|
||||||
name: 'proj',
|
name: 'proj',
|
||||||
preset: 'angular-nest',
|
preset: Preset.AngularWithNest,
|
||||||
style: 'css',
|
style: 'css',
|
||||||
linter: 'eslint',
|
linter: 'eslint',
|
||||||
cli: 'nx',
|
cli: 'nx',
|
||||||
@ -118,10 +119,10 @@ describe('preset', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create files (preset = react-express)', async () => {
|
it(`should create files (preset = ${Preset.ReactWithExpress})`, async () => {
|
||||||
await presetGenerator(tree, {
|
await presetGenerator(tree, {
|
||||||
name: 'proj',
|
name: 'proj',
|
||||||
preset: 'react-express',
|
preset: Preset.ReactWithExpress,
|
||||||
style: 'css',
|
style: 'css',
|
||||||
linter: 'eslint',
|
linter: 'eslint',
|
||||||
cli: 'nx',
|
cli: 'nx',
|
||||||
@ -137,10 +138,10 @@ describe('preset', () => {
|
|||||||
expect(tree.exists('/libs/api-interfaces/.eslintrc.json')).toBe(true);
|
expect(tree.exists('/libs/api-interfaces/.eslintrc.json')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create files (preset = express)', async () => {
|
it(`should create files (preset = ${Preset.Express})`, async () => {
|
||||||
await presetGenerator(tree, {
|
await presetGenerator(tree, {
|
||||||
name: 'proj',
|
name: 'proj',
|
||||||
preset: 'express',
|
preset: Preset.Express,
|
||||||
linter: 'eslint',
|
linter: 'eslint',
|
||||||
cli: 'nx',
|
cli: 'nx',
|
||||||
standaloneConfig: false,
|
standaloneConfig: false,
|
||||||
@ -150,10 +151,10 @@ describe('preset', () => {
|
|||||||
expect(tree.exists('apps/proj/.eslintrc.json')).toBe(true);
|
expect(tree.exists('apps/proj/.eslintrc.json')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create files (preset = gatsby)', async () => {
|
it(`should create files (preset = ${Preset.Gatsby})`, async () => {
|
||||||
await presetGenerator(tree, {
|
await presetGenerator(tree, {
|
||||||
name: 'proj',
|
name: 'proj',
|
||||||
preset: 'gatsby',
|
preset: Preset.Gatsby,
|
||||||
style: 'css',
|
style: 'css',
|
||||||
linter: 'eslint',
|
linter: 'eslint',
|
||||||
cli: 'nx',
|
cli: 'nx',
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import { libraryGenerator } from '../library/library';
|
|||||||
|
|
||||||
import { insertImport } from '../utils/insert-import';
|
import { insertImport } from '../utils/insert-import';
|
||||||
import { insertStatement } from '../utils/insert-statement';
|
import { insertStatement } from '../utils/insert-statement';
|
||||||
|
import { Preset } from '../utils/presets';
|
||||||
|
|
||||||
export async function presetGenerator(tree: Tree, options: Schema) {
|
export async function presetGenerator(tree: Tree, options: Schema) {
|
||||||
options = normalizeOptions(options);
|
options = normalizeOptions(options);
|
||||||
@ -28,11 +29,11 @@ export const presetSchematic = convertNxGenerator(presetGenerator);
|
|||||||
export default presetGenerator;
|
export default presetGenerator;
|
||||||
|
|
||||||
async function createPreset(tree: Tree, options: Schema) {
|
async function createPreset(tree: Tree, options: Schema) {
|
||||||
if (options.preset === 'empty') {
|
if (options.preset === Preset.Empty) {
|
||||||
return;
|
return;
|
||||||
} else if (options.preset === 'oss') {
|
} else if (options.preset === Preset.NPM) {
|
||||||
return;
|
return;
|
||||||
} else if (options.preset === 'angular') {
|
} else if (options.preset === Preset.Angular) {
|
||||||
const {
|
const {
|
||||||
applicationGenerator: angularApplicationGenerator,
|
applicationGenerator: angularApplicationGenerator,
|
||||||
} = require('@nrwl' + '/angular/src/generators/application/application');
|
} = require('@nrwl' + '/angular/src/generators/application/application');
|
||||||
@ -44,7 +45,7 @@ async function createPreset(tree: Tree, options: Schema) {
|
|||||||
standaloneConfig: options.standaloneConfig,
|
standaloneConfig: options.standaloneConfig,
|
||||||
});
|
});
|
||||||
setDefaultCollection(tree, '@nrwl/angular');
|
setDefaultCollection(tree, '@nrwl/angular');
|
||||||
} else if (options.preset === 'react') {
|
} else if (options.preset === Preset.React) {
|
||||||
const {
|
const {
|
||||||
applicationGenerator: reactApplicationGenerator,
|
applicationGenerator: reactApplicationGenerator,
|
||||||
} = require('@nrwl' + '/react');
|
} = require('@nrwl' + '/react');
|
||||||
@ -56,7 +57,7 @@ async function createPreset(tree: Tree, options: Schema) {
|
|||||||
standaloneConfig: options.standaloneConfig,
|
standaloneConfig: options.standaloneConfig,
|
||||||
});
|
});
|
||||||
setDefaultCollection(tree, '@nrwl/react');
|
setDefaultCollection(tree, '@nrwl/react');
|
||||||
} else if (options.preset === 'next') {
|
} else if (options.preset === Preset.NextJs) {
|
||||||
const { applicationGenerator: nextApplicationGenerator } = require('@nrwl' +
|
const { applicationGenerator: nextApplicationGenerator } = require('@nrwl' +
|
||||||
'/next');
|
'/next');
|
||||||
|
|
||||||
@ -67,7 +68,7 @@ async function createPreset(tree: Tree, options: Schema) {
|
|||||||
standaloneConfig: options.standaloneConfig,
|
standaloneConfig: options.standaloneConfig,
|
||||||
});
|
});
|
||||||
setDefaultCollection(tree, '@nrwl/next');
|
setDefaultCollection(tree, '@nrwl/next');
|
||||||
} else if (options.preset === 'web-components') {
|
} else if (options.preset === Preset.WebComponents) {
|
||||||
const { applicationGenerator: webApplicationGenerator } = require('@nrwl' +
|
const { applicationGenerator: webApplicationGenerator } = require('@nrwl' +
|
||||||
'/web');
|
'/web');
|
||||||
|
|
||||||
@ -90,7 +91,7 @@ async function createPreset(tree: Tree, options: Schema) {
|
|||||||
['@ungap/custom-elements']
|
['@ungap/custom-elements']
|
||||||
);
|
);
|
||||||
setDefaultCollection(tree, '@nrwl/web');
|
setDefaultCollection(tree, '@nrwl/web');
|
||||||
} else if (options.preset === 'angular-nest') {
|
} else if (options.preset === Preset.AngularWithNest) {
|
||||||
const {
|
const {
|
||||||
applicationGenerator: angularApplicationGenerator,
|
applicationGenerator: angularApplicationGenerator,
|
||||||
} = require('@nrwl' + '/angular/src/generators/application/application');
|
} = require('@nrwl' + '/angular/src/generators/application/application');
|
||||||
@ -118,7 +119,7 @@ async function createPreset(tree: Tree, options: Schema) {
|
|||||||
});
|
});
|
||||||
setDefaultCollection(tree, '@nrwl/angular');
|
setDefaultCollection(tree, '@nrwl/angular');
|
||||||
connectAngularAndNest(tree, options);
|
connectAngularAndNest(tree, options);
|
||||||
} else if (options.preset === 'react-express') {
|
} else if (options.preset === Preset.ReactWithExpress) {
|
||||||
const {
|
const {
|
||||||
applicationGenerator: expressApplicationGenerator,
|
applicationGenerator: expressApplicationGenerator,
|
||||||
} = require('@nrwl' + '/express');
|
} = require('@nrwl' + '/express');
|
||||||
@ -146,7 +147,7 @@ async function createPreset(tree: Tree, options: Schema) {
|
|||||||
});
|
});
|
||||||
setDefaultCollection(tree, '@nrwl/react');
|
setDefaultCollection(tree, '@nrwl/react');
|
||||||
connectReactAndExpress(tree, options);
|
connectReactAndExpress(tree, options);
|
||||||
} else if (options.preset === 'nest') {
|
} else if (options.preset === Preset.Nest) {
|
||||||
const { applicationGenerator: nestApplicationGenerator } = require('@nrwl' +
|
const { applicationGenerator: nestApplicationGenerator } = require('@nrwl' +
|
||||||
'/nest');
|
'/nest');
|
||||||
|
|
||||||
@ -155,7 +156,7 @@ async function createPreset(tree: Tree, options: Schema) {
|
|||||||
linter: options.linter,
|
linter: options.linter,
|
||||||
});
|
});
|
||||||
setDefaultCollection(tree, '@nrwl/nest');
|
setDefaultCollection(tree, '@nrwl/nest');
|
||||||
} else if (options.preset === 'express') {
|
} else if (options.preset === Preset.Express) {
|
||||||
const {
|
const {
|
||||||
applicationGenerator: expressApplicationGenerator,
|
applicationGenerator: expressApplicationGenerator,
|
||||||
} = require('@nrwl' + '/express');
|
} = require('@nrwl' + '/express');
|
||||||
@ -165,7 +166,7 @@ async function createPreset(tree: Tree, options: Schema) {
|
|||||||
standaloneConfig: options.standaloneConfig,
|
standaloneConfig: options.standaloneConfig,
|
||||||
});
|
});
|
||||||
setDefaultCollection(tree, '@nrwl/express');
|
setDefaultCollection(tree, '@nrwl/express');
|
||||||
} else if (options.preset === 'gatsby') {
|
} else if (options.preset === Preset.Gatsby) {
|
||||||
const {
|
const {
|
||||||
applicationGenerator: gatsbyApplicationGenerator,
|
applicationGenerator: gatsbyApplicationGenerator,
|
||||||
} = require('@nrwl' + '/gatsby');
|
} = require('@nrwl' + '/gatsby');
|
||||||
|
|||||||
@ -1,20 +1,11 @@
|
|||||||
|
import { Preset } from '../utils/presets';
|
||||||
|
|
||||||
export interface Schema {
|
export interface Schema {
|
||||||
name: string;
|
name: string;
|
||||||
npmScope?: string;
|
npmScope?: string;
|
||||||
style?: string;
|
style?: string;
|
||||||
cli: string;
|
cli: string;
|
||||||
linter?: string;
|
linter?: string;
|
||||||
preset:
|
preset: Preset;
|
||||||
| 'empty'
|
|
||||||
| 'oss'
|
|
||||||
| 'angular'
|
|
||||||
| 'react'
|
|
||||||
| 'next'
|
|
||||||
| 'gatsby'
|
|
||||||
| 'web-components'
|
|
||||||
| 'angular-nest'
|
|
||||||
| 'react-express'
|
|
||||||
| 'nest'
|
|
||||||
| 'express';
|
|
||||||
standaloneConfig?: boolean;
|
standaloneConfig?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
13
packages/workspace/src/generators/utils/presets.ts
Normal file
13
packages/workspace/src/generators/utils/presets.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
export enum Preset {
|
||||||
|
Empty = 'empty',
|
||||||
|
NPM = 'npm',
|
||||||
|
WebComponents = 'web-components',
|
||||||
|
Angular = 'angular',
|
||||||
|
AngularWithNest = 'angular-nest',
|
||||||
|
React = 'react',
|
||||||
|
ReactWithExpress = 'react-express',
|
||||||
|
NextJs = 'next',
|
||||||
|
Gatsby = 'gatsby',
|
||||||
|
Nest = 'nest',
|
||||||
|
Express = 'express',
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@ import { readJson } from '@nrwl/devkit';
|
|||||||
import type { Tree, NxJsonConfiguration } from '@nrwl/devkit';
|
import type { Tree, NxJsonConfiguration } from '@nrwl/devkit';
|
||||||
import { workspaceGenerator } from './workspace';
|
import { workspaceGenerator } from './workspace';
|
||||||
import { createTree } from '@nrwl/devkit/testing';
|
import { createTree } from '@nrwl/devkit/testing';
|
||||||
|
import { Preset } from '../utils/presets';
|
||||||
|
|
||||||
describe('@nrwl/workspace:workspace', () => {
|
describe('@nrwl/workspace:workspace', () => {
|
||||||
let tree: Tree;
|
let tree: Tree;
|
||||||
@ -15,7 +16,7 @@ describe('@nrwl/workspace:workspace', () => {
|
|||||||
name: 'proj',
|
name: 'proj',
|
||||||
directory: 'proj',
|
directory: 'proj',
|
||||||
cli: 'nx',
|
cli: 'nx',
|
||||||
preset: 'empty',
|
preset: Preset.Empty,
|
||||||
defaultBase: 'main',
|
defaultBase: 'main',
|
||||||
});
|
});
|
||||||
expect(tree.exists('/proj/nx.json')).toBe(true);
|
expect(tree.exists('/proj/nx.json')).toBe(true);
|
||||||
@ -29,7 +30,7 @@ describe('@nrwl/workspace:workspace', () => {
|
|||||||
name: 'proj',
|
name: 'proj',
|
||||||
directory: 'proj',
|
directory: 'proj',
|
||||||
cli: 'nx',
|
cli: 'nx',
|
||||||
preset: 'empty',
|
preset: Preset.Empty,
|
||||||
defaultBase: 'master',
|
defaultBase: 'master',
|
||||||
});
|
});
|
||||||
const nxJson = readJson<NxJsonConfiguration>(tree, '/proj/nx.json');
|
const nxJson = readJson<NxJsonConfiguration>(tree, '/proj/nx.json');
|
||||||
@ -70,7 +71,7 @@ describe('@nrwl/workspace:workspace', () => {
|
|||||||
name: 'proj',
|
name: 'proj',
|
||||||
directory: 'proj',
|
directory: 'proj',
|
||||||
cli: 'nx',
|
cli: 'nx',
|
||||||
preset: 'empty',
|
preset: Preset.Empty,
|
||||||
defaultBase: 'main',
|
defaultBase: 'main',
|
||||||
});
|
});
|
||||||
expect(tree.read('proj/.prettierrc', 'utf-8')).toMatchSnapshot();
|
expect(tree.read('proj/.prettierrc', 'utf-8')).toMatchSnapshot();
|
||||||
@ -81,7 +82,7 @@ describe('@nrwl/workspace:workspace', () => {
|
|||||||
name: 'proj',
|
name: 'proj',
|
||||||
directory: 'proj',
|
directory: 'proj',
|
||||||
cli: 'nx',
|
cli: 'nx',
|
||||||
preset: 'empty',
|
preset: Preset.Empty,
|
||||||
defaultBase: 'main',
|
defaultBase: 'main',
|
||||||
});
|
});
|
||||||
const recommendations = readJson<{ recommendations: string[] }>(
|
const recommendations = readJson<{ recommendations: string[] }>(
|
||||||
@ -97,7 +98,7 @@ describe('@nrwl/workspace:workspace', () => {
|
|||||||
name: 'proj',
|
name: 'proj',
|
||||||
directory: 'proj',
|
directory: 'proj',
|
||||||
cli: 'angular',
|
cli: 'angular',
|
||||||
preset: 'empty',
|
preset: Preset.Empty,
|
||||||
defaultBase: 'main',
|
defaultBase: 'main',
|
||||||
});
|
});
|
||||||
const recommendations = readJson<{ recommendations: string[] }>(
|
const recommendations = readJson<{ recommendations: string[] }>(
|
||||||
@ -113,7 +114,7 @@ describe('@nrwl/workspace:workspace', () => {
|
|||||||
name: 'proj',
|
name: 'proj',
|
||||||
directory: 'proj',
|
directory: 'proj',
|
||||||
cli: 'angular',
|
cli: 'angular',
|
||||||
preset: 'empty',
|
preset: Preset.Empty,
|
||||||
defaultBase: 'main',
|
defaultBase: 'main',
|
||||||
});
|
});
|
||||||
expect(tree.exists('/proj/decorate-angular-cli.js')).toBe(true);
|
expect(tree.exists('/proj/decorate-angular-cli.js')).toBe(true);
|
||||||
@ -128,7 +129,7 @@ describe('@nrwl/workspace:workspace', () => {
|
|||||||
name: 'proj',
|
name: 'proj',
|
||||||
directory: 'proj',
|
directory: 'proj',
|
||||||
cli: 'nx',
|
cli: 'nx',
|
||||||
preset: 'empty',
|
preset: Preset.Empty,
|
||||||
defaultBase: 'main',
|
defaultBase: 'main',
|
||||||
});
|
});
|
||||||
expect(tree.exists('/proj/decorate-angular-cli.js')).toBe(false);
|
expect(tree.exists('/proj/decorate-angular-cli.js')).toBe(false);
|
||||||
@ -141,7 +142,7 @@ describe('@nrwl/workspace:workspace', () => {
|
|||||||
name: 'proj',
|
name: 'proj',
|
||||||
directory: 'proj',
|
directory: 'proj',
|
||||||
cli: 'nx',
|
cli: 'nx',
|
||||||
preset: 'oss',
|
preset: Preset.NPM,
|
||||||
defaultBase: 'main',
|
defaultBase: 'main',
|
||||||
});
|
});
|
||||||
expect(tree.exists('/proj/packages/.gitkeep')).toBe(true);
|
expect(tree.exists('/proj/packages/.gitkeep')).toBe(true);
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import {
|
|||||||
import { readFileSync } from 'fs';
|
import { readFileSync } from 'fs';
|
||||||
import { join, join as pathJoin } from 'path';
|
import { join, join as pathJoin } from 'path';
|
||||||
import { reformattedWorkspaceJsonOrNull } from '@nrwl/tao/src/shared/workspace';
|
import { reformattedWorkspaceJsonOrNull } from '@nrwl/tao/src/shared/workspace';
|
||||||
|
import { Preset } from '../utils/presets';
|
||||||
|
|
||||||
export const DEFAULT_NRWL_PRETTIER_CONFIG = {
|
export const DEFAULT_NRWL_PRETTIER_CONFIG = {
|
||||||
singleQuote: true,
|
singleQuote: true,
|
||||||
@ -31,7 +32,7 @@ function decorateAngularClI(host: Tree, options: Schema) {
|
|||||||
|
|
||||||
function setPresetProperty(tree: Tree, options: Schema) {
|
function setPresetProperty(tree: Tree, options: Schema) {
|
||||||
updateJson(tree, join(options.directory, 'nx.json'), (json) => {
|
updateJson(tree, join(options.directory, 'nx.json'), (json) => {
|
||||||
if (options.preset === 'oss') {
|
if (options.preset === Preset.NPM) {
|
||||||
addPropertyWithStableKeys(
|
addPropertyWithStableKeys(
|
||||||
json,
|
json,
|
||||||
'extends',
|
'extends',
|
||||||
@ -46,7 +47,7 @@ function setPresetProperty(tree: Tree, options: Schema) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createAppsAndLibsFolders(host: Tree, options: Schema) {
|
function createAppsAndLibsFolders(host: Tree, options: Schema) {
|
||||||
if (options.preset === 'oss') {
|
if (options.preset === Preset.NPM) {
|
||||||
host.write(join(options.directory, 'packages/.gitkeep'), '');
|
host.write(join(options.directory, 'packages/.gitkeep'), '');
|
||||||
} else {
|
} else {
|
||||||
host.write(join(options.directory, 'apps/.gitkeep'), '');
|
host.write(join(options.directory, 'apps/.gitkeep'), '');
|
||||||
|
|||||||
@ -25,15 +25,16 @@ The `create-nx-workspace` command will ask you to select a preset, which will co
|
|||||||
```
|
```
|
||||||
? What to create in the new workspace (Use arrow keys)
|
? What to create in the new workspace (Use arrow keys)
|
||||||
❯ empty [an empty workspace with a layout that works best for building apps]
|
❯ empty [an empty workspace with a layout that works best for building apps]
|
||||||
oss [an empty workspace with a layout that works best for open-source projects]
|
npm [an empty workspace set up to publish npm packages (similar to and compatible with yarn workspaces)]
|
||||||
react [a workspace with a single React application]
|
react [a workspace with a single React application]
|
||||||
next.js [a workspace with a single Next.js application]
|
|
||||||
angular [a workspace with a single Angular application]
|
angular [a workspace with a single Angular application]
|
||||||
express [a workspace with a single Express application]
|
next.js [a workspace with a single Next.js application]
|
||||||
|
gatsby [a workspace with a single Gatsby application]
|
||||||
nest [a workspace with a single Nest application]
|
nest [a workspace with a single Nest application]
|
||||||
|
express [a workspace with a single Express application]
|
||||||
|
web components [a workspace with a single app built using web components]
|
||||||
react-express [a workspace with a full stack application (React + Express)]
|
react-express [a workspace with a full stack application (React + Express)]
|
||||||
angular-nest [a workspace with a full stack application (Angular + Nest)]
|
angular-nest [a workspace with a full stack application (Angular + Nest)]
|
||||||
web components [a workspace with a single app built using web components]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Select the preset that works best for you.
|
Select the preset that works best for you.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user