Skip to content

Commit

Permalink
build(packaging): produce angular package format compatible code (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
trotyl authored and vthinkxie committed Sep 9, 2017
1 parent 5e950ab commit d8063a1
Show file tree
Hide file tree
Showing 70 changed files with 1,056 additions and 46 deletions.
21 changes: 13 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/doc
/tmp
/out-tsc
dist/
doc/
tmp/
out-tsc/
publish/
integration/**/lib/
integration/**/*.ngfactory.ts
integration/**/*.ngsummary.json



/src/release
# dependencies
/node_modules
node_modules/
package-lock.json
integration/**/package-lock.json
yarn.lock

# IDEs and editors
/.idea
.idea/
.project
.classpath
.c9/
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ before_script:

script:
- npm run test
- npm run integration
- cat ./coverage/lcov.info | ./node_modules/.bin/coveralls
30 changes: 27 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,32 @@

readonly currentDir=$(cd $(dirname $0); pwd)
cd ${currentDir}
rm -rf src/release
rm -rf publish
cp -r src/components src/__gen_components
node ./less.convert.js
cd src/__gen_components && ../../node_modules/@angular/compiler-cli/src/main.js
cd .. && rm -rf __gen_components

echo 'Generating entry file using Angular compiler'
$(npm bin)/ngc -p tsconfig-build.json
rm -rf src/__gen_components

echo 'Bundling to es module'
export ROLLUP_FORMAT=es
$(npm bin)/rollup -c rollup.config.js
rm -rf publish/src/*.js
rm -rf publish/src/**/*.js
sed -e "s/from '.\//from '.\/src\//g" publish/src/index.d.ts > publish/index.d.ts
sed -e "s/\":\".\//\":\".\/src\//g" publish/src/index.metadata.json > publish/index.metadata.json
rm publish/src/index.d.ts publish/src/index.metadata.json

echo 'Transpiling es module to es5'
$(npm bin)/tsc --allowJs --importHelpers --target es5 --module es2015 --outDir publish/esm5 publish/esm15/index.js

echo 'Bundling to umd module'
export ROLLUP_FORMAT=umd
$(npm bin)/rollup -c rollup.config.js

echo 'Minifying umd module'
$(npm bin)/uglifyjs publish/bundles/ng-zorro-antd.umd.js --output publish/bundles/ng-zorro-antd.umd.min.js

echo 'Copying package.json'
cp package.json publish/package.json
9 changes: 9 additions & 0 deletions integration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
for dir in ./integration/*/
do
dir=${dir%*/}
name=${dir##*/}
echo "Integration test for $name"
cd $dir
npm run integration
cd ../..
done
82 changes: 82 additions & 0 deletions integration/angular-cli/.angular-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "integration-test"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json",
"exclude": "**/node_modules/**"
},
{
"project": "src/tsconfig.spec.json",
"exclude": "**/node_modules/**"
},
{
"project": "e2e/tsconfig.e2e.json",
"exclude": "**/node_modules/**"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {
"spec": false,
"inlineStyle": true,
"inlineTemplate": true
},
"directive": {
"spec": false
},
"class": {
"spec": false
},
"guard": {
"spec": false
},
"module": {
"spec": false
},
"pipe": {
"spec": false
},
"service": {
"spec": false
}
}
}
40 changes: 40 additions & 0 deletions integration/angular-cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "integration-test",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"setup": "mkdir -p lib/ng-zorro-antd && rsync -av --exclude=\".*\" ../../publish/ lib/ng-zorro-antd",
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "echo \"Error: no test... minimal project\" && exit 1",
"lint": "echo \"Error: no lint... minimal project\" && exit 1",
"e2e": "echo \"Error: no e2e... minimal project\" && exit 1",
"preintegration": "npm run setup && npm install",
"integration": "ng build --prod --build-optimizer"
},
"private": true,
"dependencies": {
"@angular/animations": "^4.2.4",
"@angular/cdk": "2.0.0-beta.8",
"@angular/common": "^4.2.4",
"@angular/compiler": "^4.2.4",
"@angular/core": "^4.2.4",
"@angular/forms": "^4.2.4",
"@angular/http": "^4.2.4",
"@angular/platform-browser": "^4.2.4",
"@angular/platform-browser-dynamic": "^4.2.4",
"@angular/router": "^4.2.4",
"core-js": "^2.4.1",
"moment": "^2.18.1",
"ng-zorro-antd": "file:lib/ng-zorro-antd",
"rxjs": "^5.4.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.3.2",
"@angular/compiler-cli": "^4.2.4",
"@angular/language-service": "^4.2.4",
"typescript": "~2.3.3"
}
}
12 changes: 12 additions & 0 deletions integration/angular-cli/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-root',
template: `
<button nz-button [nzType]="'primary'">测试按钮</button>
`,
styles: []
})
export class AppComponent {
title = 'app';
}
18 changes: 18 additions & 0 deletions integration/angular-cli/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgZorroAntdModule } from 'ng-zorro-antd';

import { AppComponent } from './app.component';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
NgZorroAntdModule.forRoot(),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Empty file.
3 changes: 3 additions & 0 deletions integration/angular-cli/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const environment = {
production: true
};
8 changes: 8 additions & 0 deletions integration/angular-cli/src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.

export const environment = {
production: false
};
13 changes: 13 additions & 0 deletions integration/angular-cli/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>IntegrationTest</title>
<base href="/">

<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<app-root></app-root>
</body>
</html>
11 changes: 11 additions & 0 deletions integration/angular-cli/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);
72 changes: 72 additions & 0 deletions integration/angular-cli/src/polyfills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
*/

/***************************************************************************************************
* BROWSER POLYFILLS
*/

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
// import 'core-js/es6/symbol';
// import 'core-js/es6/object';
// import 'core-js/es6/function';
// import 'core-js/es6/parse-int';
// import 'core-js/es6/parse-float';
// import 'core-js/es6/number';
// import 'core-js/es6/math';
// import 'core-js/es6/string';
// import 'core-js/es6/date';
// import 'core-js/es6/array';
// import 'core-js/es6/regexp';
// import 'core-js/es6/map';
// import 'core-js/es6/weak-map';
// import 'core-js/es6/set';

/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run `npm install --save classlist.js`.

/** Evergreen browsers require these. **/
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';


/**
* Required to support Web Animations `@angular/animation`.
* Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
**/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.



/***************************************************************************************************
* Zone JS is required by Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.



/***************************************************************************************************
* APPLICATION IMPORTS
*/

/**
* Date, currency, decimal and percent pipes.
* Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
*/
// import 'intl'; // Run `npm install --save intl`.
/**
* Need to import at least one locale-data with intl.
*/
// import 'intl/locale-data/jsonp/en';
1 change: 1 addition & 0 deletions integration/angular-cli/src/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* You can add global styles to this file, and also import other style files */
13 changes: 13 additions & 0 deletions integration/angular-cli/src/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"module": "es2015",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
5 changes: 5 additions & 0 deletions integration/angular-cli/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* SystemJS module definition */
declare var module: NodeModule;
interface NodeModule {
id: string;
}
19 changes: 19 additions & 0 deletions integration/angular-cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
Loading

0 comments on commit d8063a1

Please sign in to comment.