├── tools
├── typings.d.ts
├── build
│ ├── helpers.ts
│ ├── build-config.json
│ ├── inline-resources.ts
│ └── rollup.ts
└── test
│ └── jest.setup.ts
├── tslint.json
├── .gitignore
├── tsconfig.json
├── packages
└── @ngx-universal
│ ├── state-transfer
│ └── README.md
│ └── express-engine
│ └── README.md
├── .circleci
└── config.yml
├── CHANGELOG.md
├── LICENSE
├── .github
├── PULL_REQUEST_TEMPLATE.md
└── ISSUE_TEMPLATE.md
├── README.md
├── package.json
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
└── yarn.lock
/tools/typings.d.ts:
--------------------------------------------------------------------------------
1 | // custom typings
2 | declare module '*' {
3 | let json: any;
4 | export = json;
5 | }
6 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/codelyzer"
4 | ],
5 | "extends": ["angular-tslint-rules"]
6 | }
7 |
--------------------------------------------------------------------------------
/tools/build/helpers.ts:
--------------------------------------------------------------------------------
1 | import * as path from 'path';
2 |
3 | export const NODE_MODULES = 'node_modules';
4 |
5 | export function root(args: any = ''): string {
6 | const ROOT = path.resolve(__dirname, '../..');
7 | args = [].slice.call(arguments, 0);
8 |
9 | return path.join.apply(path, [ROOT].concat(args));
10 | }
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | .temp/
5 | dist/
6 |
7 | # dependencies
8 | node_modules/
9 |
10 | # IDEs and editors
11 | .idea/
12 |
13 | # build tools
14 | coverage/
15 | test-report.xml
16 |
17 | # misc
18 | npm-debug.log
19 | yarn-error.log
20 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "module": "commonjs",
5 | "moduleResolution": "node",
6 | "emitDecoratorMetadata": true,
7 | "experimentalDecorators": true,
8 | "importHelpers": true,
9 | "lib": [
10 | "es2017",
11 | "dom"
12 | ]
13 | },
14 | "include": [
15 | "tools/**/*.ts",
16 | "packages/**/*.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/tools/build/build-config.json:
--------------------------------------------------------------------------------
1 | {
2 | "@ngx-universal": {
3 | "state-transfer": {
4 | "angularVersion": 4,
5 | "bundle": {
6 | "globals": {
7 | "@angular/platform-server": "ng.platformServer",
8 | "rxjs/Observable": "Rx.Observable"
9 | },
10 | "external": [
11 | "rxjs/add/observable/fromPromise",
12 | "rxjs/add/operator/do",
13 | "rxjs/add/operator/map"
14 | ]
15 | },
16 | "runTests": false
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/packages/@ngx-universal/state-transfer/README.md:
--------------------------------------------------------------------------------
1 | # @ngx-universal/state-transfer [](https://www.npmjs.com/package/@ngx-universal/state-transfer) [](https://www.npmjs.com/package/@ngx-universal/state-transfer)
2 | State transferring utility for **Angular Universal**
3 |
4 | #### DEPRECATION WARNING
5 | The official `TransferState` is out with [Angular 5.x] and **runs OK**, so this library is no longer maintained and **deprecated**.
6 |
7 | ## License
8 | The MIT License (MIT)
9 |
10 | Copyright (c) 2018 [Burak Tasci]
11 |
12 | [Angular 5.x]: https://github.com/angular/angular
13 | [ng-seed/universal]: https://github.com/ng-seed/universal
14 | [Burak Tasci]: https://github.com/fulls1z3
15 |
--------------------------------------------------------------------------------
/packages/@ngx-universal/express-engine/README.md:
--------------------------------------------------------------------------------
1 | # @ngx-universal/express-engine [](https://www.npmjs.com/package/@ngx-universal/express-engine) [](https://www.npmjs.com/package/@ngx-universal/express-engine)
2 | Express engine for **Angular Universal**
3 |
4 | #### DEPRECATION WARNING
5 | The official [@ng-universal/express-engine] is out and **runs OK**, so this library is no longer maintained and **deprecated**.
6 |
7 | ## License
8 | The MIT License (MIT)
9 |
10 | Copyright (c) 2018 [Burak Tasci]
11 |
12 | [@ng-universal/express-engine]: https://www.npmjs.com/package/@nguniversal/express-engine
13 | [ng-seed/universal]: https://github.com/ng-seed/universal
14 | [Burak Tasci]: https://github.com/fulls1z3
15 |
--------------------------------------------------------------------------------
/tools/test/jest.setup.ts:
--------------------------------------------------------------------------------
1 | import 'jest-preset-angular';
2 |
3 | const mock = () => {
4 | let storage = {};
5 |
6 | return {
7 | getItem: (key: string) => key in storage ? (storage as any)[key] : undefined,
8 | setItem: (key: string, value: any) => (storage as any)[key] = value || '',
9 | removeItem: (key: string) => delete (storage as any)[key],
10 | clear: () => storage = {}
11 | };
12 | };
13 |
14 | Object.defineProperty(window, 'CSS', {value: mock()});
15 | Object.defineProperty(window, 'localStorage', {value: mock()});
16 | Object.defineProperty(window, 'sessionStorage', {value: mock()});
17 |
18 | Object.defineProperty(document, 'doctype', {
19 | value: ''
20 | });
21 |
22 | Object.defineProperty(window, 'getComputedStyle', {
23 | value: () => {
24 | return {
25 | display: 'none',
26 | appearance: ['-webkit-appearance']
27 | };
28 | }
29 | });
30 |
--------------------------------------------------------------------------------
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | jobs:
3 | build:
4 | docker:
5 | - image: circleci/node:7
6 | steps:
7 | - checkout
8 | - run: sudo npm install -g yarn@0
9 | - run: sudo yarn global add greenkeeper-lockfile@1
10 | - restore_cache:
11 | keys:
12 | - deps-{{ .Branch }}-{{ checksum "yarn.lock" }}
13 | - deps-
14 | - run: yarn
15 | - save_cache:
16 | key: deps-{{ .Branch }}-{{ checksum "yarn.lock" }}
17 | paths: 'node_modules'
18 | - run: yarn ci:before
19 | - run: yarn test:ci
20 | - run: yarn build
21 | - run: yarn ci:after
22 | - run: bash <(curl -s https://codecov.io/bash)
23 | - store_artifacts:
24 | path: coverage
25 | prefix: coverage
26 | - store_artifacts:
27 | path: dist
28 | prefix: dist
29 | - store_test_results:
30 | path: test-report.xml
31 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4 |
5 |
6 | ## [4.0.1](https://github.com/fulls1z3/ngx-universal/compare/v4.0.0...v4.0.1) (2017-09-07)
7 |
8 |
9 | ### Bug Fixes
10 |
11 | * fix moduleId for AoT compilation ([#30](https://github.com/fulls1z3/ngx-universal/issues/30)) ([dfd62ba](https://github.com/fulls1z3/ngx-universal/commit/dfd62ba)), closes [#29](https://github.com/fulls1z3/ngx-universal/issues/29)
12 |
13 |
14 |
15 |
16 | # 4.0.0 (2017-09-06)
17 |
18 |
19 | ### Bug Fixes
20 |
21 | * **state-transfer:** cannot read property '0' of undefined ([#2](https://github.com/fulls1z3/ngx-universal/issues/2)) ([46a6ba5](https://github.com/fulls1z3/ngx-universal/commit/46a6ba5))
22 |
23 |
24 | ### Features
25 |
26 | * **state-transfer:** export STATE_ID ([#6](https://github.com/fulls1z3/ngx-universal/issues/6)) ([349ddf7](https://github.com/fulls1z3/ngx-universal/commit/349ddf7))
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Burak Tasci
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ** PR Checklist
2 | Please check if your PR fulfills the following requirements:
3 |
4 | - [ ] The commit message follows our guidelines: https://github.com/fulls1z3/ngx-universal/blob/master/CONTRIBUTING.md#commit
5 | - [ ] Tests for the changes have been added (for bug fixes / features)
6 | - [ ] Docs have been added / updated (for bug fixes / features)
7 |
8 | ** PR Type
9 | What kind of change does this PR introduce?
10 |
11 |
12 | ```
13 | [ ] Bugfix
14 | [ ] Feature
15 | [ ] Code style update (formatting, local variables)
16 | [ ] Refactoring (no functional changes, no api changes)
17 | [ ] Build related changes
18 | [ ] CI related changes
19 | [ ] Documentation content changes
20 | [ ] Other... Please describe:
21 | ```
22 |
23 | ** What is the current behavior?
24 |
25 |
26 | Issue Number: N/A
27 |
28 | ** What is the new behavior?
29 |
30 | ** Does this PR introduce a breaking change?
31 | ```
32 | [ ] Yes
33 | [ ] No
34 | ```
35 |
36 |
37 |
38 | ** Other information
39 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
6 |
7 | **I'm submitting a ...** (check one with "x")
8 | ```
9 | [ ] Regression (a behavior that used to work and stopped working in a new release)
10 | [ ] Bug report
11 | [ ] Support request =>
12 | [ ] Feature request
13 | [ ] Documentation issue or request
14 | ```
15 |
16 | **Current behavior**
17 |
18 |
19 | **Expected/desired behavior**
20 |
21 |
22 | **Minimal reproduction of the problem with instructions**
23 |
27 |
28 | **What is the motivation / use case for changing the behavior?**
29 |
30 |
31 | **Environment**
32 | * **Angular version:** X.Y.Z
33 |
34 |
35 | * **Browser:**
36 | - [ ] Chrome (desktop) version XX
37 | - [ ] Chrome (Android) version XX
38 | - [ ] Chrome (iOS) version XX
39 | - [ ] Firefox version XX
40 | - [ ] Safari (desktop) version XX
41 | - [ ] Safari (iOS) version XX
42 | - [ ] IE version XX
43 | - [ ] Edge version XX
44 |
45 | * **For Tooling issues:**
46 | - Node version: XX
47 | - Platform:
48 |
49 | * Others:
50 |
51 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ngx-universal
2 | Server platform libraries for **Angular**
3 |
4 | [](https://circleci.com/gh/fulls1z3/ngx-universal)
5 | [](https://codecov.io/gh/fulls1z3/ngx-universal)
6 | [](https://github.com/facebook/jest)
7 | [](https://conventionalcommits.org)
8 | [](https://greenkeeper.io/)
9 | [](https://angular.io/styleguide)
10 |
11 | > Please support this project by simply putting a Github star. Share this library with friends on Twitter and everywhere else you can.
12 |
13 | #### NOTICE
14 | The official [@ng-universal/express-engine] and [Angular 5.x] are out and **runs OK**, so this library is no longer maintained and **deprecated**.
15 |
16 | ## Packages:
17 | Name | Description | NPM
18 | --- | --- | ---
19 | [@ngx-universal/express-engine](https://github.com/fulls1z3/ngx-universal/tree/master/packages/@ngx-universal/express-engine) | DEPRECATED: use [@ng-universal/express-engine] | ---
20 | [@ngx-universal/state-transfer](https://github.com/fulls1z3/ngx-universal/tree/master/packages/@ngx-universal/state-transfer) | DEPRECATED: use [Angular 5.x] | ---
21 |
22 | ## License
23 | The MIT License (MIT)
24 |
25 | Copyright (c) 2018 [Burak Tasci]
26 |
27 | [master]: https://github.com/ngx-universal/core/tree/master
28 | [5.x.x]: https://github.com/ngx-universal/core/tree/5.x.x
29 | [@ng-universal/express-engine]: https://www.npmjs.com/package/@nguniversal/express-engine
30 | [Angular 5.x]: https://github.com/angular/angular
31 | [ng-seed/universal]: https://github.com/ng-seed/universal
32 | [Burak Tasci]: https://github.com/fulls1z3
33 |
--------------------------------------------------------------------------------
/tools/build/inline-resources.ts:
--------------------------------------------------------------------------------
1 | import { readFile, readFileSync, writeFile } from 'fs';
2 | import * as path from 'path';
3 | import * as glob from 'glob';
4 |
5 | const inlineTemplate = (content: string, urlResolver: Function) =>
6 | content.replace(/templateUrl:\s*'([^']+?\.html)'/g, (m, templateUrl) => {
7 | const templateFile = urlResolver(templateUrl);
8 | const templateContent = readFileSync(templateFile, {encoding: 'utf-8'});
9 | const shortenedTemplate = (templateContent as string)
10 | .replace(/([\n\r]\s*)+/gm, ' ')
11 | .replace(/"/g, '\\"');
12 |
13 | return `template: "${shortenedTemplate}"`;
14 | });
15 |
16 | const inlineStyle = (content: string, urlResolver: Function) =>
17 | content.replace(/styleUrls:\s*(\[[\s\S]*?\])/gm, (m, styleUrls) => {
18 | // tslint:disable-next-line
19 | const urls = eval(styleUrls);
20 |
21 | const res = urls.map((styleUrl: string) => {
22 | const styleFile = urlResolver(styleUrl);
23 | const styleContent = readFileSync(styleFile, {encoding: 'utf-8'});
24 | const shortenedStyle = (styleContent as string)
25 | .replace(/([\n\r]\s*)+/gm, ' ')
26 | .replace(/"/g, '\\"');
27 |
28 | return `"${shortenedStyle}"`;
29 | });
30 |
31 | return `styles: [${res}]`;
32 | });
33 |
34 | const inlineResourcesFromString = (content: string, urlResolver: Function) => [
35 | inlineTemplate,
36 | inlineStyle
37 | ].reduce((res, fn) => fn(res, urlResolver), content);
38 |
39 | function promiseify(fn: any): any {
40 | return function(): any {
41 | const args = [].slice.call(arguments, 0);
42 |
43 | return new Promise((resolve, reject) => {
44 | // tslint:disable-next-line
45 | fn.apply(this, args.concat([(err: any, value: any) => {
46 | if (err)
47 | reject(err);
48 | else
49 | resolve(value);
50 | }]));
51 | });
52 | };
53 | }
54 |
55 | const readFileAsync = promiseify(readFile);
56 | const writeFileAsync = promiseify(writeFile);
57 |
58 | export const inlineResources = (projectPath: string) => {
59 | const files = glob.sync('**/*.ts', {cwd: projectPath});
60 |
61 | return Promise.all(files
62 | .map((filePath: string) => {
63 | const fullFilePath = path.join(projectPath, filePath);
64 |
65 | return readFileAsync(fullFilePath, 'utf-8')
66 | .then((content: string) => inlineResourcesFromString(content,
67 | (url: string) => path.join(path.dirname(fullFilePath), url)))
68 | .then((content: string) => writeFileAsync(fullFilePath, content))
69 | .catch((err: string) => {
70 | console.error('An error occured: ', err);
71 | });
72 | }));
73 | };
74 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ngx-universal",
3 | "version": "4.0.1",
4 | "description": "Server platform libraries for Angular",
5 | "repository": {
6 | "type": "git",
7 | "url": "https://github.com/fulls1z3/ngx-universal.git"
8 | },
9 | "keywords": [],
10 | "author": {
11 | "name": "Burak Tasci",
12 | "email": "me@fulls1z3.com"
13 | },
14 | "license": "MIT",
15 | "bugs": {
16 | "url": "https://github.com/fulls1z3/ngx-universal/issues"
17 | },
18 | "homepage": "https://github.com/fulls1z3/ngx-universal#readme",
19 | "scripts": {
20 | "clean": "rimraf .temp dist",
21 | "build": "ts-node ./tools/build/rollup.ts && rimraf .temp",
22 | "lint": "tslint -p ./tslint.json --force",
23 | "rebuild": "npm run clean && npm run build",
24 | "ci:before": "greenkeeper-lockfile-update",
25 | "ci:after": "greenkeeper-lockfile-upload",
26 | "test": "jest --runInBand --colors",
27 | "test:ci": "jest --ci --updateSnapshot --colors",
28 | "release": "standard-version"
29 | },
30 | "devDependencies": {
31 | "@angular/animations": "~5.1.3",
32 | "@angular/common": "~5.1.3",
33 | "@angular/compiler": "~5.1.3",
34 | "@angular/compiler-cli": "~5.1.3",
35 | "@angular/core": "~5.1.3",
36 | "@angular/platform-browser": "~5.1.3",
37 | "@angular/platform-server": "~5.1.3",
38 | "core-js": "~2.5.1",
39 | "rxjs": "~5.5.6",
40 | "zone.js": "~0.8.18",
41 | "express": "~4.16.1",
42 | "@types/node": "~8.0.32",
43 | "@types/express": "~4.0.37",
44 | "@types/jest": "~21.1.2",
45 | "rimraf": "~2.6.2",
46 | "ts-node": "~3.3.0",
47 | "glob": "~7.1.2",
48 | "camelcase": "~4.1.0",
49 | "rollup": "~0.42.0",
50 | "rollup-plugin-node-resolve": "~3.0.0",
51 | "rollup-plugin-commonjs": "~8.2.1",
52 | "rollup-plugin-sourcemaps": "~0.4.2",
53 | "rollup-plugin-uglify": "~2.0.1",
54 | "jest": "~21.2.1",
55 | "jest-preset-angular": "~4.0.0-alpha.1",
56 | "jest-junit-reporter": "~1.1.0",
57 | "standard-version": "~4.3.0",
58 | "codelyzer": "~4.0.2",
59 | "tslint": "~5.8.0",
60 | "angular-tslint-rules": "1.1.0",
61 | "typescript": "~2.6.2"
62 | },
63 | "jest": {
64 | "preset": "jest-preset-angular",
65 | "setupTestFrameworkScriptFile": "./tools/test/jest.setup.ts",
66 | "testResultsProcessor": "./node_modules/jest-junit-reporter",
67 | "globals": {
68 | "ts-jest": {
69 | "tsConfigFile": "./tsconfig.json"
70 | },
71 | "__TRANSFORM_HTML__": true
72 | },
73 | "moduleNameMapper": null,
74 | "cache": false,
75 | "silent": true,
76 | "collectCoverage": true,
77 | "collectCoverageFrom": [
78 | "packages/@ngx-universal/state-transfer/src/**.ts"
79 | ]
80 | },
81 | "greenkeeper": {
82 | "ignore": [
83 | "rollup"
84 | ]
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at mail@buraktasci.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/tools/build/rollup.ts:
--------------------------------------------------------------------------------
1 | import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
2 | import * as path from 'path';
3 | import * as glob from 'glob';
4 | import * as camelCase from 'camelcase';
5 | import { main as ngc } from '@angular/compiler-cli/src/main';
6 | import * as rollup from 'rollup';
7 | import * as commonJs from 'rollup-plugin-commonjs';
8 | import * as sourceMaps from 'rollup-plugin-sourcemaps';
9 | import * as resolve from 'rollup-plugin-node-resolve';
10 | import * as uglify from 'rollup-plugin-uglify';
11 |
12 | import { NODE_MODULES, root } from './helpers';
13 | import { inlineResources } from './inline-resources';
14 |
15 | const compilationFolder = root('.temp');
16 | let globals = {
17 | tslib: 'tslib',
18 | '@angular/core': 'ng.core'
19 | };
20 |
21 | const relativeCopy = (fileGlob: string, from: string, to: string) => {
22 | return new Promise((res, reject) => {
23 | glob(fileGlob, {
24 | cwd: from,
25 | nodir: true
26 | }, (err: string, files: Array) => {
27 | if (err)
28 | reject(err);
29 |
30 | for (const file of files) {
31 | if (file.indexOf(NODE_MODULES) >= 0)
32 | continue;
33 |
34 | const origin = path.join(from, file);
35 | const destination = path.join(to, file);
36 | const data = readFileSync(origin, 'utf-8');
37 |
38 | recursiveMkDir(path.dirname(destination));
39 | writeFileSync(destination, data);
40 | }
41 |
42 | res();
43 | });
44 | });
45 | };
46 |
47 | const recursiveMkDir = (dir: string) => {
48 | if (!existsSync(dir)) {
49 | recursiveMkDir(path.dirname(dir));
50 | mkdirSync(dir);
51 | }
52 | };
53 |
54 | import * as buildConfig from './build-config.json';
55 |
56 | const build = (group: string, item: string, settings: any) => {
57 | const paths = {
58 | src: root(`packages/${group}/${item}`),
59 | temp: path.join(compilationFolder, `packages/${group}/${item}`),
60 | es2015: path.join(compilationFolder, `packages/${group}/${item}-es2015`),
61 | es5: path.join(compilationFolder, `packages/${group}/${item}-es5`),
62 | dist: root(`dist/${group}/${item}`)
63 | };
64 |
65 | globals = {
66 | ...globals,
67 | ...settings.bundle.globals
68 | };
69 | const external = settings.bundle.external
70 | ? settings.bundle.external.concat(Object.keys(globals))
71 | : Object.keys(globals);
72 |
73 | return Promise.resolve()
74 | .then(() => relativeCopy('**/*', paths.src, paths.temp)
75 | .then(() => inlineResources(paths.temp))
76 | // tslint:disable-next-line
77 | .then(() => console.log(`>>> ${group}/${item}: Inlining succeeded`))
78 | )
79 | .then(() => ngc({project: `${paths.temp}/tsconfig.es2015.json`})
80 | .then(exitCode => new Promise((res, reject) => {
81 | exitCode === 0
82 | ? res()
83 | : reject();
84 | }))
85 | // tslint:disable-next-line
86 | .then(() => console.log(`>>> ${group}/${item}: ES2015 compilation succeeded`))
87 | )
88 | .then(() => ngc({project: `${paths.temp}/tsconfig.es5.json`})
89 | .then(exitCode => new Promise((res, reject) => {
90 | exitCode === 0
91 | ? res()
92 | : reject();
93 | }))
94 | // tslint:disable-next-line
95 | .then(() => console.log(`>>> ${group}/${item}: ES5 compilation succeeded`))
96 | )
97 | .then(() => Promise.resolve()
98 | .then(() => relativeCopy('**/*.d.ts', paths.es2015, paths.dist))
99 | .then(() => relativeCopy('**/*.metadata.json', paths.es2015, paths.dist))
100 | // tslint:disable-next-line
101 | .then(() => console.log(`>>> ${group}/${item}: Typings and metadata copy succeeded`))
102 | )
103 | .then(() => {
104 | const es5Entry = path.join(paths.es5, `${settings.angularVersion > 2 ? item : 'index'}.js`);
105 | const es2015Entry = path.join(paths.es2015, `${settings.angularVersion > 2 ? item : 'index'}.js`);
106 | const rollupBaseConfig = {
107 | moduleName: `${camelCase(group.replace(/@/g, ''))}.${camelCase(item)}`,
108 | sourceMap: true,
109 | globals,
110 | external,
111 | plugins: [
112 | resolve({
113 | module: true,
114 | jsnext: true
115 | }),
116 | commonJs({
117 | include: ['node_modules/rxjs/**']
118 | }),
119 | sourceMaps()
120 | ]
121 | };
122 |
123 | const umdConfig = {
124 | ...rollupBaseConfig,
125 | entry: es5Entry,
126 | dest: path.join(paths.dist, 'bundles', `${item}.umd.js`),
127 | format: 'umd'
128 | };
129 |
130 | const minUmdConfig = {
131 | ...rollupBaseConfig,
132 | entry: es5Entry,
133 | dest: path.join(paths.dist, 'bundles', `${item}.umd.min.js`),
134 | format: 'umd',
135 | plugins: rollupBaseConfig.plugins.concat([uglify({})])
136 | };
137 |
138 | const es5config = {
139 | ...rollupBaseConfig,
140 | entry: es5Entry,
141 | dest: path.join(paths.dist, `${group}/${item}.es5.js`),
142 | format: 'es'
143 | };
144 |
145 | const es2015config = {
146 | ...rollupBaseConfig,
147 | entry: es2015Entry,
148 | dest: path.join(paths.dist, `${group}/${item}.js`),
149 | format: 'es'
150 | };
151 |
152 | const bundles = [
153 | umdConfig,
154 | minUmdConfig,
155 | es5config,
156 | es2015config
157 | ]
158 | .map(options => rollup.rollup(options)
159 | .then((bundle: any) => bundle.write(options)));
160 |
161 | return Promise.all(bundles)
162 | // tslint:disable-next-line
163 | .then(() => console.log(`>>> ${group}/${item}: All bundles generated successfully`));
164 | })
165 | .then(() => Promise.resolve()
166 | .then(() => relativeCopy('LICENSE', root(), paths.dist))
167 | .then(() => relativeCopy('package.json', paths.src, paths.dist))
168 | .then(() => relativeCopy('README.md', paths.src, paths.dist))
169 | // tslint:disable-next-line
170 | .then(() => console.log(`>>> ${group}/${item}: Package files copy succeeded`))
171 | // tslint:disable-next-line
172 | .then(() => console.log(`\n`))
173 | )
174 | .catch(e => {
175 | console.error(`>>> ${group}/${item}: Build failed, see below for errors\n`);
176 | console.error(e);
177 | process.exit(1);
178 | });
179 | };
180 |
181 | const libs = [];
182 |
183 | for (const group of Object.keys(buildConfig))
184 | if (group !== '__once__')
185 | for (const item of Object.keys(buildConfig[group]))
186 | libs.push({
187 | group,
188 | item,
189 | settings: buildConfig[group][item]
190 | });
191 | else
192 | libs.push({
193 | group: '',
194 | item: Object.keys(buildConfig[group])[0],
195 | settings: buildConfig[group][Object.keys(buildConfig[group])[0]]
196 | });
197 |
198 | const toSeries = (series: any) => series
199 | .reduce((promise: Promise, fn: Function) => promise
200 | .then((res: any) => fn()
201 | .then(Array.prototype.concat.bind(res))), Promise.resolve([]));
202 |
203 | const builds = libs
204 | .map((lib: any) => () => build(lib.group, lib.item, lib.settings));
205 |
206 | toSeries(builds);
207 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to ngx-universal
2 |
3 | We would love for you to contribute to **`ngx-universal`** and help make it even better than it is today! As a contributor,
4 | here are the guidelines we would like you to follow:
5 |
6 | - [Code of Conduct](#coc)
7 | - [Issues and Bugs](#issue)
8 | - [Feature requests](#feature)
9 | - [Submission guidelines](#submit)
10 | - [Coding rules](#rules)
11 | - [Commit message guidelines](#commit)
12 |
13 | ## Code of Conduct
14 | Help us keep **`ngx-universal`** open and inclusive. Please read and follow our [Code of Conduct][coc].
15 |
16 | ## Found a Bug?
17 | If you find a bug in the source code, you can help us by [submitting an issue](#submit-issue) to our [GitHub Repository][github].
18 |
19 | Even better, you can [submit a Pull Request](#submit-pr) with a fix.
20 |
21 | ## Missing a Feature?
22 | You can *request* a new feature by [submitting an issue](#submit-issue) to our GitHub Repository.
23 |
24 | If you would like to *implement* a new feature, please submit an issue with a proposal for your work first, to be sure that
25 | we can use it.
26 |
27 | Please consider what kind of change it is:
28 | * For a **Major Feature**, first open an issue and outline your proposal so that it can be discussed.
29 | This will also allow us to better coordinate our efforts, prevent duplication of work, and help you to craft the change
30 | so that it is successfully accepted into the project.
31 | * **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr).
32 |
33 | ## Submission guidelines
34 | ### Submitting an Issue
35 | Before you submit an issue, please search the issue tracker, maybe an issue for your problem already exists and the discussion
36 | might inform you of workarounds readily available.
37 |
38 | We want to fix all the issues as soon as possible, but before fixing a bug we need to reproduce and confirm it. In order
39 | to reproduce bugs we will systematically ask you to provide a minimal reproduction scenario using http://plnkr.co.
40 |
41 | Having a live, reproducible scenario gives us wealth of important information without going back & forth to you with additional
42 | questions like:
43 | - version used
44 | - 3rd-party libraries and their versions
45 | - and most importantly: a use-case that fails
46 |
47 | A minimal reproduce scenario using http://plnkr.co/ allows us to quickly confirm a bug (or point out coding problem) as
48 | well as confirm that we are fixing the right problem. If plunker is not a suitable way to demonstrate the problem (*ex:
49 | issues related to our npm packaging*), please create a standalone git repository demonstrating the problem.
50 |
51 | We will be insisting on a minimal reproduce scenario in order to save maintainers time and ultimately be able to fix more
52 | bugs.
53 |
54 | Interestingly, from our experience users often find coding problems themselves while preparing a minimal plunk. We understand
55 | that sometimes it might be hard to extract essentials bits of code from a larger code-base but we really need to isolate
56 | the problem before we can fix it.
57 |
58 | Unfortunately we are not able to investigate / fix bugs without a minimal reproduction, so if we don't hear back from you,
59 | we are going to close an issue that don't have enough info to be reproduced.
60 |
61 | You can file new issues by filling out our [new issue form](https://github.com/fulls1z3/ngx-universal/issues/new).
62 |
63 | ### Submitting a Pull Request (PR)
64 | Before you submit your Pull Request (PR) consider the following guidelines:
65 |
66 | * Search [GitHub](https://github.com/fulls1z3/ngx-universal/pulls) for an open or closed PR that relates to your submission.
67 | You don't want to duplicate effort.
68 | * Make your changes in a new git branch:
69 | ```shell
70 | git checkout -b my-fix-branch master
71 | ```
72 | * Create your patch, **including appropriate test cases**.
73 | * Follow our [Coding rules](#rules).
74 | * Run the full test suite and ensure that all tests pass.
75 | * Commit your changes using a descriptive commit message that follows our [commit message conventions](#commit).
76 | Adherence to these conventions is necessary because release notes are automatically generated from these messages.
77 | ```shell
78 | git commit -a
79 | ```
80 | Note: the optional commit `-a` command line option will automatically "add" and "rm" edited files.
81 | * Push your branch to GitHub:
82 | ```shell
83 | git push origin my-fix-branch
84 | ```
85 | * In GitHub, send a pull request to `state-transfer:master`.
86 | * If we suggest changes then:
87 | * Make the required updates.
88 | * Re-run the test suites to ensure tests are still passing.
89 | * Rebase your branch and force push to your GitHub repository (this will update your Pull Request):
90 | ```shell
91 | git rebase master -i
92 | git push -f
93 | ```
94 | That's it, thanks for your contribution!
95 |
96 | #### After your pull request is merged
97 | After your pull request is merged, you can safely delete your branch and pull the changes from the main (upstream) repository:
98 | * Delete the remote branch on GitHub either through the GitHub web UI or your local shell as follows:
99 | ```shell
100 | git push origin --delete my-fix-branch
101 | ```
102 | * Check out the master branch:
103 | ```shell
104 | git checkout master -f
105 | ```
106 | * Delete the local branch:
107 | ```shell
108 | git branch -D my-fix-branch
109 | ```
110 | * Update your master with the latest upstream version:
111 | ```shell
112 | git pull --ff upstream master
113 | ```
114 |
115 | ## Coding rules
116 | To ensure consistency throughout the source code, keep these rules in mind as you are working:
117 | * All features or bug fixes **must be tested** by one or more specs (unit-tests).
118 | * All public API methods **must be documented**. (Details TBC).
119 | * We follow [fulls1z3's Angular TSLint rules][angular-tslint-rules].
120 |
121 | ## Commit message guidelines
122 | We have very precise rules over how our git commit messages can be formatted. This leads to **more readable messages** that
123 | are easy to follow when looking through the **project history**. But also, we use the git commit messages to **generate
124 | the `ngx-universal` change log**.
125 |
126 | ### Commit Message Format
127 | Each commit message consists of a **header**, a **body** and a **footer**. The header has a special format that includes
128 | a **type**, a **scope** (*when applicable*) and a **subject**:
129 | ```
130 | ():
131 |
132 |
133 |
134 |