Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit fe313da

Browse files
authored
Merge pull request #51 from CaerusKaru/lib
build: update build process to conform to Angular Package Format
2 parents 9576ece + ef71a5a commit fe313da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+12561
-61333
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
12+
[*.md]
13+
max_line_length = 0
14+
trim_trailing_whitespace = false

.gitignore

Lines changed: 19 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,23 @@ logs
66
.DS_Store
77
**/.DS_Store
88

9-
# Runtime data
10-
pids
11-
*.pid
12-
*.seed
9+
package-lock.json
10+
11+
dist/
12+
node_modules/
13+
out-tsc/
14+
debug.log
15+
npm-debug.log
16+
src/**/*.js
17+
src/**/*.js.map
18+
src/**/*.d.ts
19+
utils/**/*.js
20+
utils/**/*.js.map
21+
utils/**/*.d.ts
22+
integration/src/**/*.js
23+
integration/e2e/**/*.js
24+
integration/**/*.js.map
25+
integration/**/*.d.ts
26+
*.metadata.json
27+
*.ngsummary.json
1328

14-
typings
15-
16-
# Directory for instrumented libs generated by jscoverage/JSCover
17-
/lib-cov
18-
19-
# Coverage directory used by tools like istanbul
20-
/coverage
21-
22-
# Dependency directory
23-
# Commenting this out is preferred by some people, see
24-
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
25-
node_modules
26-
27-
# used for karma unit test coverage
28-
test/coverage
29-
30-
# Users Environment Variables
31-
.lock-wscript
32-
33-
# Static files
34-
35-
/bower_components/
36-
/web_modules/
37-
/dist
38-
39-
# Typings
40-
/typings/main
41-
/typings/browser
42-
/typings/main.d.ts
43-
/typings/browser.d.ts
44-
/tsd_typings
45-
/docs
46-
47-
/src/**/*.js
48-
/src/**/*.d.ts
49-
/test/**/*.js
50-
/test/**/*.d.ts
51-
/server.js
52-
/server.d.ts
53-
/browser.js
54-
/browser.d.ts
55-
/record.js
56-
/record.d.ts
57-
/replay.js
58-
/replay.d.ts

.npmignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,16 @@
44
.DS_Store
55
*.pid
66
*.seed
7+
8+
# top-level files
9+
CONTRIBUTING.md
10+
package-lock.json
11+
prettier.config.js
12+
protractor.conf.js
13+
tsconfig.json
14+
tslint.json
15+
16+
# top-level directories
17+
build
18+
src
19+
test

CONTRIBUTING.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Contributing to Preboot
22

3-
We would love for you to contribute to Angular 2 and help make it even better than it is
3+
We would love for you to contribute to Preboot and help make it even better than it is
44
today! As a contributor, here are the guidelines we would like you to follow:
55

