Skip to content

Commit ce2de62

Browse files
committed
chore: add dynamic tempalte logic to inject projectName
1 parent 2f07113 commit ce2de62

17 files changed

+145
-291
lines changed

README.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,14 @@ This build plugin is a utility for supporting Angular Universal on Netlify.
1212

1313
## Installation and Configuration
1414

15-
The schematic commands will create a `netlify.toml` in the root of your project, if it doesn't already exist. Your file should include the correct build command, publish directory, and plugins section below. Note: the build command requires you to include your custom project name (as indicated in your angular.json) where designated below:
16-
17-
```toml
18-
[build]
19-
command = "ng build --configuration production && ng run {projectName}:serverless:production"
20-
publish = "dist/netlify-serverless/browser"
21-
22-
[[plugins]]
23-
package = "@netlify/plugin-angular-serverless"
24-
```
25-
26-
## Installation and Configuration
27-
2815
### Manual Installation
2916

3017
Create a `netlify.toml` in the root of your project. Your file should include the plugins section below:
3118

3219
```toml
3320
[build]
3421
command = "ng build --configuration production && ng run {projectName}:serverless:production"
35-
publish = "dist/netlify-serverless/browser"
22+
publish = "dist/{projectName}/browser"
3623

3724
[[plugins]]
3825
package = "@netlify/plugin-angular-serverless"
@@ -41,7 +28,7 @@ Create a `netlify.toml` in the root of your project. Your file should include th
4128
If you'd like to install this plugin at a fixed version, install it via your package manager:
4229

4330
```bash
44-
# yarn add @netlify/plugin-angular-universal
31+
yarn add @netlify/plugin-angular-universal
4532
npm install --save @netlify/plugin-angular-universal
4633
```
4734

@@ -50,6 +37,17 @@ in our docs.
5037

5138
## CLI Usage
5239

40+
### Plugin Side Effects
41+
42+
This plugin will make direct changes to your project source when run via the CLI:
43+
44+
1. It will modify your angular.json to add a `serverless` project configuration.
45+
2. It will add `serverless.ts` and `tsconfig.serverless.json` files.
46+
47+
It is up to you whether to commit these changes to your project. If the plugin makes updates to these files or configurations, it will overwrite what you'd previously committed, and you can commit the new updates. Otherwise, you can stash and ignore them.
48+
49+
### Workflow
50+
5351
If you'd like to build and deploy your project using the
5452
[Netlify CLI](https://docs.netlify.com/cli/get-started/), we recommend this
5553
workflow to manage git tracking plugin-generated files:

demo/angular.json

Lines changed: 1 addition & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -1,161 +1 @@
1-
{
2-
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3-
"cli": {
4-
"analytics": false
5-
},
6-
"version": 1,
7-
"newProjectRoot": "projects",
8-
"projects": {
9-
"angular-bfdx": {
10-
"projectType": "application",
11-
"schematics": {},
12-
"root": "",
13-
"sourceRoot": "src",
14-
"prefix": "app",
15-
"architect": {
16-
"build": {
17-
"builder": "@angular-devkit/build-angular:browser",
18-
"options": {
19-
"outputPath": "dist/angular-bfdx/browser",
20-
"index": "src/index.html",
21-
"main": "src/main.ts",
22-
"polyfills": "src/polyfills.ts",
23-
"tsConfig": "tsconfig.app.json",
24-
"aot": true,
25-
"assets": ["src/favicon.ico", "src/assets"],
26-
"styles": ["src/styles.css"],
27-
"scripts": []
28-
},
29-
"configurations": {
30-
"production": {
31-
"fileReplacements": [
32-
{
33-
"replace": "src/environments/environment.ts",
34-
"with": "src/environments/environment.prod.ts"
35-
}
36-
],
37-
"optimization": true,
38-
"outputHashing": "none",
39-
"sourceMap": false,
40-
"namedChunks": false,
41-
"extractLicenses": true,
42-
"vendorChunk": false,
43-
"buildOptimizer": true,
44-
"budgets": [
45-
{
46-
"type": "initial",
47-
"maximumWarning": "2mb",
48-
"maximumError": "5mb"
49-
},
50-
{
51-
"type": "anyComponentStyle",
52-
"maximumWarning": "6kb",
53-
"maximumError": "10kb"
54-
}
55-
]
56-
}
57-
}
58-
},
59-
"serve": {
60-
"builder": "@angular-devkit/build-angular:dev-server",
61-
"options": {
62-
"browserTarget": "angular-bfdx:build"
63-
},
64-
"configurations": {
65-
"production": {
66-
"browserTarget": "angular-bfdx:build:production"
67-
}
68-
}
69-
},
70-
"extract-i18n": {
71-
"builder": "@angular-devkit/build-angular:extract-i18n",
72-
"options": {
73-
"browserTarget": "angular-bfdx:build"
74-
}
75-
},
76-
"test": {
77-
"builder": "@angular-devkit/build-angular:karma",
78-
"options": {
79-
"main": "src/test.ts",
80-
"polyfills": "src/polyfills.ts",
81-
"tsConfig": "tsconfig.spec.json",
82-
"karmaConfig": "karma.conf.js",
83-
"assets": ["src/favicon.ico", "src/assets"],
84-
"styles": ["src/styles.css"],
85-
"scripts": []
86-
}
87-
},
88-
"lint": {
89-
"builder": "@angular-devkit/build-angular:tslint",
90-
"options": {
91-
"tsConfig": [
92-
"tsconfig.app.json",
93-
"tsconfig.spec.json",
94-
"e2e/tsconfig.json",
95-
"tsconfig.server.json"
96-
],
97-
"exclude": ["**/node_modules/**"]
98-
}
99-
},
100-
"e2e": {
101-
"builder": "@angular-devkit/build-angular:protractor",
102-
"options": {
103-
"protractorConfig": "e2e/protractor.conf.js",
104-
"devServerTarget": "angular-bfdx:serve"
105-
},
106-
"configurations": {
107-
"production": {
108-
"devServerTarget": "angular-bfdx:serve:production"
109-
}
110-
}
111-
},
112-
"server": {
113-
"builder": "@angular-devkit/build-angular:server",
114-
"options": {
115-
"outputPath": "dist/angular-bfdx/server",
116-
"main": "server.ts",
117-
"tsConfig": "tsconfig.server.json"
118-
},
119-
"configurations": {
120-
"production": {
121-
"outputHashing": "media",
122-
"fileReplacements": [
123-
{
124-
"replace": "src/environments/environment.ts",
125-
"with": "src/environments/environment.prod.ts"
126-
}
127-
],
128-
"sourceMap": false,
129-
"optimization": true
130-
}
131-
}
132-
},
133-
"serve-ssr": {
134-
"builder": "@nguniversal/builders:ssr-dev-server",
135-
"options": {
136-
"browserTarget": "angular-bfdx:build",
137-
"serverTarget": "angular-bfdx:server"
138-
},
139-
"configurations": {
140-
"production": {
141-
"browserTarget": "angular-bfdx:build:production",
142-
"serverTarget": "angular-bfdx:server:production"
143-
}
144-
}
145-
},
146-
"prerender": {
147-
"builder": "@nguniversal/builders:prerender",
148-
"options": {
149-
"browserTarget": "angular-bfdx:build:production",
150-
"serverTarget": "angular-bfdx:server:production",
151-
"routes": ["/"]
152-
},
153-
"configurations": {
154-
"production": {}
155-
}
156-
}
157-
}
158-
}
159-
},
160-
"defaultProject": "angular-bfdx"
161-
}
1+
{"$schema":"./node_modules/@angular/cli/lib/config/schema.json","cli":{"analytics":false},"version":1,"newProjectRoot":"projects","projects":{"angular-bfdx":{"projectType":"application","schematics":{},"root":"","sourceRoot":"src","prefix":"app","architect":{"build":{"builder":"@angular-devkit/build-angular:browser","options":{"outputPath":"dist/angular-bfdx/browser","index":"src/index.html","main":"src/main.ts","polyfills":"src/polyfills.ts","tsConfig":"tsconfig.app.json","aot":true,"assets":["src/favicon.ico","src/assets"],"styles":["src/styles.css"],"scripts":[]},"configurations":{"production":{"fileReplacements":[{"replace":"src/environments/environment.ts","with":"src/environments/environment.prod.ts"}],"optimization":true,"outputHashing":"none","sourceMap":false,"namedChunks":false,"extractLicenses":true,"vendorChunk":false,"buildOptimizer":true,"budgets":[{"type":"initial","maximumWarning":"2mb","maximumError":"5mb"},{"type":"anyComponentStyle","maximumWarning":"6kb","maximumError":"10kb"}]}}},"serve":{"builder":"@angular-devkit/build-angular:dev-server","options":{"browserTarget":"angular-bfdx:build"},"configurations":{"production":{"browserTarget":"angular-bfdx:build:production"}}},"extract-i18n":{"builder":"@angular-devkit/build-angular:extract-i18n","options":{"browserTarget":"angular-bfdx:build"}},"test":{"builder":"@angular-devkit/build-angular:karma","options":{"main":"src/test.ts","polyfills":"src/polyfills.ts","tsConfig":"tsconfig.spec.json","karmaConfig":"karma.conf.js","assets":["src/favicon.ico","src/assets"],"styles":["src/styles.css"],"scripts":[]}},"lint":{"builder":"@angular-devkit/build-angular:tslint","options":{"tsConfig":["tsconfig.app.json","tsconfig.spec.json","e2e/tsconfig.json","tsconfig.server.json"],"exclude":["**/node_modules/**"]}},"e2e":{"builder":"@angular-devkit/build-angular:protractor","options":{"protractorConfig":"e2e/protractor.conf.js","devServerTarget":"angular-bfdx:serve"},"configurations":{"production":{"devServerTarget":"angular-bfdx:serve:production"}}},"server":{"builder":"@angular-devkit/build-angular:server","options":{"outputPath":"dist/angular-bfdx/server","main":"server.ts","tsConfig":"tsconfig.server.json"},"configurations":{"production":{"outputHashing":"media","fileReplacements":[{"replace":"src/environments/environment.ts","with":"src/environments/environment.prod.ts"}],"sourceMap":false,"optimization":true}}},"serve-ssr":{"builder":"@nguniversal/builders:ssr-dev-server","options":{"browserTarget":"angular-bfdx:build","serverTarget":"angular-bfdx:server"},"configurations":{"production":{"browserTarget":"angular-bfdx:build:production","serverTarget":"angular-bfdx:server:production"}}},"prerender":{"builder":"@nguniversal/builders:prerender","options":{"browserTarget":"angular-bfdx:build:production","serverTarget":"angular-bfdx:server:production","routes":["/"]},"configurations":{"production":{}}},"serverless":{"builder":"@angular-devkit/build-angular:server","options":{"outputPath":"dist/angular-bfdx/serverless","main":"serverless.ts","tsConfig":"tsconfig.serverless.json"},"configurations":{"production":{"outputHashing":"media","fileReplacements":[{"replace":"src/environments/environment.ts","with":"src/environments/environment.prod.ts"}],"sourceMap":false,"optimization":true}}}}}},"defaultProject":"angular-bfdx"}

demo/netlify.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
[build]
22
command = "npm run build:sls"
3-
publish = "dist/netlify-serverless/browser"
3+
publish = "dist/angular-bfdx/browser"
44

5+
# TO-DO: remove after cli redirect fix is out https://github.com/netlify/cli/pull/2920
56
# any additional redirects for the site should come *before* this one
67
[[redirects]]
78
from = "/*"
89
to = "/.netlify/functions/angular-builder"
910
status = 200
1011

12+
# TO-DO: remove when config-mutating bug is diagnosed by workflow
1113
[functions]
12-
included_files=["dist/netlify-serverless/browser/index.html"]
14+
included_files=["dist/angular-bfdx/browser/index.html"]
1315
node_bundler="esbuild"
1416

1517
[[plugins]]
1618
package = "../"
17-
[plugins.inputs]
18-
projectName = "angular-bfdx"

manifest.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
name: 'netlify-plugin-angular-universal'
2-
inputs:
3-
- name: projectName
4-
description: The Angular project name as defined in angular.json
2+
inputs: []

package-lock.json

Lines changed: 25 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"aws-serverless-express": "^3.4.0",
5959
"chalk": "^2.4.2",
6060
"fs-extra": "^9.1.0",
61+
"make-dir": "^3.1.0",
6162
"zone.js": "^0.11.4"
6263
}
6364
}

src/helpers/addAngularServerlessFiles.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
const { join } = require('path')
22

3-
const { copySync } = require('fs-extra')
3+
const { copySync, existsSync, removeSync, writeFileSync } = require('fs-extra')
44

5-
const addAngularServerlessFiles = () => {
5+
const { getServerlessTs } = require('./getDynamicTemplates')
6+
7+
const addAngularServerlessFiles = ({ projectName }) => {
68
const TEMPLATES_DIR = join('..', 'src', 'templates')
79

8-
copySync(join(TEMPLATES_DIR, 'serverless.ts'), './serverless.ts', {
9-
overwrite: true,
10-
})
10+
// Write file with injected project name
11+
writeFileSync('./serverless.ts', getServerlessTs(projectName))
12+
13+
// We can copy this file over without writing because it's not dependent on projectName
1114
copySync(join(TEMPLATES_DIR, 'tsconfig.serverless.json'), './tsconfig.serverless.json', {
1215
overwrite: true,
1316
})

src/helpers/copyProjectDist.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)