diff --git a/.gitignore b/.gitignore index 611d291..b3ddb43 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ npm-debug.log node_modules jspm_packages +tmp /dist *.metadata.json .idea diff --git a/README.md b/README.md index 5655a8c..fb11b8a 100644 --- a/README.md +++ b/README.md @@ -73,4 +73,4 @@ telInputObject(obj) { } ``` -![N|Solid](./example.png) +![N|Solid](https://raw.githubusercontent.com/gauravsoni119/ng2-tel-input/master/example.png) diff --git a/changelog.md b/changelog.md index 98f444f..70f120b 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.3.0] - 2020-3-08 +### Changed +- Align packages with Angular Package Format + ## [2.2.0] - 2020-2-29 ### Changed - Revert dependency of angular to 8 diff --git a/gulpfile.js b/gulpfile.js index b8737b2..68652a4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -43,14 +43,23 @@ const compile = async (cb) => { } /** - * copy package.jsona and README.md, and example.png to package + * copy assets to package * @param {Function} cb needs to execute at the end of the function */ -copy = (cb) => { - const stream = src(['./package.json', './README.md', './example.png']).pipe(dest('./dist')); +const copyAssets = (cb) => { + const stream = src(['tmp/esm2015/*.d.ts', 'tmp/esm2015/*.json','./package.json', './README.md']).pipe(dest('dist/')); stream.on('end', () => cb()); }; +/** + * copy declarations(d.ts) files to package + * @param {Function} cb needs to execute at the end of the function + */ +const copySrcDeclarations = (cb) => { + src('tmp/esm2015/src/*.d.ts').pipe(dest('dist/src')); + cb(); +}; + /** * Run yarn pack command to create .tar file so that we can install package locally and test it * @param {Function} cb needs to execute at the end of the function @@ -72,6 +81,15 @@ const cleanDist = (cb) => { cb(); }; +/** + * Remove tmp folder + * @param {Function} cb needs to execute at the end of the function + */ +const cleanTmp = (cb) => { + src(path.resolve(__dirname, 'tmp')).pipe(clean()); + cb(); +}; + /** * Wrapp readFile function inside promise so that we can use promises * @param {string} path of the file @@ -96,10 +114,31 @@ const updatePackageJson = async (cb) => { const packageFile = JSON.parse(file); packageFile.devDependencies = {}; packageFile.scripts = {}; + packageFile.main = "./bundles/ng2-tel-input.umd.min.js"; + packageFile.module = "./esm5/ng2-tel-input.js"; + packageFile.es2015 = "./esm2015/ng2-tel-input.js"; + packageFile.typings = "./ng2-tel-input.d.ts"; const data = JSON.stringify(packageFile, null, 2); fs.writeFileSync(path.resolve(`${__dirname}/dist`, 'package.json'), data); cb(); }; -exports.buildDev = series(cleanDist, compile, copy, updatePackageJson, pack); -exports.default = series(cleanDist, compile, copy, updatePackageJson); \ No newline at end of file +/** + * Create tmp direcatory in root folder and copy the src into the tmp src directory + * @param {Function} cb The callback that needs to execute at the end of function + */ +const createTempDir = async (cb) => { + src(['./src/**/*.ts']).pipe(dest('./tmp/src')); +}; + +/** + * Copy the public_api.ts file into the tmp directory + * @param {Function} cb The callback that needs to execute at the end of function + */ +const copyPublicApi = async (cb) => { + src(['./public_api.ts']).pipe(dest('./tmp')); +}; + + +exports.buildDev = series(cleanDist, createTempDir, copyPublicApi, compile, copyAssets, copySrcDeclarations, updatePackageJson, cleanTmp, pack); +exports.default = series(cleanDist, createTempDir, copyPublicApi, compile, copyAssets, copySrcDeclarations, updatePackageJson, cleanTmp); \ No newline at end of file diff --git a/ng2-tel-input.ts b/ng2-tel-input.ts deleted file mode 100644 index aa82ca7..0000000 --- a/ng2-tel-input.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { Ng2TelInputModule } from './src/ng2-tel-input.module'; -export { Ng2TelInput } from './src/ng2-tel-input'; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 357453e..8cba33b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ng2-tel-input", - "version": "2.1.0", + "version": "2.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -572,6 +572,12 @@ "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==", "dev": true }, + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + }, "component-emitter": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz", @@ -3240,6 +3246,24 @@ "glob": "^7.1.3" } }, + "rollup": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.0.2.tgz", + "integrity": "sha512-99VIc2DHm+HEhdla2ASH/LaomWS3v7RDANamD65w24TQTNVs3vtRM+oiFsP4KvUCri5+p5Q5xoXscUnIdE8gJA==", + "dev": true, + "requires": { + "fsevents": "~2.1.2" + }, + "dependencies": { + "fsevents": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.2.tgz", + "integrity": "sha512-R4wDiBwZ0KzpgOWetKDug1FZcYhqYnUYKtfZYt4mD5SBz76q0KR4Q9o7GIPamsVPGmW3EYPPJ0dOOjvx32ldZA==", + "dev": true, + "optional": true + } + } + }, "rxjs": { "version": "6.5.4", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.4.tgz", @@ -3726,6 +3750,12 @@ "through2": "^2.0.3" } }, + "tsickle": { + "version": "0.38.1", + "resolved": "https://registry.npmjs.org/tsickle/-/tsickle-0.38.1.tgz", + "integrity": "sha512-4xZfvC6+etRu6ivKCNqMOd1FqcY/m6JY3Y+yr5+Xw+i751ciwrWINi6x/3l1ekcODH9GZhlf0ny2LpzWxnjWYA==", + "dev": true + }, "tslib": { "version": "1.11.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.0.tgz", @@ -3750,6 +3780,16 @@ "integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==", "dev": true }, + "uglify-js": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.8.0.tgz", + "integrity": "sha512-ugNSTT8ierCsDHso2jkBHXYrU8Y5/fY2ZUprfrJUiD7YpuFvV4jODLFmb3h4btQjqr5Nh4TX4XtgDfCU1WdioQ==", + "dev": true, + "requires": { + "commander": "~2.20.3", + "source-map": "~0.6.1" + } + }, "unc-path-regex": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/unc-path-regex/-/unc-path-regex-0.1.2.tgz", diff --git a/package.json b/package.json index b902dfd..fe70155 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,16 @@ "scripts": { "watch": "tsc -p src -w", "start": "http-server -c-1 .", - "build": "ngc -p ./tsconfig-ngc.json", + "build": "npm run build:esm2015 && npm run build:fesm2015 && npm run build:esm5 && npm run build:fesm5 && npm run build:umd && npm run build:umd:min", "build:prod": "gulp", "build:dev": "gulp buildDev", + "createTemp": "gulp createTemp", + "build:esm2015": "ngc -p tsconfig-esm2015.json", + "build:fesm2015": "rollup -c rollup-esm2015.conf.js", + "build:esm5": "ngc -p tsconfig-esm5.json", + "build:fesm5": "rollup -c rollup-esm5.conf.js", + "build:umd": "rollup -c rollup-umd.conf.js", + "build:umd:min": "uglifyjs dist/bundles/ng2-tel-input.umd.js -c -m -o dist/bundles/ng2-tel-input.umd.min.js", "ls": "gulp --tasks" }, "repository": { @@ -35,8 +42,11 @@ "gulp": "^4.0.2", "gulp-clean": "^0.4.0", "reflect-metadata": "^0.1.13", + "rollup": "^2.0.2", "rxjs": "^6.5.2", + "tsickle": "^0.38.1", "typescript": "~3.4.5", + "uglify-js": "^3.8.0", "zone.js": "^0.9.1" }, "peerDependencies": { @@ -44,6 +54,5 @@ }, "dependencies": { "intl-tel-input": "^16.0.0" - }, - "typings": "./ng2-tel-input.d.ts" + } } diff --git a/public_api.ts b/public_api.ts new file mode 100644 index 0000000..4433b2e --- /dev/null +++ b/public_api.ts @@ -0,0 +1 @@ +export * from './src/index'; \ No newline at end of file diff --git a/rollup-esm2015.conf.js b/rollup-esm2015.conf.js new file mode 100644 index 0000000..3fb17df --- /dev/null +++ b/rollup-esm2015.conf.js @@ -0,0 +1,4 @@ +export default { + input: 'tmp/esm2015/ng2-tel-input.js', + output: { file: 'dist/esm2015/ng2-tel-input.js', format: 'es' }, +}; diff --git a/rollup-esm5.conf.js b/rollup-esm5.conf.js new file mode 100644 index 0000000..8728105 --- /dev/null +++ b/rollup-esm5.conf.js @@ -0,0 +1,4 @@ +export default { + input: 'tmp/esm5/ng2-tel-input.js', + output: { file: 'dist/esm5/ng2-tel-input.js', format: 'es' }, +}; diff --git a/rollup-umd.conf.js b/rollup-umd.conf.js new file mode 100644 index 0000000..94707d7 --- /dev/null +++ b/rollup-umd.conf.js @@ -0,0 +1,7 @@ +export default { + input: 'tmp/esm5/ng2-tel-input.js', + output: { file: 'dist/bundles/ng2-tel-input.umd.js', name: 'Ng2TelInput', format: 'umd' }, + globals: { + '@angular/core': 'ng.core' + } +}; diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..7c204fe --- /dev/null +++ b/src/index.ts @@ -0,0 +1,2 @@ +export { Ng2TelInputModule } from './ng2-tel-input.module'; +export { Ng2TelInput } from './ng2-tel-input'; \ No newline at end of file diff --git a/src/ng2-tel-input.ts b/src/ng2-tel-input.ts index e4f1b42..e24923e 100644 --- a/src/ng2-tel-input.ts +++ b/src/ng2-tel-input.ts @@ -8,7 +8,7 @@ const defaultUtilScript = 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input selector: '[ng2TelInput]', }) export class Ng2TelInput implements OnInit { - @Input('ng2TelInputOptions') ng2TelInputOptions: any = {}; + @Input('ng2TelInputOptions') ng2TelInputOptions: { [key: string]: any } = {}; @Output('hasError') hasError: EventEmitter = new EventEmitter(); @Output('ng2TelOutput') ng2TelOutput: EventEmitter = new EventEmitter(); @Output('countryChange') countryChange: EventEmitter = new EventEmitter(); diff --git a/tsconfig-ngc.json b/tsconfig-esm2015.json similarity index 60% rename from tsconfig-ngc.json rename to tsconfig-esm2015.json index 18f2ba1..0c4867d 100644 --- a/tsconfig-ngc.json +++ b/tsconfig-esm2015.json @@ -1,26 +1,28 @@ { "compilerOptions": { - "target": "es5", + "target": "es2015", "module": "es2015", "lib": [ "es2015", "dom" ], "moduleResolution": "node", - "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, - "removeComments": false, "noImplicitAny": true, "declaration": true, "stripInternal": true, - "outDir": "./dist" + "outDir": "./tmp/esm2015", + "rootDir": "./tmp" }, "exclude": [ "node_modules" ], "files": [ - "./ng2-tel-input.ts" + "./tmp/public_api.ts" ], "angularCompilerOptions": { + "annotateForClosureCompiler": true, "strictMetadataEmit": true, - "skipTemplateCodegen": true + "skipTemplateCodegen": true, + "flatModuleOutFile": "ng2-tel-input.js", + "flatModuleId": "ng2-tel-input", } } \ No newline at end of file diff --git a/tsconfig-esm5.json b/tsconfig-esm5.json new file mode 100644 index 0000000..a1d9f02 --- /dev/null +++ b/tsconfig-esm5.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig-esm2015.json", + "compilerOptions": { + "target": "es5", + "outDir": "./tmp/esm5", + "rootDir": "./tmp" + }, + "angularCompilerOptions": { + "annotateForClosureCompiler": true, + "strictMetadataEmit": true, + "skipTemplateCodegen": true, + "flatModuleOutFile": "ng2-tel-input.js", + "flatModuleId": "ng2-tel-input", + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 7cf8664..6dde7ff 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,9 +9,6 @@ "sourceMap": true, "declaration": true }, - "files": [ - "ng2-tel-input.ts" - ], "exclude": [ "node_modules" ] diff --git a/yarn.lock b/yarn.lock index 5f7cc53..fdac34d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -426,6 +426,11 @@ color-support@^1.1.3: resolved "https://registry.yarnpkg.com/color-support/-/color-support-1.1.3.tgz#93834379a1cc9a0c61f82f52f0d04322251bd5a2" integrity sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg== +commander@~2.20.3: + version "2.20.3" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" + integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== + component-emitter@^1.2.1: version "1.3.0" resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0" @@ -836,6 +841,11 @@ fsevents@^1.2.7: bindings "^1.5.0" nan "^2.12.1" +fsevents@~2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.1.2.tgz#4c0a1fb34bc68e543b4b82a9ec392bfbda840805" + integrity sha512-R4wDiBwZ0KzpgOWetKDug1FZcYhqYnUYKtfZYt4mD5SBz76q0KR4Q9o7GIPamsVPGmW3EYPPJ0dOOjvx32ldZA== + function-bind@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" @@ -2012,6 +2022,13 @@ rimraf@^2.6.2: dependencies: glob "^7.1.3" +rollup@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.0.2.tgz#0f63aa02bb106802a387380ee88b90b5c0449eaa" + integrity sha512-99VIc2DHm+HEhdla2ASH/LaomWS3v7RDANamD65w24TQTNVs3vtRM+oiFsP4KvUCri5+p5Q5xoXscUnIdE8gJA== + optionalDependencies: + fsevents "~2.1.2" + rxjs@^6.5.2: version "6.5.4" resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.5.4.tgz#e0777fe0d184cec7872df147f303572d414e211c" @@ -2129,7 +2146,7 @@ source-map@^0.5.6: resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w= -source-map@^0.6.1: +source-map@^0.6.1, source-map@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== @@ -2339,6 +2356,11 @@ to-through@^2.0.0: dependencies: through2 "^2.0.3" +tsickle@^0.38.1: + version "0.38.1" + resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.38.1.tgz#30762db759d40c435943093b6972c7f2efb384ef" + integrity sha512-4xZfvC6+etRu6ivKCNqMOd1FqcY/m6JY3Y+yr5+Xw+i751ciwrWINi6x/3l1ekcODH9GZhlf0ny2LpzWxnjWYA== + tslib@^1.9.0: version "1.9.3" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286" @@ -2363,6 +2385,14 @@ typescript@~3.4.5: resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.5.tgz#2d2618d10bb566572b8d7aad5180d84257d70a99" integrity sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw== +uglify-js@^3.8.0: + version "3.8.0" + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.8.0.tgz#f3541ae97b2f048d7e7e3aa4f39fd8a1f5d7a805" + integrity sha512-ugNSTT8ierCsDHso2jkBHXYrU8Y5/fY2ZUprfrJUiD7YpuFvV4jODLFmb3h4btQjqr5Nh4TX4XtgDfCU1WdioQ== + dependencies: + commander "~2.20.3" + source-map "~0.6.1" + unc-path-regex@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/unc-path-regex/-/unc-path-regex-0.1.2.tgz#e73dd3d7b0d7c5ed86fbac6b0ae7d8c6a69d50fa"