Skip to content

Commit

Permalink
cleanup(misc): rename oss preset to npm and update presets related do…
Browse files Browse the repository at this point in the history
…cs (#6777)
  • Loading branch information
leosvelperez authored Aug 19, 2021
1 parent 2f3742b commit ff202d3
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 91 deletions.
2 changes: 1 addition & 1 deletion docs/shared/migration/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Select `empty` when prompted:

```bash
? 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
Expand Down
6 changes: 3 additions & 3 deletions e2e/workspace/src/create-nx-workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ describe('create-nx-workspace', () => {
expectNoAngularDevkit();
});

it('should be able to create an oss workspace', () => {
const wsName = uniq('oss');
it('should be able to create an npm workspace', () => {
const wsName = uniq('npm');
runCreateWorkspace(wsName, {
preset: 'oss',
preset: 'npm',
packageManager,
});

Expand Down
2 changes: 1 addition & 1 deletion e2e/workspace/src/custom-layout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('custom workspace layout', () => {
it('should work', async () => {
const proj = uniq('custom-layout-proj');
const packageManager = getSelectedPackageManager();
runCreateWorkspace(proj, { preset: 'oss', packageManager });
runCreateWorkspace(proj, { preset: 'npm', packageManager });
packageInstall('@nrwl/react @nrwl/angular @nrwl/express');

const nxJson = readJson('nx.json');
Expand Down
2 changes: 1 addition & 1 deletion nx-dev/nx-dev/pages/node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function Node() {
title: 'Open Source Tool',
content: [
'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.',
].join(' '),
},
Expand Down
16 changes: 8 additions & 8 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {

export enum Preset {
Empty = 'empty',
OSS = 'oss',
NPM = 'npm',
WebComponents = 'web-components',
Angular = 'angular',
AngularWithNest = 'angular-nest',
Expand All @@ -37,6 +37,11 @@ const presetOptions: { name: Preset; message: string }[] = [
message:
'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,
message: 'react [a workspace with a single React application]',
Expand Down Expand Up @@ -79,11 +84,6 @@ const presetOptions: { name: Preset; message: string }[] = [
message:
'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';
Expand Down Expand Up @@ -280,7 +280,7 @@ function determinePreset(parsedArgs: any): Promise<Preset> {
}

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('');
}

Expand Down Expand Up @@ -337,7 +337,7 @@ function determineCli(
function determineStyle(preset: Preset, parsedArgs: any) {
if (
preset === Preset.Empty ||
preset === Preset.OSS ||
preset === Preset.NPM ||
preset === Preset.Nest ||
preset === Preset.Express
) {
Expand Down
9 changes: 5 additions & 4 deletions packages/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

{{getting-started}}

```angular [a workspace with a single Angular application]
? Workspace name (e.g., org name) happyorg ? 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
```
? Workspace name (e.g., org name) happyorg
? 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
```

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.
Expand Down
3 changes: 2 additions & 1 deletion packages/workspace/src/generators/new/new.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createTree } from '@nrwl/devkit/testing';
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 { Preset } from '../utils/presets';

const defaultOptions: Omit<Schema, 'name' | 'directory' | 'appName'> = {
cli: 'nx',
Expand Down
25 changes: 6 additions & 19 deletions packages/workspace/src/generators/new/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,7 @@ import { spawn, SpawnOptions } from 'child_process';

import { workspaceGenerator } from '../workspace/workspace';
import { nxVersion } from '../../utils/versions';

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',
}
import { Preset } from '../utils/presets';

