Skip to content

Commit

Permalink
feat(schematics): app generator now includes Nx + xplat options
Browse files Browse the repository at this point in the history
closes #138
closes #147
closes #140
  • Loading branch information
NathanWalker committed Aug 27, 2019
1 parent 87a9161 commit 0650c4f
Show file tree
Hide file tree
Showing 14 changed files with 411 additions and 100 deletions.
2 changes: 1 addition & 1 deletion docs/xplat/getting-started/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ yarn global add @nrwl/cli
**Using `npm`**

```bash
npm install -save-dev @nstudio/xplat
npm install --save-dev @nstudio/xplat
```

**Using `yarn`**
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"@angular/router": "^8.0.0",
"@cypress/webpack-preprocessor": "^4.1.0",
"@nrwl/angular": "~8.4.0",
"@nrwl/express": "~8.4.0",
"@nrwl/nest": "~8.4.0",
"@nrwl/node": "~8.4.0",
"@nrwl/react": "~8.4.0",
"@nrwl/web": "~8.4.0",
"@nrwl/workspace": "~8.4.0",
"@schematics/angular": "8.1.1",
"@types/express": "4.16.0",
Expand Down
9 changes: 5 additions & 4 deletions packages/angular/src/schematics/helpers/applitools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function applitools(helperChains: Array<any>, options: IHelperSchema) {
// Add applitools modules
const packageJson = getJsonFromFile(tree, 'package.json');
packageJson.devDependencies = packageJson.devDependencies || {};
packageJson.devDependencies['@applitools/eyes-cypress'] = '^3.5.2';
packageJson.devDependencies['@applitools/eyes-cypress'] = '^3.7.1';
helperChains.push(updateJsonFile(tree, 'package.json', packageJson));

// update sample test
Expand Down Expand Up @@ -122,27 +122,28 @@ require('@applitools/eyes-cypress')(module);

function updateSampleTest() {
return `import { getGreeting } from '../support/app.po';
import { eyesOpen, eyesCheckWindow, eyesClose } from '@applitools/eyes-cypress';
describe('Hello Nx', () => {
beforeEach(() => cy.visit('/'));
it('should display welcome message', () => {
// start applitools test
(<any>cy).eyesOpen({
eyesOpen({
appName: 'myapp',
testName: 'Welcome message',
browser: { width: 800, height: 600 },
});
// check window with applitools
(<any>cy).eyesCheckWindow('Main Page');
eyesCheckWindow('Main Page');
// standard cypress testing
getGreeting().contains('Welcome to web-myapp!');
// end applitools test
(<any>cy).eyesClose();
eyesClose();
});
});
`;
Expand Down
5 changes: 3 additions & 2 deletions packages/angular/src/schematics/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
IHelperSchema,
buildHelperChain,
prerun,
missingArgument
missingArgument,
addInstallTask
} from '@nstudio/xplat';
import { config as configApplitools } from './applitools';
import { SchematicsException, chain, noop } from '@angular-devkit/schematics';
Expand Down Expand Up @@ -33,5 +34,5 @@ export default function(options: IHelperSchema) {
}
}

return chain([prerun(<any>options), ...helperChain]);
return chain([prerun(<any>options), ...helperChain, addInstallTask(options)]);
}
3 changes: 3 additions & 0 deletions packages/electron-angular/migrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"schematics": {}
}
6 changes: 6 additions & 0 deletions packages/xplat/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
"description": "Add applications.",
"aliases": ["app"]
},
"app-generate": {
"factory": "./src/schematics/app-generate",
"schema": "./src/schematics/app-generate/schema.json",
"description": "Generate apps.",
"hidden": true
},
"feature": {
"factory": "./src/schematics/feature",
"schema": "./src/schematics/feature/schema.json",
Expand Down
14 changes: 14 additions & 0 deletions packages/xplat/src/schematics/app-generate/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Schema } from '../application/schema';
import { chain } from '@angular-devkit/schematics';
import { prerun, XplatHelpers } from '../../utils';

let packagesToRunXplat: Array<string> = [];
export default function(options: Schema) {
const externalChains = XplatHelpers.getExternalChainsForGenerator(
options,
'app',
packagesToRunXplat
);

return chain([prerun(options, true), ...externalChains]);
}
80 changes: 80 additions & 0 deletions packages/xplat/src/schematics/app-generate/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"$schema": "http://json-schema.org/schema",
"id": "xplatAppGen",
"title": "Generate an xplat app",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The name of the app.",
"alias": "n",
"$default": {
"$source": "argv",
"index": 0
}
},
"prefix": {
"type": "string",
"description": "The prefix to apply to generated selectors.",
"alias": "p"
},
"platforms": {
"type": "string",
"description": "Platforms."
},
"framework": {
"type": "string",
"description": "Frontend framework.",
"x-prompt": {
"message": "Which frontend framework should it use?",
"type": "list",
"items": [
{
"value": "angular",
"label": "angular [Angular app]"
},
{
"value": "",
"label": "none [vanilla app]"
}
]
}
},
"groupByName": {
"description": "Group by app name (appname-platform) instead of the default (platform-appname)",
"type": "boolean",
"default": false
},
"target": {
"type": "string",
"description": "The target to use with this generator."
},
"npmScope": {
"type": "string",
"description": "The npm scope to use.",
"alias": "wn"
},
"routing": {
"type": "boolean",
"description": "Configure routing.",
"default": false
},
"setupSandbox": {
"type": "boolean",
"description": "Setup app as a sandbox for the workspace.",
"default": false
},
"useXplat": {
"description": "Generate xplat supporting architecture",
"type": "boolean",
"default": true,
"x-prompt": "Use xplat supporting architecture?"
},
"skipInstall": {
"type": "boolean",
"description": "Skip installing dependencies.",
"default": false
}
},
"required": []
}
83 changes: 71 additions & 12 deletions packages/xplat/src/schematics/application/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,75 @@ describe('xplat schematic', () => {
).toBeTruthy();
});

