Skip to content

Commit 2514dd1

Browse files
authored
improvement(cofig.ts): throw an error when ./dist is used as outputpath in angular.json (#188)
We will run into trouble when an user uses './dist` without subfolder. This PR does docuent that, and also make scully check, and throw en error when this is detected re #56
1 parent 746e037 commit 2514dd1

3 files changed

Lines changed: 44 additions & 49 deletions

File tree

angular.json

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,14 @@
1313
"build": {
1414
"builder": "@angular-devkit/build-angular:browser",
1515
"options": {
16-
"outputPath": "dist/browser",
16+
"outputPath": "dist/sampleBlog",
1717
"index": "projects/sampleBlog/src/index.html",
1818
"main": "projects/sampleBlog/src/main.ts",
1919
"polyfills": "projects/sampleBlog/src/polyfills.ts",
2020
"tsConfig": "projects/sampleBlog/tsconfig.app.json",
2121
"aot": true,
22-
"assets": [
23-
"projects/sampleBlog/src/favicon.ico",
24-
"projects/sampleBlog/src/assets"
25-
],
26-
"styles": [
27-
"projects/sampleBlog/src/styles.css"
28-
],
22+
"assets": ["projects/sampleBlog/src/favicon.ico", "projects/sampleBlog/src/assets"],
23+
"styles": ["projects/sampleBlog/src/styles.css"],
2924
"scripts": []
3025
},
3126
"configurations": {
@@ -83,13 +78,8 @@
8378
"polyfills": "projects/sampleBlog/src/polyfills.ts",
8479
"tsConfig": "projects/sampleBlog/tsconfig.spec.json",
8580
"karmaConfig": "projects/sampleBlog/karma.conf.js",
86-
"assets": [
87-
"projects/sampleBlog/src/favicon.ico",
88-
"projects/sampleBlog/src/assets"
89-
],
90-
"styles": [
91-
"projects/sampleBlog/src/styles.css"
92-
],
81+
"assets": ["projects/sampleBlog/src/favicon.ico", "projects/sampleBlog/src/assets"],
82+
"styles": ["projects/sampleBlog/src/styles.css"],
9383
"scripts": []
9484
}
9585
},
@@ -101,9 +91,7 @@
10191
"projects/sampleBlog/tsconfig.spec.json",
10292
"projects/sampleBlog/e2e/tsconfig.json"
10393
],
104-
"exclude": [
105-
"**/node_modules/**"
106-
]
94+
"exclude": ["**/node_modules/**"]
10795
}
10896
},
10997
"e2e": {
@@ -174,9 +162,7 @@
174162
"projects/scullyio/ng-lib/tsconfig.lib.json",
175163
"projects/scullyio/ng-lib/tsconfig.spec.json"
176164
],
177-
"exclude": [
178-
"**/node_modules/**"
179-
]
165+
"exclude": ["**/node_modules/**"]
180166
}
181167
}
182168
}

docs/getting-started.md

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
11
# Scully - Getting Started
22

3-
## Prerequisites
4-
The first thing you need to get started with Scully is a working Angular app using **Angular 9.x.x** and **Node 12.x.x**
3+
## Prerequisites
4+
5+
The first thing you need to get started with Scully is a working Angular app using **Angular 9.x.x** and **Node 12.x.x**
56

67
You can create a new Angular 9 app using the following command:
78

8-
```
9+
```bash
910
npx -p @angular/cli@next ng new my-scully-app
1011
```
11-
12+
1213
If that fails, you can install the `next` version of Angular CLI globally and create a new app with that version.
13-
14+
1415
**Note**: doing this means that any new apps you will create after this will use version 9.
15-
16+
1617
```
1718
npm install -g @angular/cli@next
1819
ng new my-scully-app
1920
```
2021

21-
2222
Find more info here [👉 angular.io/cli](https://angular.io/cli)
2323

24-
__NOTE:__ Scully will use Chromium. Make sure your Operating System (and its restrictions by your administrator) allow installing and executing Chromium.
24+
**NOTE:** Scully will use Chromium. Make sure your Operating System (and its restrictions by your administrator) allow installing and executing Chromium.
2525

2626
This getting started doc covers the three steps to adding Scully into your project.
2727

2828
1. [Installation](#installation)
2929
2. [Build](#build)
3030
3. [Test](#test)
3131

32-
3332
## Installation
33+
3434
To install Scully, execute the following command from the root directory of your Angular project (in a terminal window):
35+
3536
```bash
3637
ng add @scullyio/init
3738
```
@@ -54,9 +55,14 @@ CREATE scully.config.js (65 bytes)
5455
UPDATE package.json (1507 bytes)
5556
```
5657

57-
#### IMPORTANT: *Scully requires the router to be present in your application, don't forget to add it.*
58+
#### IMPORTANT: _Scully requires the router to be present in your application, don't forget to add it._
59+
60+
#### IMPORTANT: _Scully requires the distrubution files to be in a subfolder of `./dist`_
61+
62+
If you have an angular app, that outputs the distribution files directly into to root of `./dist` Scully can't copy all of the dist files. This is an OS file-system issue. We can't copy recursively into a subfolder of dist. The solution is set the option `architect->build->options->outputPath` to a subfolder.
5863