export interface Schema {
cli: 'nx' | 'angular';
Expand Down Expand Up @@ -155,8 +142,8 @@ async function initializeGitRepo(
export async function newGenerator(host: Tree, options: Schema) {
if (
options.skipInstall &&
options.preset !== 'empty' &&
options.preset !== 'oss'
options.preset !== Preset.Empty &&
options.preset !== Preset.NPM
) {
throw new Error(`Cannot select a preset when skipInstall is set to true.`);
}
Expand Down Expand Up @@ -220,7 +207,7 @@ const presetDependencies: Omit<
Preset,
{ dependencies: Record<string, string>; dev: Record<string, string> }
>,
Preset.Empty | Preset.OSS
Preset.Empty | Preset.NPM
> = {
[Preset.WebComponents]: { dependencies: {}, dev: { '@nrwl/web': nxVersion } },
[Preset.Angular]: { dependencies: { '@nrwl/angular': nxVersion }, dev: {} },
Expand Down Expand Up @@ -268,7 +255,7 @@ const presetDependencies: Omit<
};

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;
}
const { dependencies, dev } = presetDependencies[options.preset];
Expand All @@ -292,7 +279,7 @@ function normalizeOptions(options: Schema): Schema {
function setDefaultLinter(host: Tree, options: Schema) {
const { linter, preset } = options;
// Don't do anything if someone doesn't pick angular
if (preset !== 'angular' && preset !== 'angular-nest') {
if (preset !== Preset.Angular && preset !== Preset.AngularWithNest) {
return;
}

Expand Down
33 changes: 17 additions & 16 deletions packages/workspace/src/generators/preset/preset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { overrideCollectionResolutionForTesting } from '@nrwl/devkit/ngcli-adapter';
import { presetGenerator } from './preset';
import * as path from 'path';
import { Preset } from '../utils/presets';

describe('preset', () => {
let tree: Tree;
Expand Down Expand Up @@ -40,10 +41,10 @@ describe('preset', () => {
overrideCollectionResolutionForTesting(null);
});

it('should create files (preset = angular)', async () => {
it(`should create files (preset = ${Preset.Angular})`, async () => {
await presetGenerator(tree, {
name: 'proj',
preset: 'angular',
preset: Preset.Angular,
cli: 'nx',
style: 'css',
linter: 'eslint',
Expand All @@ -58,10 +59,10 @@ describe('preset', () => {
).toBe('@nrwl/angular');
});

it('should create files (preset = web-components)', async () => {
it(`should create files (preset = ${Preset.WebComponents})`, async () => {
await presetGenerator(tree, {
name: 'proj',
preset: 'web-components',
preset: Preset.WebComponents,
cli: 'nx',
standaloneConfig: false,
});
Expand All @@ -71,10 +72,10 @@ describe('preset', () => {
);
});

it('should create files (preset = react)', async () => {
it(`should create files (preset = ${Preset.React})`, async () => {
await presetGenerator(tree, {
name: 'proj',
preset: 'react',
preset: Preset.React,
style: 'css',
linter: 'eslint',
cli: 'nx',
Expand All @@ -86,10 +87,10 @@ describe('preset', () => {
);
});

it('should create files (preset = next)', async () => {
it(`should create files (preset = ${Preset.NextJs})`, async () => {
await presetGenerator(tree, {
name: 'proj',
preset: 'next',
preset: Preset.NextJs,
style: 'css',
linter: 'eslint',
cli: 'nx',
Expand All @@ -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, {
name: 'proj',
preset: 'angular-nest',
preset: Preset.AngularWithNest,
style: 'css',
linter: 'eslint',
cli: 'nx',
Expand All @@ -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, {
name: 'proj',
preset: 'react-express',
preset: Preset.ReactWithExpress,
style: 'css',
linter: 'eslint',
cli: 'nx',
Expand All @@ -137,10 +138,10 @@ describe('preset', () => {
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, {
name: 'proj',
preset: 'express',
preset: Preset.Express,
linter: 'eslint',
cli: 'nx',
standaloneConfig: false,
Expand All @@ -150,10 +151,10 @@ describe('preset', () => {
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, {
name: 'proj',
preset: 'gatsby',
preset: Preset.Gatsby,
style: 'css',
linter: 'eslint',
cli: 'nx',
Expand Down
23 changes: 12 additions & 11 deletions packages/workspace/src/generators/preset/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { libraryGenerator } from '../library/library';

import { insertImport } from '../utils/insert-import';
import { insertStatement } from '../utils/insert-statement';
import { Preset } from '../utils/presets';

export async function presetGenerator(tree: Tree, options: Schema) {
options = normalizeOptions(options);
Expand All @@ -28,11 +29,11 @@ export const presetSchematic = convertNxGenerator(presetGenerator);
export default presetGenerator;

async function createPreset(tree: Tree, options: Schema) {
if (options.preset === 'empty') {
if (options.preset === Preset.Empty) {
return;
} else if (options.preset === 'oss') {
} else if (options.preset === Preset.NPM) {
return;
} else if (options.preset === 'angular') {
} else if (options.preset === Preset.Angular) {
const {
applicationGenerator: angularApplicationGenerator,
} = require('@nrwl' + '/angular/src/generators/application/application');
Expand All @@ -44,7 +45,7 @@ async function createPreset(tree: Tree, options: Schema) {
standaloneConfig: options.standaloneConfig,
});
setDefaultCollection(tree, '@nrwl/angular');
} else if (options.preset === 'react') {
} else if (options.preset === Preset.React) {
const {
applicationGenerator: reactApplicationGenerator,
} = require('@nrwl' + '/react');
Expand All @@ -56,7 +57,7 @@ async function createPreset(tree: Tree, options: Schema) {
standaloneConfig: options.standaloneConfig,
});
setDefaultCollection(tree, '@nrwl/react');
} else if (options.preset === 'next') {
} else if (options.preset === Preset.NextJs) {
const { applicationGenerator: nextApplicationGenerator } = require('@nrwl' +
'/next');

Expand All @@ -67,7 +68,7 @@ async function createPreset(tree: Tree, options: Schema) {
standaloneConfig: options.standaloneConfig,
});
setDefaultCollection(tree, '@nrwl/next');
} else if (options.preset === 'web-components') {
} else if (options.preset === Preset.WebComponents) {
const { applicationGenerator: webApplicationGenerator } = require('@nrwl' +
'/web');

Expand All @@ -90,7 +91,7 @@ async function createPreset(tree: Tree, options: Schema) {
['@ungap/custom-elements']
);
setDefaultCollection(tree, '@nrwl/web');
} else if (options.preset === 'angular-nest') {
} else if (options.preset === Preset.AngularWithNest) {
const {
applicationGenerator: angularApplicationGenerator,
} = require('@nrwl' + '/angular/src/generators/application/application');
Expand Down Expand Up @@ -118,7 +119,7 @@ async function createPreset(tree: Tree, options: Schema) {
});
setDefaultCollection(tree, '@nrwl/angular');
connectAngularAndNest(tree, options);
} else if (options.preset === 'react-express') {
} else if (options.preset === Preset.ReactWithExpress) {
const {
applicationGenerator: expressApplicationGenerator,
} = require('@nrwl' + '/express');
Expand Down Expand Up @@ -146,7 +147,7 @@ async function createPreset(tree: Tree, options: Schema) {
});
setDefaultCollection(tree, '@nrwl/react');
connectReactAndExpress(tree, options);
} else if (options.preset === 'nest') {
} else if (options.preset === Preset.Nest) {
const { applicationGenerator: nestApplicationGenerator } = require('@nrwl' +
'/nest');

Expand All @@ -155,7 +156,7 @@ async function createPreset(tree: Tree, options: Schema) {
linter: options.linter,
});
setDefaultCollection(tree, '@nrwl/nest');
} else if (options.preset === 'express') {
} else if (options.preset === Preset.Express) {
const {
applicationGenerator: expressApplicationGenerator,
} = require('@nrwl' + '/express');
Expand All @@ -165,7 +166,7 @@ async function createPreset(tree: Tree, options: Schema) {
standaloneConfig: options.standaloneConfig,
});
setDefaultCollection(tree, '@nrwl/express');
} else if (options.preset === 'gatsby') {
} else if (options.preset === Preset.Gatsby) {
const {
applicationGenerator: gatsbyApplicationGenerator,
} = require('@nrwl' + '/gatsby');
Expand Down
Loading

1 comment on commit ff202d3

@vercel
Copy link

@vercel vercel bot commented on ff202d3 Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.