66
- [Code of Conduct](#coc)
@@ -13,12 +13,13 @@ today! As a contributor, here are the guidelines we would like you to follow:
1313
- [Signing the CLA](#cla)
1414

1515
## <a name="coc"></a> Code of Conduct
16-
Help us keep Angular open and inclusive. Please read and follow our [Code of Conduct][coc].
16+
Help us keep Preboot open and inclusive. Please read and follow our [Code of Conduct][coc].
1717

1818
## <a name="question"></a> Got a Question or Problem?
1919

2020
If you have questions about how to *use* Preboot, please direct them to [Gitter][gitter].
21-
There is also a [Slack](https://angular-universal.slack.com) ground that we would be hapy to invite you to. Just ping [@jeffwhelpley](https://twitter.com/jeffwhelpley)
21+
There is also a [Slack](https://angular-universal.slack.com) ground that we would be happy to invite you to.
22+
Just ping [@jeffwhelpley](https://twitter.com/jeffwhelpley)
2223
or [@gdi2290](https://twitter.com/gdi2290) on [Twitter](https://twitter.com) or [Gitter][gitter].
2324

2425
## <a name="issue"></a> Found an Issue?
@@ -29,8 +30,7 @@ If you find a bug in the source code or a mistake in the documentation, you can
2930
## <a name="feature"></a> Want a Feature?
3031
You can *request* a new feature by [submitting an issue](#submit-issue) to our [GitHub
3132
Repository][github]. If you would like to *implement* a new feature, please submit an issue with
32-
a proposal for your work first, to be sure that we can use it. Angular 2 is in developer preview
33-
and we are not ready to accept major contributions ahead of the full release.
33+
a proposal for your work first, to be sure that we can use it.
3434
Please consider what kind of change it is:
3535

3636
* For a **Major Feature**, first open an issue and outline your proposal so that it can be
@@ -50,7 +50,7 @@ chances of your issue being dealt with quickly:
5050

5151
* **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps
5252
* **Preboot Version** - what version is affected
53-
* **Motivation for or Use Case** - explain what are you trying to do and why the current behavior is a bug for you
53+
* **Motivation for or Use Case** - explain what you are trying to do and why the current behavior is a bug for you
5454
* **Browsers and Operating System** - is this a problem with all browsers?
5555
* **Reproduce the Error** - provide a live example (using [Plunker][plunker],
5656
[JSFiddle][jsfiddle] or [Runnable][runnable]) or a unambiguous set of steps
@@ -95,7 +95,7 @@ Before you submit your Pull Request (PR) consider the following guidelines:
9595
* In GitHub, send a pull request to `preboot:master`.
9696
* If we suggest changes then:
9797
* Make the required updates.
98-
* Re-run the Angular 2 test suites for JS and Dart to ensure tests are still passing.
98+
* Re-run the Preboot test suites to ensure tests are still passing.
9999
* Rebase your branch and force push to your GitHub repository (this will update your Pull Request):
100100

101101
```shell
@@ -167,7 +167,8 @@ Any line of the commit message cannot be longer 100 characters! This allows the
167167
to read on GitHub as well as in various git tools.
168168

169169
### Revert
170-
If the commit reverts a previous commit, it should begin with `revert: `, followed by the header of the reverted commit. In the body it should say: `This reverts commit <hash>.`, where the hash is the SHA of the commit being reverted.
170+
If the commit reverts a previous commit, it should begin with `revert: `, followed by the header of the reverted commit.
171+
In the body it should say: `This reverts commit <hash>.`, where the hash is the SHA of the commit being reverted.
171172

172173
### Type
173174
Must be one of the following:
@@ -180,7 +181,8 @@ Must be one of the following:
180181
* **refactor**: A code change that neither fixes a bug nor adds a feature
181182
* **perf**: A code change that improves performance
182183
* **test**: Adding missing tests or correcting existing tests
183-
* **build** Changes that affect the build system, CI configuration or external dependencies (example scopes: gulp, broccoli, npm)
184+
* **build** Changes that affect the build system, CI configuration or external dependencies
185+
(example scopes: gulp, broccoli, npm)
184186
* **chore**: Other changes that don't modify `src` or `test` files
185187
186188
### Scope
@@ -202,7 +204,8 @@ The body should include the motivation for the change and contrast this with pre
202204
The footer should contain any information about **Breaking Changes** and is also the place to
203205
reference GitHub issues that this commit **Closes**.
204206

205-
**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this.
207+
**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit
208+
message is then used for this.
206209

207210
A detailed explanation can be found in this [document][commit-message-format].
208211

README.md

Lines changed: 42 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -21,62 +21,38 @@ cd into your app root and run the following command:
2121
npm i preboot --save
2222
```
2323

24-
There are two parts of preboot (server configuration and browser configuration). For each part of preboot, there is a slightly different API for Angular and non-Angular apps. The following sections covers these 4 different configurations:
24+
The following sections covers the three different configurations of preboot:
2525

26-
- Angular Server Configuration
27-
- Angular Browser Configuration
26+
- Angular Configuration
2827
- Non-Angular Server Configuration
2928
- Non-Angular Browser Configuration
3029

31-
#### Angular Server Configuration
30+
#### Angular Configuration
3231

33-
```
32+
```typescript
3433
import { NgModule } from '@angular/core';
3534
import { BrowserModule } from '@angular/platform-browser';
36-
import { ServerModule } from '@angular/platform-server';
37-
import { ServerPrebootModule } from 'preboot/server';
35+
import { PrebootModule } from 'preboot';
3836
import { AppComponent } from './app.component';
3937

4038
@NgModule({
4139
declarations: [AppComponent],
4240
imports: [
4341
BrowserModule.withServerTransition({ appId: 'foo' }),
44-
ServerModule,
45-
ServerPrebootModule.recordEvents({ appRoot: 'app-root' })
46-
],
47-
bootstrap: [AppComponent]
48-
})
49-
export class AppModule { }
50-
```
51-
52-
The key part here for preboot is to include `ServerPrebootModule.recordEvents({ appRoot: 'app-root' })` where the `appRoot`
53-
is the selector to find the root of your application. The options you can pass into `recordEvents()` are in the [PrebootRecordOptions](#PrebootRecordOptions) section below. In most cases, however, you will only need to specify the `appRoot`.
54-
55-
#### Angular Browser Configuration
56-
57-
```
58-
import { NgModule } from '@angular/core';
59-
import { BrowserModule } from '@angular/platform-browser';
60-
import { BrowserPrebootModule } from 'preboot/browser';
61-
import { AppComponent } from './app.component';
62-
63-
@NgModule({
64-
declarations: [AppComponent],
65-
imports: [
66-
BrowserModule,
67-
BrowserPrebootModule.replayEvents()
42+
PrebootModule.withConfig({ appRoot: 'app-root' })
6843
],
6944
bootstrap: [AppComponent]
7045
})
7146
export class AppModule { }
7247
```
7348

74-
The key part here for preboot is to include `BrowserPrebootModule.replayEvents()`. You can optionally pass an object into `replayEvents()` that is detailed in the [PrebootReplayOptions](#PrebootReplayOptions) section further below. In most cases, however, you can just rely on the preset defaults.
49+
The key part here for preboot is to include `PrebootModule.withConfig({ appRoot: 'app-root' })` where the `appRoot`
50+
is the selector(s) to find the root of your application. The options you can pass into `withConfig()` are in the [PrebootOptions](#PrebootOptions) section below. In most cases, however, you will only need to specify the `appRoot`.
7551

7652
#### Non-Angular Server Configuration
7753

7854
```
79-
import { getInlinePrebootCode } from 'preboot/record';
55+
import { getInlinePrebootCode } from 'preboot';
8056
8157
const prebootOptions = {}; // see PrebootRecordOptions section below
8258
const inlineCode = getInlinePrebootCode(prebootOptions);
@@ -88,25 +64,50 @@ const inlineCode = getInlinePrebootCode(prebootOptions);
8864
#### Non-Angular Browser Configuration
8965

9066
```
91-
import { EventReplayer } from 'preboot/replay';
67+
import { EventReplayer } from 'preboot';
9268
9369
const replayer = new EventReplayer();
9470
9571
// once you are ready to replay events (usually after client app fully loaded)
9672
replayer.replayAll();
9773
```
9874

99-
#### PrebootRecordOptions
75+
#### PrebootOptions
10076

10177
* `appRoot` (**required**) - One or more selectors for apps in the page (i.e. so one string or an array of strings).
10278
* `buffer` (default true) - If true, preboot will attempt to buffer client rendering to an extra hidden div. In most
10379
cases you will want to leave the default (i.e. true) but may turn off if you are debugging an issue.
104-
* `minify` (default true) - If true, the inline code for recording will be minified in the server view. We recommend
105-
only setting this to false if you are debugging an issue.
80+
* `minify` (deprecated) - minification has been removed in v6. Minification should be handled by the end-user
10681
* `eventSelectors` (defaults below) - This is an array of objects which specify what events preboot should be listening for
10782
on the server view and how preboot should replay those events to the client view.
10883
See Event Selector section below for more details but note that in most cases, you can just rely on the defaults
10984
and you don't need to explicitly set anything here.
85+
* `noReplay` (default false) - The only reason why you would want to set this to true is if you want to
86+
manually trigger the replay yourself. This contrasts with the event selector `noReplay`, because this option is global
87+
88+
This comes in handy for situations where you want to hold off
89+
on the replay and buffer switch until AFTER some async events occur (i.e. route loading, http calls, etc.). By
90+
default, replay occurs right after bootstrap is complete. In some apps, there are more events after bootstrap
91+
however where the page continues to change in significant ways. Basically if you are making major changes to
92+
the page after bootstrap then you will see some jank unless you set `noReplay` to `true` and then trigger replay
93+
yourself once you know that all async events are complete.
94+
95+
To manually trigger replay, simply inject the EventReplayer like this:
96+
97+
```
98+
import { Injectable } from '@angular/core';
99+
import { EventReplayer } from 'preboot';
100+
101+
@Injectable()
102+
class Foo {
103+
constructor(private replayer: EventReplayer) {}
104+
105+
// you decide when to call this based on what your app is doing
106+
manualReplay() {
107+
this.replayer.replayAll();
108+
}
109+
}
110+
```
110111

111112
**Event Selectors**
112113

@@ -147,37 +148,6 @@ var eventSelectors = [
147148
];
148149
```
149150

150-
#### PrebootReplayOptions
151-
152-
This is only used with the Angular browser configuration for preboot.
153-
154-
* `noReplay` (default false) - The only reason why you would want to set this to true is if you want to
155-
manually trigger the replay yourself.
156-
157-
This comes in handy for situations where you want to hold off
158-
on the replay and buffer switch until AFTER some async events occur (i.e. route loading, http calls, etc.). By
159-
default, replay occurs right after bootstrap is complete. In some apps, there are more events after bootstrap
160-
however where the page continues to change in significant ways. Basically if you are making major changes to
161-
the page after bootstrap then you will see some jank unless you set `noReplay` to `true` and then trigger replay
162-
yourself once you know that all async events are complete.
163-
164-
To manually trigger replay, simply inject the EventReplayer like this:
165-
166-
```
167-
import { Injectable } from '@angular/core';
168-
import { EventReplayer } from 'preboot/browser';
169-
170-
@Injectable()
171-
class Foo {
172-
constructor(private replayer: EventReplayer) {}
173-
174-
// you decide when to call this based on what your app is doing
175-
manualReplay() {
176-
this.replayer.replayAll();
177-
}
178-
}
179-
```
180-
181151
#### PrebootComplete
182152

183153
When you are manually replaying events, you often will want to know when Preboot
@@ -197,7 +167,7 @@ Preboot allows you to configure this by exporting an optional `PREBOOT_NONCE` to
197167
Example usage is as follows (for an Express server):
198168

199169
```typescript
200-
import {PREBOOT_NONCE} from 'preboot/src';
170+
import {PREBOOT_NONCE} from 'preboot';
201171
import * as express from 'express';
202172
import {v4} from 'uuid';
203173
import * as csp from 'helmet-csp';
@@ -226,8 +196,8 @@ app.get('*', (req, res) => {
226196
res,
227197
providers: [
228198
{
229-
provide: PREBOOT_NONCE,
230-
useValue: res.locals.nonce
199+
provide: PREBOOT_NONCE,
200+
useValue: res.locals.nonce
231201
}
232202
]
233203
});
@@ -248,4 +218,4 @@ res.render('index', (req, res) => {
248218
console.log(html.substring(0, 50)); // we only care about the top part
249219
res.send(html);
250220
});
251-
```
221+
```

browser.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

bs-config.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"server": {
3+
"baseDir": "src/demo",
4+
"routes": {
5+
"/node_modules": "node_modules",
6+
"/preboot": "src/lib"
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)