5964
## ng g @scullyio/init:blog
65+
6066
This command will generate a blog module. [more info here](https://github.com/scullyio/scully/blob/master/docs/blog.md)
6167

6268
Once it's generated you can open the default `app.component.html` created by angular-cli and remove the whole placeholder leaving only the router outlet tag `<router-outlet></router-outlet>`
@@ -79,9 +85,9 @@ Open `app-routing.module.ts` and let the path attribute empty for the home route
7985
const routes: Routes = [
8086
// ...
8187
{
82-
path: "",
83-
loadChildren: () => import("./home/home.module").then(m => m.HomeModule)
84-
}
88+
path: '',
89+
loadChildren: () => import('./home/home.module').then(m => m.HomeModule),
90+
},
8591
];
8692
```
8793

@@ -90,26 +96,23 @@ const routes: Routes = [
9096
Scully provides a service to easy get access on generated routes. To list these in your template open `home.component.ts` by adding the following code
9197

9298
```ts
99+
import {ScullyRoutesService} from '@scullyio/ng-lib';
100+
import {Observable} from 'rxjs';
93101

94-
import { ScullyRoutesService } from "@scullyio/ng-lib";
95-
import { Observable } from "rxjs";
96-
97-
@Component(
98-
//...
99-
)
102+
@Component()
103+
//...
100104
export class HomeComponent implements OnInit {
101105
links$: Observable<any> = this.scully.available$;
102-
106+
103107
constructor(private scully: ScullyRoutesService) {}
104-
108+
105109
ngOnInit() {
106110
// debug current pages
107111
this.links$.subscribe(links => {
108112
console.log(links);
109113
});
110114
}
111115
}
112-
113116
```
114117

115118
and then loop inside `home.component.html`
@@ -120,7 +123,6 @@ and then loop inside `home.component.html`
120123
<ul>
121124
<li *ngFor="let page of links$ | async">{{ page.route }}</li>
122125
</ul>
123-
124126
```
125127

126128
## Build
@@ -138,10 +140,10 @@ npm run scully
138140
That's it, you're done! In your project directory, you should now have a `/dist/static` folder containing the built version
139141
of your app.
140142

141-
__NOTE:__ If you had any errors or warnings during the build phase, please follow the instructions in the errors/warnings
143+
**NOTE:** If you had any errors or warnings during the build phase, please follow the instructions in the errors/warnings
142144
(if applicable) or [submit an issue](https://github.com/scullyio/scully/issues/new/choose).
143145

144-
__NOTE:__ If you don't add any route, scully will pre-render 0 pages.
146+
**NOTE:** If you don't add any route, scully will pre-render 0 pages.
145147

146148
## Test
147149

@@ -153,9 +155,9 @@ By utilizing something like [http-server](https://www.npmjs.com/package/http-ser
153155
`dist/static` folder. All of the routes in your non-pre-rendered Angular app should still work. Not all apps are
154156
capable of running without
155157

156-
[//]: # (Missing text for the line above)
158+
[//]: # 'Missing text for the line above'
157159

158-
__Extra Credit__: While serving your app, [disable JavaScript](https://developers.google.com/web/tools/chrome-devtools/javascript/disable)
160+
**Extra Credit**: While serving your app, [disable JavaScript](https://developers.google.com/web/tools/chrome-devtools/javascript/disable)
159161
and make sure that it still works. This is the goal for your app, to run with JavaScript disabled. Most parts of your app should still work without JS enabled.
160162

161163
#### Browsing the contents
@@ -164,4 +166,5 @@ Browse the contents of your `dist/static` directory and make sure that all of yo
164166
HTML correctly.
165167

166168
---
169+
167170
[Full Documentation ➡️](scully.md)

scully/utils/config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ const loadIt = async () => {
2929
// TODO: make scully handle other projects as just the default one.
3030
const defaultProject = angularConfig.defaultProject;
3131
distFolder = angularConfig.projects[defaultProject].architect.build.options.outputPath;
32+
if (distFolder.endsWith('dist') && !distFolder.includes('/')) {
33+
logError(
34+
`Your distribution files are in "${yellow(distFolder)}". Please change that to include a subfolder`
35+
);
36+
process.exit(15);
37+
}
3238
} catch (e) {
3339
logError(`Angular config file could not be parsed!`, e);
3440
process.exit(15);
@@ -51,7 +57,7 @@ const loadIt = async () => {
5157
staticport: /** 1771 */ 'scully'.split('').reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
5258
defaultPostRenderers: [],
5359
// tslint:disable-next-line:no-bitwise
54-
hostUrl: compiledConfig.hostUrl
60+
hostUrl: compiledConfig.hostUrl,
5561
}
5662
// compiledConfig
5763
) as ScullyConfig;

0 commit comments

Comments
 (0)