Skip to content

Commit

Permalink
feat(nx): support no framework apps
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored and vsavkin committed Mar 2, 2019
1 parent 24f31d1 commit 3bad40e
Show file tree
Hide file tree
Showing 65 changed files with 3,088 additions and 356 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules
/.vscode
dist
/build
/coverage
test
.DS_Store
tmp
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ tmp
/build
node_modules
/package.json
packages/schematics/src/collection/**/files/*.json
packages/schematics/src/collection/**/files/**/*.json
/.vscode
/.idea
/.github
/coverage
2 changes: 2 additions & 0 deletions docs/api-builders/node-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Build a Node application
| `externalDependencies` | Dependencies to keep external to the bundle. ("all" (default), "none", or an array of module names) | string | `all` |
| `main` | The name of the main entry-point file. | string | `undefined` |
| `watch` | Run build when files change. | boolean | `false` |
| `poll` | Frequency of file watcher in ms. | number | `undefined` |
| `sourceMap` | Produce source maps. | boolean | `true` |
| `progress` | Log progress to the console while building. | boolean | `false` |
| `tsConfig` | The name of the Typescript configuration file. | string | `undefined` |
Expand All @@ -17,3 +18,4 @@ Build a Node application
| `optimization` | Defines the optimization level of the build. | boolean | `false` |
| `showCircularDependencies` | Show circular dependency warnings on builds. | boolean | `true` |
| `maxWorkers` | Number of workers to use for type checking. (defaults to # of CPUS - 2) | number | `undefined` |
| `webpackConfig` | Path to a function which takes a webpack config, context and returns the resulting webpack config | string | `undefined` |
32 changes: 32 additions & 0 deletions docs/api-builders/web-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# web-build

Build a web application

### Properties

| Name | Description | Type | Default value |
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ------- | ------------- |
| `namedChunks` | Names the produced bundles according to their entry file | boolean | `true` |
| `main` | The name of the main entry-point file. | string | `undefined` |
| `watch` | Enable re-building when files change. | boolean | `false` |
| `baseHref` | Base url for the application being built. | string | `/` |
| `deployUrl` | URL where the application will be deployed. | string | `undefined` |
| `vendorChunk` | Use a separate bundle containing only vendor libraries. | boolean | `true` |
| `commonChunk` | Use a separate bundle containing code used across multiple bundles. | boolean | `true` |
| `sourceMap` | Output sourcemaps. | boolean | `true` |
| `progress` | Log progress to the console while building. | boolean | `false` |
| `index` | HTML File which will be contain the application | string | `undefined` |
| `scripts` | External Scripts which will be included before the main application entry | array | `undefined` |
| `styles` | External Styles which will be included with the application | array | `undefined` |
| `tsConfig` | The name of the Typescript configuration file. | string | `undefined` |
| `outputHashing` | Define the output filename cache-busting hashing mode. | string | `none` |
| `optimization` | Enables optimization of the build output. | boolean | `undefined` |
| `extractCss` | Extract css into a .css file | boolean | `false` |
| `es2015Polyfills` | Conditional polyfills loaded in browsers which do not support ES2015. | string | `undefined` |
| `subresourceIntegrity` | Enables the use of subresource integrity validation. | boolean | `false` |
| `polyfills` | Polyfills to load before application | string | `undefined` |
| `statsJson` | Generates a 'stats.json' file which can be analyzed using tools such as: #webpack-bundle-analyzer' or https://webpack.github.io/analyse. | boolean | `false` |
| `extractLicenses` | Extract all licenses in a separate file, in the case of production builds only. | boolean | `false` |
| `showCircularDependencies` | Show circular dependency warnings on builds. | boolean | `true` |
| `maxWorkers` | Number of workers to use for type checking. (defaults to # of CPUS - 2) | number | `undefined` |
| `webpackConfig` | Path to a function which takes a webpack config, some context and returns the resulting webpack config | string | `undefined` |
18 changes: 18 additions & 0 deletions docs/api-builders/web-dev-server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# web-dev-server

Serve a web application

### Properties

| Name | Description | Type | Default value |
| ------------- | -------------------------------------------------------- | ------- | ------------- |
| `buildTarget` | Target which builds the application | string | `undefined` |
| `port` | Port to listen on. | number | `4200` |
| `host` | Host to listen on. | string | `localhost` |
| `ssl` | Serve using HTTPS. | boolean | `false` |
| `sslKey` | SSL key to use for serving HTTPS. | string | `undefined` |
| `sslCert` | SSL certificate to use for serving HTTPS. | string | `undefined` |
| `watch` | Watches for changes and rebuilds application | boolean | `true` |
| `liveReload` | Whether to reload the page on change, using live-reload. | boolean | `true` |
| `publicHost` | Public URL where the application will be served | string | `undefined` |
| `open` | Open the application in the browser. | boolean | `false` |
9 changes: 5 additions & 4 deletions docs/api-schematics/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ ng generate application ...

| Name | Alias | Description | Type | Default value |
| ------------------- | ----- | ------------------------------------------------- | ------- | ------------- |
| `style` | | The file extension to be used for style files. | string | `css` |
| `name` | | The name of the application. | string | `undefined` |
| `prefix` | p | The prefix to apply to generated selectors. | string | `undefined` |
| `framework` | | The Framework for the application. | string | `angular` |
| `directory` | | The directory of the new application. | string | `undefined` |
| `inlineStyle` | s | Specifies if the style will be in the ts file. | boolean | `false` |
| `inlineTemplate` | t | Specifies if the template will be in the ts file. | boolean | `false` |
| `viewEncapsulation` | | Specifies the view encapsulation strategy. | string | `undefined` |
| `routing` | | Generates a routing module. | boolean | `false` |
| `prefix` | p | The prefix to apply to generated selectors. | string | `undefined` |
| `directory` | | The directory of the new application. | string | `undefined` |
| `name` | | The name of the application. | string | `undefined` |
| `style` | | The file extension to be used for style files. | string | `css` |
| `skipTests` | S | Skip creating spec files. | boolean | `false` |
| `skipFormat` | | Skip formatting files | boolean | `false` |
| `skipPackageJson` | | Do not add dependencies to package.json. | boolean | `false` |
Expand Down
12 changes: 7 additions & 5 deletions docs/api-schematics/jest-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ ng generate jest-project ...

### Options

| Name | Alias | Description | Type | Default value |
| ----------------- | ----- | ------------------------------------------------------------ | ------- | ------------- |
| `project` | | The name of the project. | string | `undefined` |
| `skipSetupFile` | | Skips the setup file required for angular | boolean | `false` |
| `skipSerializers` | | Skips the serializers required to snapshot angular templates | boolean | `false` |
| Name | Alias | Description | Type | Default value |
| ----------------- | ----- | --------------------------------------------------------------------------- | ------- | ------------- |
| `project` | | The name of the project. | string | `undefined` |
| `skipSetupFile` | | [Deprecated]: Skips the setup file required for angular. (Use --setup-file) | boolean | `false` |
| `setupFile` | | The setup file to be generated | string | `angular` |
| `skipSerializers` | | Skips the serializers required to snapshot angular templates | boolean | `false` |
| `supportTsx` | | Setup tsx support | boolean | `false` |
88 changes: 88 additions & 0 deletions e2e/schematics/web.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import {
ensureProject,
runCLI,
uniq,
newApp,
newLib,
updateFile,
readFile,
runCLIAsync,
checkFilesExist
} from '../utils';

describe('Web Applications', () => {
it('should be able to generate a react application', async () => {
ensureProject();
const appName = uniq('app');
const libName = uniq('lib');

newApp(`${appName} --framework react`);
newLib(`${libName} --framework none`);

const mainPath = `apps/${appName}/src/main.tsx`;
updateFile(mainPath, `import '@proj/${libName}';\n` + readFile(mainPath));

const lintResults = runCLI(`lint ${appName}`);
expect(lintResults).toContain('All files pass linting.');
runCLI(`build ${appName}`);
checkFilesExist(
`dist/apps/${appName}/index.html`,
`dist/apps/${appName}/polyfills.js`,
`dist/apps/${appName}/runtime.js`,
`dist/apps/${appName}/vendor.js`,
`dist/apps/${appName}/main.js`,
`dist/apps/${appName}/styles.js`
);
runCLI(`build ${appName} --prod --output-hashing none`);
checkFilesExist(
`dist/apps/${appName}/index.html`,
`dist/apps/${appName}/polyfills.js`,
`dist/apps/${appName}/runtime.js`,
`dist/apps/${appName}/main.js`,
`dist/apps/${appName}/styles.css`
);
const testResults = await runCLIAsync(`test ${appName}`);
expect(testResults.stderr).toContain('Test Suites: 1 passed, 1 total');
const lintE2eResults = runCLI(`lint ${appName}-e2e`);
expect(lintE2eResults).toContain('All files pass linting.');
const e2eResults = runCLI(`e2e ${appName}-e2e`);
expect(e2eResults).toContain('All specs passed!');
}, 30000);

it('should be able to generate a custom-elements application', async () => {
ensureProject();
const appName = uniq('app');
const libName = uniq('lib');

newApp(`${appName} --framework custom-elements`);
newLib(`${libName} --framework none`);

const mainPath = `apps/${appName}/src/main.ts`;
updateFile(mainPath, `import '@proj/${libName}';\n` + readFile(mainPath));

const lintResults = runCLI(`lint ${appName}`);
expect(lintResults).toContain('All files pass linting.');
runCLI(`build ${appName}`);
checkFilesExist(
`dist/apps/${appName}/index.html`,
`dist/apps/${appName}/polyfills.js`,
`dist/apps/${appName}/runtime.js`,
`dist/apps/${appName}/main.js`,
`dist/apps/${appName}/styles.js`
);
runCLI(`build ${appName} --prod --output-hashing none`);
checkFilesExist(
`dist/apps/${appName}/index.html`,
`dist/apps/${appName}/polyfills.js`,
`dist/apps/${appName}/runtime.js`,
`dist/apps/${appName}/main.js`,
`dist/apps/${appName}/styles.css`
);
const testResults = await runCLIAsync(`test ${appName}`);
expect(testResults.stderr).toContain('Test Suites: 1 passed, 1 total');
const lintE2eResults = runCLI(`lint ${appName}-e2e`);
expect(lintE2eResults).toContain('All files pass linting.');
const e2eResults = runCLI(`e2e ${appName}-e2e`);
expect(e2eResults).toContain('All specs passed!');
}, 30000);
});
10 changes: 9 additions & 1 deletion e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@ export function copyMissingPackages(): void {
'@types/jasminewd2',
'@nestjs',
'express',
'@types/express'
'@types/express',

'react',
'react-dom',
'@types/react',
'@types/react-dom',
'react-testing-library',

'document-register-element'
];
modulesToCopy.forEach(m => copyNodeModule(projectName, m));
updateFile(
Expand Down
34 changes: 23 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,24 @@
"@angular/platform-browser-dynamic": "^7.2.1",
"@angular/router": "^7.2.1",
"@angular/upgrade": "^7.2.1",
"@nestjs/common": "5.5.0",
"@nestjs/core": "5.5.0",
"@nestjs/schematics": "5.11.2",
"@nestjs/testing": "5.5.0",
"@ngrx/effects": "7.1.0",
"@ngrx/router-store": "7.1.0",
"@ngrx/schematics": "7.1.0",
"@ngrx/store": "7.1.0",
"@ngrx/store-devtools": "7.1.0",
"@schematics/angular": "7.2.2",
"@types/express": "4.16.0",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/jest": "^23.3.2",
"@types/node": "~8.9.4",
"@types/prettier": "^1.10.0",
"@types/react": "^16.8.4",
"@types/react-dom": "^16.8.2",
"@types/webpack": "^4.4.24",
"@types/yargs": "^11.0.0",
"angular": "1.6.6",
Expand All @@ -57,9 +64,13 @@
"cosmiconfig": "^4.0.0",
"cypress": "3.1.0",
"cz-conventional-changelog": "^2.1.0",
"document-register-element": "^1.13.1",
"dotenv": "6.2.0",
"express": "4.16.3",
"fork-ts-checker-webpack-plugin": "^0.4.9",
"fs-extra": "5.0.0",
"graphviz": "^0.0.8",
"html-webpack-plugin": "^3.2.0",
"husky": "^1.0.0-rc.13",
"ignore": "^5.0.4",
"jasmine-core": "~2.99.1",
Expand All @@ -70,16 +81,19 @@
"jest-preset-angular": "^6.0.2",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.1",
"karma-webpack": "2.0.4",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-webpack": "2.0.4",
"license-webpack-plugin": "^1.4.0",
"ng-packagr": "4.3.1",
"npm-run-all": "^4.1.5",
"opn": "^5.3.0",
"precise-commits": "1.0.2",
"prettier": "1.15.3",
"react": "^16.8.3",
"react-dom": "^16.8.3",
"react-testing-library": "6.0.0",
"release-it": "^7.4.0",
"rxjs": "6.3.3",
"semver": "5.4.1",
Expand All @@ -96,22 +110,20 @@
"webpack-node-externals": "^1.7.2",
"yargs": "^11.0.0",
"yargs-parser": "10.0.0",
"zone.js": "^0.8.26",
"dotenv": "6.2.0",
"@nestjs/core": "5.5.0",
"@nestjs/common": "5.5.0",
"@nestjs/testing": "5.5.0",
"@nestjs/schematics": "5.11.2",
"express": "4.16.3",
"@types/express": "4.16.0"
"zone.js": "^0.8.26"
},
"author": "Victor Savkin",
"license": "MIT",
"jest": {
"modulePathIgnorePatterns": [
"tmp",
"collection/.*/files"
]
],
"collectCoverage": true,
"coverageReporters": [
"html"
],
"coverageDirectory": "coverage"
},
"config": {
"commitizen": {
Expand Down
1 change: 1 addition & 0 deletions packages/builders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"builders": "./src/builders.json",
"dependencies": {
"@angular-devkit/architect": "~0.13.1",
"@angular-devkit/build-angular": "~0.13.1",
"@angular-devkit/build-webpack": "~0.13.1",
"copy-webpack-plugin": "4.6.0",
"fork-ts-checker-webpack-plugin": "0.4.9",
Expand Down
10 changes: 10 additions & 0 deletions packages/builders/src/builders.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
"schema": "./node/execute/schema.json",
"description": "Execute a Node application"
},
"web-build": {
"class": "./web/build/web-build.builder",
"schema": "./web/build/schema.json",
"description": "Build a web application"
},
"web-dev-server": {
"class": "./web/dev-server/web-dev-server.builder",
"schema": "./web/dev-server/schema.json",
"description": "Serve a web application"
},
"jest": {
"class": "./jest/jest.builder",
"schema": "./jest/schema.json",
Expand Down
Loading

0 comments on commit 3bad40e

Please sign in to comment.