@nx/web 0.0.0-pr-22179-271588f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +68 -0
- package/babel.d.ts +1 -0
- package/babel.js +6 -0
- package/executors.json +16 -0
- package/generators.json +25 -0
- package/index.d.ts +3 -0
- package/index.js +9 -0
- package/migrations.json +51 -0
- package/package.json +45 -0
- package/src/executors/file-server/compat.d.ts +2 -0
- package/src/executors/file-server/compat.js +5 -0
- package/src/executors/file-server/file-server.impl.d.ts +8 -0
- package/src/executors/file-server/file-server.impl.js +210 -0
- package/src/executors/file-server/schema.d.ts +20 -0
- package/src/executors/file-server/schema.json +98 -0
- package/src/generators/application/application.d.ts +5 -0
- package/src/generators/application/application.js +353 -0
- package/src/generators/application/files/app-vite/.babelrc__tmpl__ +5 -0
- package/src/generators/application/files/app-vite/index.html__tmpl__ +16 -0
- package/src/generators/application/files/app-vite/public/favicon.ico +0 -0
- package/src/generators/application/files/app-vite/src/app/app.element.__style__ +424 -0
- package/src/generators/application/files/app-vite/src/app/app.element.spec.ts__tmpl__ +21 -0
- package/src/generators/application/files/app-vite/src/app/app.element.ts__tmpl__ +409 -0
- package/src/generators/application/files/app-vite/src/assets/.gitkeep +0 -0
- package/src/generators/application/files/app-vite/src/main.ts__tmpl__ +1 -0
- package/src/generators/application/files/app-vite/src/styles.__style__ +1 -0
- package/src/generators/application/files/app-vite/tsconfig.app.json +9 -0
- package/src/generators/application/files/app-vite/tsconfig.json__tmpl__ +27 -0
- package/src/generators/application/files/app-webpack/src/app/app.element.__style__ +424 -0
- package/src/generators/application/files/app-webpack/src/app/app.element.spec.ts__tmpl__ +21 -0
- package/src/generators/application/files/app-webpack/src/app/app.element.ts__tmpl__ +409 -0
- package/src/generators/application/files/app-webpack/src/assets/.gitkeep +0 -0
- package/src/generators/application/files/app-webpack/src/favicon.ico +0 -0
- package/src/generators/application/files/app-webpack/src/index.html +14 -0
- package/src/generators/application/files/app-webpack/src/main.ts__tmpl__ +1 -0
- package/src/generators/application/files/app-webpack/src/styles.__style__ +1 -0
- package/src/generators/application/files/app-webpack/tsconfig.app.json +9 -0
- package/src/generators/application/files/app-webpack/tsconfig.json +10 -0
- package/src/generators/application/files/app-webpack/webpack.config.js__tmpl__ +39 -0
- package/src/generators/application/schema.d.ts +21 -0
- package/src/generators/application/schema.json +113 -0
- package/src/generators/init/init.d.ts +4 -0
- package/src/generators/init/init.js +23 -0
- package/src/generators/init/schema.d.ts +5 -0
- package/src/generators/init/schema.json +28 -0
- package/src/generators/static-serve/schema.json +24 -0
- package/src/generators/static-serve/static-serve-configuration.d.ts +8 -0
- package/src/generators/static-serve/static-serve-configuration.js +73 -0
- package/src/migrations/update-15-0-0/add-babel-inputs.d.ts +2 -0
- package/src/migrations/update-15-0-0/add-babel-inputs.js +9 -0
- package/src/migrations/update-15-0-0/update-rollup-executor.d.ts +2 -0
- package/src/migrations/update-15-0-0/update-rollup-executor.js +33 -0
- package/src/migrations/update-15-5-4/update-babel-preset.d.ts +2 -0
- package/src/migrations/update-15-5-4/update-babel-preset.js +32 -0
- package/src/migrations/update-15-9-1/add-dropped-dependencies.d.ts +2 -0
- package/src/migrations/update-15-9-1/add-dropped-dependencies.js +35 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/migrations/update-16-0-0-update-executors/update-16-0-0-update-executors.d.ts +2 -0
- package/src/migrations/update-16-0-0-update-executors/update-16-0-0-update-executors.js +34 -0
- package/src/plugins/webpack-nx-build-coordination-plugin.d.ts +1 -0
- package/src/plugins/webpack-nx-build-coordination-plugin.js +5 -0
- package/src/utils/fs.d.ts +1 -0
- package/src/utils/fs.js +4 -0
- package/src/utils/has-webpack-plugin.d.ts +2 -0
- package/src/utils/has-webpack-plugin.js +11 -0
- package/src/utils/normalize.d.ts +1 -0
- package/src/utils/normalize.js +4 -0
- package/src/utils/versions.d.ts +4 -0
- package/src/utils/versions.js +7 -0
- package/src/utils/wait-for-port-open.d.ts +5 -0
- package/src/utils/wait-for-port-open.js +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-2023 Narwhal Technologies Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<p style="text-align: center;">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
|
|
4
|
+
<img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
|
|
5
|
+
</picture>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<div style="text-align: center;">
|
|
9
|
+
|
|
10
|
+
[](https://circleci.com/gh/nrwl/nx)
|
|
11
|
+
[]()
|
|
12
|
+
[](https://www.npmjs.com/@nx/workspace)
|
|
13
|
+
[]()
|
|
14
|
+
[](http://commitizen.github.io/cz-cli/)
|
|
15
|
+
[](https://gitter.im/nrwl-nx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
16
|
+
[](https://go.nx.dev/community)
|
|
17
|
+
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
<hr>
|
|
22
|
+
|
|
23
|
+
# Nx: Smart Monorepos · Fast CI
|
|
24
|
+
|
|
25
|
+
Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
|
|
26
|
+
|
|
27
|
+
This package is a [Web plugin for Nx](https://nx.dev/packages/web).
|
|
28
|
+
|
|
29
|
+
## Getting Started
|
|
30
|
+
|
|
31
|
+
### Creating an Nx Workspace
|
|
32
|
+
|
|
33
|
+
**Using `npx`**
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npx create-nx-workspace
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Using `npm init`**
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm init nx-workspace
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Using `yarn create`**
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
yarn create nx-workspace
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Adding Nx to an Existing Repository
|
|
52
|
+
|
|
53
|
+
Run:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npx nx@latest init
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Documentation & Resources
|
|
60
|
+
|
|
61
|
+
- [Nx.Dev: Documentation, Guides, Tutorials](https://nx.dev)
|
|
62
|
+
- [Intro to Nx](https://nx.dev/getting-started/intro)
|
|
63
|
+
- [Official Nx YouTube Channel](https://www.youtube.com/@NxDevtools)
|
|
64
|
+
- [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
|
|
65
|
+
|
|
66
|
+
<p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
|
|
67
|
+
width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
|
|
68
|
+
|
package/babel.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare const nxJsBabelPreset: any;
|
package/babel.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const nxJsBabelPreset = require('@nx/js/babel');
|
|
2
|
+
/** @deprecated Use `@nx/js/babel`. */
|
|
3
|
+
module.exports = function (api, options = {}) {
|
|
4
|
+
console.warn('`@nx/web/babel` has been deprecated. Use `@nx/js/babel` instead in your .babelrc files.');
|
|
5
|
+
return nxJsBabelPreset(api, options);
|
|
6
|
+
};
|
package/executors.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"builders": {
|
|
3
|
+
"file-server": {
|
|
4
|
+
"implementation": "./src/executors/file-server/compat",
|
|
5
|
+
"schema": "./src/executors/file-server/schema.json",
|
|
6
|
+
"description": "Serve a web application from a folder."
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"executors": {
|
|
10
|
+
"file-server": {
|
|
11
|
+
"implementation": "./src/executors/file-server/file-server.impl",
|
|
12
|
+
"schema": "./src/executors/file-server/schema.json",
|
|
13
|
+
"description": "Serve a web application from a folder."
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
package/generators.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nx/web",
|
|
3
|
+
"version": "0.1",
|
|
4
|
+
"extends": ["@nx/workspace"],
|
|
5
|
+
"generators": {
|
|
6
|
+
"init": {
|
|
7
|
+
"factory": "./src/generators/init/init#webInitGenerator",
|
|
8
|
+
"schema": "./src/generators/init/schema.json",
|
|
9
|
+
"description": "Add `@nrwl/web` to a project.",
|
|
10
|
+
"hidden": true
|
|
11
|
+
},
|
|
12
|
+
"application": {
|
|
13
|
+
"factory": "./src/generators/application/application#applicationGeneratorInternal",
|
|
14
|
+
"schema": "./src/generators/application/schema.json",
|
|
15
|
+
"aliases": ["app"],
|
|
16
|
+
"x-type": "application",
|
|
17
|
+
"description": "Create an web application."
|
|
18
|
+
},
|
|
19
|
+
"static-config": {
|
|
20
|
+
"factory": "./src/generators/static-serve/static-serve-configuration",
|
|
21
|
+
"schema": "./src/generators/static-serve/schema.json",
|
|
22
|
+
"description": "Add a new static-serve target to a project."
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.webStaticServeGenerator = exports.applicationGenerator = exports.webInitGenerator = void 0;
|
|
4
|
+
var init_1 = require("./src/generators/init/init");
|
|
5
|
+
Object.defineProperty(exports, "webInitGenerator", { enumerable: true, get: function () { return init_1.webInitGenerator; } });
|
|
6
|
+
var application_1 = require("./src/generators/application/application");
|
|
7
|
+
Object.defineProperty(exports, "applicationGenerator", { enumerable: true, get: function () { return application_1.applicationGenerator; } });
|
|
8
|
+
var static_serve_configuration_1 = require("./src/generators/static-serve/static-serve-configuration");
|
|
9
|
+
Object.defineProperty(exports, "webStaticServeGenerator", { enumerable: true, get: function () { return static_serve_configuration_1.webStaticServeGenerator; } });
|
package/migrations.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"generators": {
|
|
3
|
+
"add-babel-inputs": {
|
|
4
|
+
"cli": "nx",
|
|
5
|
+
"version": "15.0.0-beta.0",
|
|
6
|
+
"description": "Adds babel.config.json to the hash of all tasks",
|
|
7
|
+
"factory": "./src/migrations/update-15-0-0/add-babel-inputs"
|
|
8
|
+
},
|
|
9
|
+
"update-rollup-executor": {
|
|
10
|
+
"cli": "nx",
|
|
11
|
+
"version": "15.0.0-beta.1",
|
|
12
|
+
"description": "Update usages of rollup executors to @nrwl/rollup",
|
|
13
|
+
"factory": "./src/migrations/update-15-0-0/update-rollup-executor"
|
|
14
|
+
},
|
|
15
|
+
"update-babel-preset": {
|
|
16
|
+
"cli": "nx",
|
|
17
|
+
"version": "15.5.4-beta.0",
|
|
18
|
+
"description": "Update `@nrwl/web/babel` preset to `@nrwl/js/babel` for projects that have a .babelrc file.",
|
|
19
|
+
"factory": "./src/migrations/update-15-5-4/update-babel-preset"
|
|
20
|
+
},
|
|
21
|
+
"add-dropped-dependencies": {
|
|
22
|
+
"cli": "nx",
|
|
23
|
+
"version": "15.9.1",
|
|
24
|
+
"description": "Add @nrwl/linter, @nrwl/cypress, @nrwl/jest, @nrwl/rollup if they are used",
|
|
25
|
+
"factory": "./src/migrations/update-15-9-1/add-dropped-dependencies"
|
|
26
|
+
},
|
|
27
|
+
"update-16-0-0-add-nx-packages": {
|
|
28
|
+
"cli": "nx",
|
|
29
|
+
"version": "16.0.0-beta.1",
|
|
30
|
+
"description": "Replace @nrwl/web with @nx/web",
|
|
31
|
+
"implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
|
|
32
|
+
},
|
|
33
|
+
"update-16-0-0-update-executors": {
|
|
34
|
+
"cli": "nx",
|
|
35
|
+
"version": "16.0.0-beta.4",
|
|
36
|
+
"description": "Replace @nrwl/web executors with @nx/webpack and @nx/rollup",
|
|
37
|
+
"implementation": "./src/migrations/update-16-0-0-update-executors/update-16-0-0-update-executors"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"packageJsonUpdates": {
|
|
41
|
+
"17.3.0": {
|
|
42
|
+
"version": "17.3.0-beta.3",
|
|
43
|
+
"packages": {
|
|
44
|
+
"@types/node": {
|
|
45
|
+
"version": "18.16.9",
|
|
46
|
+
"alwaysAddToPackageJson": false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nx/web",
|
|
3
|
+
"version": "0.0.0-pr-22179-271588f",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "The Nx Plugin for Web Components contains generators for managing Web Component applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Cypress, and Storybook.\n\n- Scaffolding for creating buildable libraries that can be published to npm.\n\n- Utilities for automatic workspace refactoring.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/nrwl/nx.git",
|
|
9
|
+
"directory": "packages/web"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"Monorepo",
|
|
13
|
+
"Web",
|
|
14
|
+
"Jest",
|
|
15
|
+
"Cypress",
|
|
16
|
+
"CLI"
|
|
17
|
+
],
|
|
18
|
+
"main": "./index.js",
|
|
19
|
+
"typings": "./index.d.ts",
|
|
20
|
+
"author": "Victor Savkin",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/nrwl/nx/issues"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://nx.dev",
|
|
26
|
+
"generators": "./generators.json",
|
|
27
|
+
"executors": "./executors.json",
|
|
28
|
+
"ng-update": {
|
|
29
|
+
"requirements": {},
|
|
30
|
+
"migrations": "./migrations.json"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"chalk": "^4.1.0",
|
|
34
|
+
"detect-port": "^1.5.1",
|
|
35
|
+
"http-server": "^14.1.0",
|
|
36
|
+
"tslib": "^2.3.0",
|
|
37
|
+
"@nx/devkit": "0.0.0-pr-22179-271588f",
|
|
38
|
+
"@nx/js": "0.0.0-pr-22179-271588f",
|
|
39
|
+
"@nrwl/web": "0.0.0-pr-22179-271588f"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"type": "commonjs"
|
|
45
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { Schema } from './schema';
|
|
3
|
+
export default function fileServerExecutor(options: Schema, context: ExecutorContext): AsyncGenerator<{
|
|
4
|
+
success: boolean;
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
}, {
|
|
7
|
+
success: boolean;
|
|
8
|
+
}, unknown>;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const child_process_1 = require("child_process");
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const os_1 = require("os");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const package_json_1 = require("nx/src/utils/package-json");
|
|
10
|
+
const detectPort = require("detect-port");
|
|
11
|
+
const client_1 = require("nx/src/daemon/client/client");
|
|
12
|
+
const utils_1 = require("nx/src/tasks-runner/utils");
|
|
13
|
+
// platform specific command name
|
|
14
|
+
const pmCmd = (0, os_1.platform)() === 'win32' ? `npx.cmd` : 'npx';
|
|
15
|
+
function getHttpServerArgs(options) {
|
|
16
|
+
const args = [`-c${options.cacheSeconds}`];
|
|
17
|
+
if (options.cors) {
|
|
18
|
+
args.push(`--cors`);
|
|
19
|
+
}
|
|
20
|
+
if (options.host) {
|
|
21
|
+
args.push(`-a=${options.host}`);
|
|
22
|
+
}
|
|
23
|
+
if (options.ssl) {
|
|
24
|
+
args.push(`-S`);
|
|
25
|
+
}
|
|
26
|
+
if (options.sslCert) {
|
|
27
|
+
args.push(`-C=${options.sslCert}`);
|
|
28
|
+
}
|
|
29
|
+
if (options.sslKey) {
|
|
30
|
+
args.push(`-K=${options.sslKey}`);
|
|
31
|
+
}
|
|
32
|
+
if (options.proxyUrl) {
|
|
33
|
+
args.push(`-P=${options.proxyUrl}`);
|
|
34
|
+
}
|
|
35
|
+
if (options.gzip) {
|
|
36
|
+
args.push('-g');
|
|
37
|
+
}
|
|
38
|
+
if (options.brotli) {
|
|
39
|
+
args.push('-b');
|
|
40
|
+
}
|
|
41
|
+
if (options.proxyOptions) {
|
|
42
|
+
Object.keys(options.proxyOptions).forEach((key) => {
|
|
43
|
+
args.push(`--proxy-options.${key}=${options.proxyOptions[key]}`);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return args;
|
|
47
|
+
}
|
|
48
|
+
function getBuildTargetCommand(options, context) {
|
|
49
|
+
const target = (0, devkit_1.parseTargetString)(options.buildTarget, context);
|
|
50
|
+
const cmd = ['nx', 'run'];
|
|
51
|
+
if (target.configuration) {
|
|
52
|
+
cmd.push(`${target.project}:${target.target}:${target.configuration}`);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
cmd.push(`${target.project}:${target.target}`);
|
|
56
|
+
}
|
|
57
|
+
if (options.parallel) {
|
|
58
|
+
cmd.push(`--parallel`);
|
|
59
|
+
}
|
|
60
|
+
if (options.maxParallel) {
|
|
61
|
+
cmd.push(`--maxParallel=${options.maxParallel}`);
|
|
62
|
+
}
|
|
63
|
+
return cmd;
|
|
64
|
+
}
|
|
65
|
+
function getBuildTargetOutputPath(options, context) {
|
|
66
|
+
if (options.staticFilePath) {
|
|
67
|
+
return options.staticFilePath;
|
|
68
|
+
}
|
|
69
|
+
let outputPath;
|
|
70
|
+
try {
|
|
71
|
+
const target = (0, devkit_1.parseTargetString)(options.buildTarget, context);
|
|
72
|
+
const buildOptions = (0, devkit_1.readTargetOptions)(target, context);
|
|
73
|
+
if (buildOptions?.outputPath) {
|
|
74
|
+
outputPath = buildOptions.outputPath;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const project = context.projectGraph.nodes[context.projectName];
|
|
78
|
+
const buildTarget = project.data.targets[target.target];
|
|
79
|
+
outputPath = buildTarget.outputs?.[0];
|
|
80
|
+
if (outputPath)
|
|
81
|
+
outputPath = (0, utils_1.interpolate)(outputPath, {
|
|
82
|
+
projectName: project.data.name,
|
|
83
|
+
projectRoot: project.data.root,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
throw new Error(`Invalid buildTarget: ${options.buildTarget}`);
|
|
89
|
+
}
|
|
90
|
+
if (!outputPath) {
|
|
91
|
+
throw new Error(`Unable to get the outputPath from buildTarget ${options.buildTarget}. Make sure ${options.buildTarget} has an outputPath property or manually provide an staticFilePath property`);
|
|
92
|
+
}
|
|
93
|
+
return outputPath;
|
|
94
|
+
}
|
|
95
|
+
function createFileWatcher(project, changeHandler) {
|
|
96
|
+
return client_1.daemonClient.registerFileWatcher({
|
|
97
|
+
watchProjects: project ? [project] : 'all',
|
|
98
|
+
includeGlobalWorkspaceFiles: true,
|
|
99
|
+
includeDependentProjects: true,
|
|
100
|
+
}, async (error, val) => {
|
|
101
|
+
if (error === 'closed') {
|
|
102
|
+
throw new Error('Watch error: Daemon closed the connection');
|
|
103
|
+
}
|
|
104
|
+
else if (error) {
|
|
105
|
+
throw new Error(`Watch error: ${error?.message ?? 'Unknown'}`);
|
|
106
|
+
}
|
|
107
|
+
else if (val?.changedFiles.length > 0) {
|
|
108
|
+
changeHandler();
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
async function* fileServerExecutor(options, context) {
|
|
113
|
+
if (!options.buildTarget && !options.staticFilePath) {
|
|
114
|
+
throw new Error("You must set either 'buildTarget' or 'staticFilePath'.");
|
|
115
|
+
}
|
|
116
|
+
if (options.watch && !options.buildTarget) {
|
|
117
|
+
throw new Error("Watch error: You can only specify 'watch' when 'buildTarget' is set.");
|
|
118
|
+
}
|
|
119
|
+
let running = false;
|
|
120
|
+
let disposeWatch;
|
|
121
|
+
if (options.buildTarget) {
|
|
122
|
+
const run = () => {
|
|
123
|
+
if (!running) {
|
|
124
|
+
running = true;
|
|
125
|
+
/**
|
|
126
|
+
* Expose a variable to the build target to know if it's being run by the serve-static executor
|
|
127
|
+
* This is useful because a config might need to change if it's being run by serve-static without the user's input
|
|
128
|
+
* or if being ran by another executor (eg. E2E tests)
|
|
129
|
+
* */
|
|
130
|
+
process.env.NX_SERVE_STATIC_BUILD_RUNNING = 'true';
|
|
131
|
+
try {
|
|
132
|
+
const args = getBuildTargetCommand(options, context);
|
|
133
|
+
(0, child_process_1.execFileSync)(pmCmd, args, {
|
|
134
|
+
stdio: [0, 1, 2],
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
throw new Error(`Build target failed: ${chalk.bold(options.buildTarget)}`);
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
process.env.NX_SERVE_STATIC_BUILD_RUNNING = undefined;
|
|
142
|
+
running = false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
if (options.watch) {
|
|
147
|
+
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
|
|
148
|
+
disposeWatch = await createFileWatcher(context.projectName, run);
|
|
149
|
+
}
|
|
150
|
+
// perform initial run
|
|
151
|
+
run();
|
|
152
|
+
}
|
|
153
|
+
const outputPath = getBuildTargetOutputPath(options, context);
|
|
154
|
+
if (options.spa) {
|
|
155
|
+
const src = (0, path_1.join)(outputPath, 'index.html');
|
|
156
|
+
const dst = (0, path_1.join)(outputPath, '404.html');
|
|
157
|
+
// See: https://github.com/http-party/http-server#magic-files
|
|
158
|
+
(0, fs_1.copyFileSync)(src, dst);
|
|
159
|
+
}
|
|
160
|
+
const args = getHttpServerArgs(options);
|
|
161
|
+
const { path: pathToHttpServerPkgJson, packageJson } = (0, package_json_1.readModulePackageJson)('http-server', module.paths);
|
|
162
|
+
const pathToHttpServerBin = packageJson.bin['http-server'];
|
|
163
|
+
const pathToHttpServer = (0, path_1.resolve)(pathToHttpServerPkgJson.replace('package.json', ''), pathToHttpServerBin);
|
|
164
|
+
// detect port as close to when used to prevent port being used by another process
|
|
165
|
+
// when running in parallel
|
|
166
|
+
const port = await detectPort(options.port || 8080);
|
|
167
|
+
args.push(`-p=${port}`);
|
|
168
|
+
const serve = (0, child_process_1.fork)(pathToHttpServer, [outputPath, ...args], {
|
|
169
|
+
stdio: 'pipe',
|
|
170
|
+
cwd: context.root,
|
|
171
|
+
env: {
|
|
172
|
+
FORCE_COLOR: 'true',
|
|
173
|
+
...process.env,
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
const processExitListener = () => {
|
|
177
|
+
serve.kill();
|
|
178
|
+
if (disposeWatch) {
|
|
179
|
+
disposeWatch();
|
|
180
|
+
}
|
|
181
|
+
if (options.spa) {
|
|
182
|
+
(0, fs_1.unlinkSync)((0, path_1.join)(outputPath, '404.html'));
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
process.on('exit', processExitListener);
|
|
186
|
+
process.on('SIGTERM', processExitListener);
|
|
187
|
+
serve.stdout.on('data', (chunk) => {
|
|
188
|
+
if (chunk.toString().indexOf('GET') === -1) {
|
|
189
|
+
process.stdout.write(chunk);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
serve.stderr.on('data', (chunk) => {
|
|
193
|
+
process.stderr.write(chunk);
|
|
194
|
+
});
|
|
195
|
+
yield {
|
|
196
|
+
success: true,
|
|
197
|
+
baseUrl: `${options.ssl ? 'https' : 'http'}://${options.host}:${port}`,
|
|
198
|
+
};
|
|
199
|
+
return new Promise((res) => {
|
|
200
|
+
serve.on('exit', (code) => {
|
|
201
|
+
if (code == 0) {
|
|
202
|
+
res({ success: true });
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
res({ success: false });
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
exports.default = fileServerExecutor;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface Schema {
|
|
2
|
+
host?: string;
|
|
3
|
+
port?: number;
|
|
4
|
+
ssl?: boolean;
|
|
5
|
+
sslKey?: string;
|
|
6
|
+
sslCert?: string;
|
|
7
|
+
proxyUrl?: string;
|
|
8
|
+
buildTarget?: string;
|
|
9
|
+
parallel: boolean;
|
|
10
|
+
maxParallel?: number;
|
|
11
|
+
withDeps: boolean;
|
|
12
|
+
proxyOptions?: object;
|
|
13
|
+
watch?: boolean;
|
|
14
|
+
spa: boolean;
|
|
15
|
+
staticFilePath?: string;
|
|
16
|
+
cors?: boolean;
|
|
17
|
+
gzip?: boolean;
|
|
18
|
+
brotli?: boolean;
|
|
19
|
+
cacheSeconds?: number;
|
|
20
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 2,
|
|
3
|
+
"outputCapture": "direct-nodejs",
|
|
4
|
+
"title": "File Server",
|
|
5
|
+
"description": "Serve a web application from a folder.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"cli": "nx",
|
|
8
|
+
"properties": {
|
|
9
|
+
"buildTarget": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "Target which builds the application."
|
|
12
|
+
},
|
|
13
|
+
"parallel": {
|
|
14
|
+
"type": "boolean",
|
|
15
|
+
"description": "Build the target in parallel.",
|
|
16
|
+
"default": true
|
|
17
|
+
},
|
|
18
|
+
"maxParallel": {
|
|
19
|
+
"type": "number",
|
|
20
|
+
"description": "Max number of parallel jobs."
|
|
21
|
+
},
|
|
22
|
+
"port": {
|
|
23
|
+
"type": "number",
|
|
24
|
+
"description": "Port to listen on.",
|
|
25
|
+
"default": 4200
|
|
26
|
+
},
|
|
27
|
+
"host": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"description": "Host to listen on.",
|
|
30
|
+
"default": "localhost"
|
|
31
|
+
},
|
|
32
|
+
"ssl": {
|
|
33
|
+
"type": "boolean",
|
|
34
|
+
"description": "Serve using `HTTPS`.",
|
|
35
|
+
"default": false
|
|
36
|
+
},
|
|
37
|
+
"sslKey": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"description": "SSL key to use for serving `HTTPS`."
|
|
40
|
+
},
|
|
41
|
+
"sslCert": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"description": "SSL certificate to use for serving `HTTPS`."
|
|
44
|
+
},
|
|
45
|
+
"proxyUrl": {
|
|
46
|
+
"type": "string",
|
|
47
|
+
"description": "URL to proxy unhandled requests to."
|
|
48
|
+
},
|
|
49
|
+
"proxyOptions": {
|
|
50
|
+
"type": "object",
|
|
51
|
+
"description": "Options for the proxy used by `http-server`.",
|
|
52
|
+
"default": {},
|
|
53
|
+
"properties": {
|
|
54
|
+
"secure": {
|
|
55
|
+
"type": "boolean",
|
|
56
|
+
"default": false
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"additionalProperties": true
|
|
60
|
+
},
|
|
61
|
+
"watch": {
|
|
62
|
+
"type": "boolean",
|
|
63
|
+
"description": "Watch for file changes.",
|
|
64
|
+
"default": true
|
|
65
|
+
},
|
|
66
|
+
"spa": {
|
|
67
|
+
"type": "boolean",
|
|
68
|
+
"description": "Redirect 404 errors to index.html (useful for SPA's)",
|
|
69
|
+
"default": false,
|
|
70
|
+
"x-priority": "important"
|
|
71
|
+
},
|
|
72
|
+
"staticFilePath": {
|
|
73
|
+
"type": "string",
|
|
74
|
+
"description": "Path where the build artifacts are located. If not provided then it will be infered from the buildTarget executor options as outputPath"
|
|
75
|
+
},
|
|
76
|
+
"cors": {
|
|
77
|
+
"type": "boolean",
|
|
78
|
+
"description": "Enable CORS",
|
|
79
|
+
"default": true
|
|
80
|
+
},
|
|
81
|
+
"gzip": {
|
|
82
|
+
"type": "boolean",
|
|
83
|
+
"description": "Enable gzip compression",
|
|
84
|
+
"default": false
|
|
85
|
+
},
|
|
86
|
+
"brotli": {
|
|
87
|
+
"type": "boolean",
|
|
88
|
+
"description": "Enable brotli compression",
|
|
89
|
+
"default": false
|
|
90
|
+
},
|
|
91
|
+
"cacheSeconds": {
|
|
92
|
+
"type": "number",
|
|
93
|
+
"description": "Set cache time (in seconds) for cache-control max-age header. To disable caching, use -1. Caching defaults to disabled.",
|
|
94
|
+
"default": -1
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"additionalProperties": false
|
|
98
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
import { Schema } from './schema';
|
|
3
|
+
export declare function applicationGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
4
|
+
export declare function applicationGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
5
|
+
export default applicationGenerator;
|