// describe('Nx app generators supporte via proxy xplat app generator', () => {
// it('should create Nx express', async () => {
// const options: XplatHelpers.Schema = { ...defaultOptions };
// options.platforms = 'express';

// const tree = await runSchematic('app', options, appTree);
// const files = tree.files;
// console.log('files:', files);

// // expect(tree.exists('/apps/nativescript-sample/nsconfig.json')).toBeTruthy();
// });
// });
fdescribe('Nx app generators supporte via proxy xplat app generator', () => {

it('should create Nx express', async () => {
appTree = Tree.empty();
appTree = createEmptyWorkspace(appTree);
const options: XplatHelpers.Schema = { ...defaultOptions };
options.platforms = 'express';

const tree = await runSchematic('app', options, appTree);
const files = tree.files;
// console.log('files:', files);

expect(tree.exists('/apps/express-sample/src/main.ts')).toBeTruthy();

let fileContent = getFileContent(
tree,
'/apps/express-sample/src/main.ts'
);
// console.log(fileContent);
expect(fileContent.indexOf(`from 'express'`)).toBeGreaterThan(0);
});

it('should create Nx nest', async () => {
appTree = Tree.empty();
appTree = createEmptyWorkspace(appTree);
const options: XplatHelpers.Schema = { ...defaultOptions };
options.platforms = 'nest';

const tree = await runSchematic('app', options, appTree);
const files = tree.files;
// console.log('files:', files);
expect(tree.exists('/apps/nest-sample/src/main.ts')).toBeTruthy();

let fileContent = getFileContent(tree, '/apps/nest-sample/src/main.ts');
// console.log(fileContent);
expect(fileContent.indexOf(`from '@nestjs/core'`)).toBeGreaterThan(0);
});

fit('should create Nx node', async () => {
appTree = Tree.empty();
appTree = createEmptyWorkspace(appTree);
const options: XplatHelpers.Schema = { ...defaultOptions };
options.platforms = 'node';

const tree = await runSchematic('app', options, appTree);
const files = tree.files;
// console.log('files:', files);

expect(tree.exists('/apps/node-sample/src/main.ts')).toBeTruthy();

let fileContent = getFileContent(tree, '/apps/node-sample/src/main.ts');
// console.log(fileContent);
expect(fileContent.indexOf(`console.log('Hello World!')`)).toBeGreaterThanOrEqual(0);
});

it('should create Nx react', async () => {
appTree = Tree.empty();
appTree = createEmptyWorkspace(appTree);
const options: XplatHelpers.Schema = { ...defaultOptions };
options.platforms = 'react';

const tree = await runSchematic('app', options, appTree);
const files = tree.files;
// console.log('files:', files);
expect(tree.exists('/apps/react-sample/src/app/app.tsx')).toBeTruthy();

let fileContent = getFileContent(tree, '/apps/react-sample/src/app/app.tsx');
// console.log(fileContent);
expect(fileContent.indexOf(`from 'react'`)).toBeGreaterThan(0);
});
});
});
46 changes: 4 additions & 42 deletions packages/xplat/src/schematics/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,13 @@ import { Schema } from './schema';
import { chain } from '@angular-devkit/schematics';
import { prerun, XplatHelpers } from '../../utils';

let packagesToRunXplat: Array<string> = [];
let packagesToRun: Array<string> = [];
export default function(options: Schema) {
const externalChains = XplatHelpers.getExternalChainsForGenerator(
const externalChains = XplatHelpers.getExternalChainsForApplication(
options,
'app',
packagesToRunXplat
packagesToRun
);

return chain([prerun(options, true), ...externalChains]);
}

// TODO: Allow prompts for all Nx generators
// Right now the x-prompt for what frontend framework should it use comes up for all options
// use 2 schematics which conditionally execute depending upon the first app type choice
// "items": [
// {
// "value": "electron",
// "label": "electron [Electron app]"
// },
// {
// "value": "express",
// "label": "express [Express app]"
// },
// {
// "value": "ionic",
// "label": "ionic [Ionic app]"
// },
// {
// "value": "nativescript",
// "label": "nativescript [NativeScript app]"
// },
// {
// "value": "nest",
// "label": "nest [Nest app]"
// },
// {
// "value": "node",
// "label": "node [Node app]"
// },
// {
// "value": "react",
// "label": "react [React app]"
// },
// {
// "value": "web",
// "label": "web [Web app]"
// }
// ]
}
Loading

0 comments on commit 0650c4f

Please sign in to comment.