From 5d217c768891e9b310293f37059a36f6e3c7b5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= <info@sebastian-mueller.net> Date: Mon, 19 Jun 2017 19:45:59 +0200 Subject: [PATCH] refactor: enable to develop multiple packages --- .gitignore | 6 +++--- karma-test-shim.js | 2 +- package.json | 16 ++++++++------- {src => packages}/core/core.module.ts | 0 {src => packages}/core/directives.ts | 0 {src => packages}/core/directives/circle.ts | 0 .../core/directives/data-layer.ts | 0 .../core/directives/info-window.ts | 0 .../core/directives/kml-layer.ts | 0 {src => packages}/core/directives/map.ts | 0 {src => packages}/core/directives/marker.ts | 0 {src => packages}/core/directives/polygon.ts | 0 .../core/directives/polyline-point.ts | 0 {src => packages}/core/directives/polyline.ts | 0 {src => packages}/core/index.ts | 0 {src => packages}/core/map-types.ts | 0 {src => packages}/core/services.ts | 0 .../core/services/google-maps-api-wrapper.ts | 0 .../core/services/google-maps-types.ts | 0 .../core/services/managers/circle-manager.ts | 0 .../services/managers/data-layer-manager.ts | 0 .../services/managers/info-window-manager.ts | 0 .../services/managers/kml-layer-manager.ts | 0 .../services/managers/marker-manager.spec.ts | 0 .../core/services/managers/marker-manager.ts | 0 .../services/managers/polygon-manager.spec.ts | 0 .../core/services/managers/polygon-manager.ts | 0 .../managers/polyline-manager.spec.ts | 0 .../services/managers/polyline-manager.ts | 0 .../lazy-maps-api-loader.spec.ts | 0 .../maps-api-loader/lazy-maps-api-loader.ts | 0 .../maps-api-loader/maps-api-loader.ts | 0 .../maps-api-loader/noop-maps-api-loader.ts | 0 .../core/utils/browser-globals.ts | 0 rollup.config.js => rollup.core.config.js | 0 scripts/create-package-json.js | 7 ++++++- tsconfig.json | 9 ++++++--- webpack.config.js | 20 +++++++++---------- 38 files changed, 35 insertions(+), 25 deletions(-) rename {src => packages}/core/core.module.ts (100%) rename {src => packages}/core/directives.ts (100%) rename {src => packages}/core/directives/circle.ts (100%) rename {src => packages}/core/directives/data-layer.ts (100%) rename {src => packages}/core/directives/info-window.ts (100%) rename {src => packages}/core/directives/kml-layer.ts (100%) rename {src => packages}/core/directives/map.ts (100%) rename {src => packages}/core/directives/marker.ts (100%) rename {src => packages}/core/directives/polygon.ts (100%) rename {src => packages}/core/directives/polyline-point.ts (100%) rename {src => packages}/core/directives/polyline.ts (100%) rename {src => packages}/core/index.ts (100%) rename {src => packages}/core/map-types.ts (100%) rename {src => packages}/core/services.ts (100%) rename {src => packages}/core/services/google-maps-api-wrapper.ts (100%) rename {src => packages}/core/services/google-maps-types.ts (100%) rename {src => packages}/core/services/managers/circle-manager.ts (100%) rename {src => packages}/core/services/managers/data-layer-manager.ts (100%) rename {src => packages}/core/services/managers/info-window-manager.ts (100%) rename {src => packages}/core/services/managers/kml-layer-manager.ts (100%) rename {src => packages}/core/services/managers/marker-manager.spec.ts (100%) rename {src => packages}/core/services/managers/marker-manager.ts (100%) rename {src => packages}/core/services/managers/polygon-manager.spec.ts (100%) rename {src => packages}/core/services/managers/polygon-manager.ts (100%) rename {src => packages}/core/services/managers/polyline-manager.spec.ts (100%) rename {src => packages}/core/services/managers/polyline-manager.ts (100%) rename {src => packages}/core/services/maps-api-loader/lazy-maps-api-loader.spec.ts (100%) rename {src => packages}/core/services/maps-api-loader/lazy-maps-api-loader.ts (100%) rename {src => packages}/core/services/maps-api-loader/maps-api-loader.ts (100%) rename {src => packages}/core/services/maps-api-loader/noop-maps-api-loader.ts (100%) rename {src => packages}/core/utils/browser-globals.ts (100%) rename rollup.config.js => rollup.core.config.js (100%) diff --git a/.gitignore b/.gitignore index a6032ee63..dc8d5d0df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,9 @@ node_modules/ dist docs_generated -src/**/*.js -src/**/*.map -src/**/*.ngfactory.js +packages/**/*.js +packages/**/*.map +packages/**/*.ngfactory.js .tmp test-built npm-debug.log diff --git a/karma-test-shim.js b/karma-test-shim.js index c349de72e..169dc1abb 100644 --- a/karma-test-shim.js +++ b/karma-test-shim.js @@ -16,7 +16,7 @@ require('zone.js/dist/jasmine-patch'); require('zone.js/dist/async-test'); require('zone.js/dist/fake-async-test'); -var ctx = require.context('./src', true, /\.spec\.ts/); +var ctx = require.context('./packages', true, /\.spec\.ts/); ctx.keys().forEach(ctx); var testing = require('@angular/core/testing'); diff --git a/package.json b/package.json index 188603690..13bb11904 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { - "name": "@agm/core-src", + "name": "@agm/dummy", + "private": true, "version": "1.0.0-beta.0", "description": "Angular 2+ components for Google Maps", "repository": { @@ -17,17 +18,18 @@ "angular2" ], "scripts": { - "clean": "rimraf dist && rimraf .tmp && mkdir dist && mkdir .tmp && rimraf 'src/**/*.ngfactory.ts'", + "clean": "rimraf dist && rimraf .tmp && mkdir dist && mkdir .tmp && rimraf 'packages/**/*.ngfactory.ts'", "prebuild": "npm run clean", "build": "npm run lint && npm run scripts && npm run packagejson && npm run copyassets", - "lint": "tslint -c tslint.json 'src/**/*.ts'", + "lint": "tslint -c tslint.json 'packages/**/*.ts'", "packagejson": "node ./scripts/create-package-json.js", "copyassets": "cp -R assets/release/* dist/core && cp LICENSE dist/core", - "scripts": "npm run ngc:esm && npm run bundle:umd", - "bundle:umd": "rollup -c rollup.config.js", + "scripts": "npm run ngc:esm && npm run bundle", + "bundle": "npm run bundle:umd:core", + "bundle:umd:core": "rollup -c rollup.core.config.js", "ngc:esm": "ngc -p tsconfig.json", - "clang:format": "clang-format --glob=src/**/*.ts -i", - "postngc:esm": "mkdir -p dist/ && cp -R .tmp/esm/src/* dist/ && rimraf src/**/*.ngfactory.ts", + "clang:format": "clang-format --glob=packages/**/*.ts -i", + "postngc:esm": "mkdir -p dist/ && cp -R .tmp/esm/* dist/ && rimraf packages/**/*.ngfactory.ts", "test": "karma start", "test:watch": "karma start --no-single-run --auto-watch", "ci": "npm run build && npm run test", diff --git a/src/core/core.module.ts b/packages/core/core.module.ts similarity index 100% rename from src/core/core.module.ts rename to packages/core/core.module.ts diff --git a/src/core/directives.ts b/packages/core/directives.ts similarity index 100% rename from src/core/directives.ts rename to packages/core/directives.ts diff --git a/src/core/directives/circle.ts b/packages/core/directives/circle.ts similarity index 100% rename from src/core/directives/circle.ts rename to packages/core/directives/circle.ts diff --git a/src/core/directives/data-layer.ts b/packages/core/directives/data-layer.ts similarity index 100% rename from src/core/directives/data-layer.ts rename to packages/core/directives/data-layer.ts diff --git a/src/core/directives/info-window.ts b/packages/core/directives/info-window.ts similarity index 100% rename from src/core/directives/info-window.ts rename to packages/core/directives/info-window.ts diff --git a/src/core/directives/kml-layer.ts b/packages/core/directives/kml-layer.ts similarity index 100% rename from src/core/directives/kml-layer.ts rename to packages/core/directives/kml-layer.ts diff --git a/src/core/directives/map.ts b/packages/core/directives/map.ts similarity index 100% rename from src/core/directives/map.ts rename to packages/core/directives/map.ts diff --git a/src/core/directives/marker.ts b/packages/core/directives/marker.ts similarity index 100% rename from src/core/directives/marker.ts rename to packages/core/directives/marker.ts diff --git a/src/core/directives/polygon.ts b/packages/core/directives/polygon.ts similarity index 100% rename from src/core/directives/polygon.ts rename to packages/core/directives/polygon.ts diff --git a/src/core/directives/polyline-point.ts b/packages/core/directives/polyline-point.ts similarity index 100% rename from src/core/directives/polyline-point.ts rename to packages/core/directives/polyline-point.ts diff --git a/src/core/directives/polyline.ts b/packages/core/directives/polyline.ts similarity index 100% rename from src/core/directives/polyline.ts rename to packages/core/directives/polyline.ts diff --git a/src/core/index.ts b/packages/core/index.ts similarity index 100% rename from src/core/index.ts rename to packages/core/index.ts diff --git a/src/core/map-types.ts b/packages/core/map-types.ts similarity index 100% rename from src/core/map-types.ts rename to packages/core/map-types.ts diff --git a/src/core/services.ts b/packages/core/services.ts similarity index 100% rename from src/core/services.ts rename to packages/core/services.ts diff --git a/src/core/services/google-maps-api-wrapper.ts b/packages/core/services/google-maps-api-wrapper.ts similarity index 100% rename from src/core/services/google-maps-api-wrapper.ts rename to packages/core/services/google-maps-api-wrapper.ts diff --git a/src/core/services/google-maps-types.ts b/packages/core/services/google-maps-types.ts similarity index 100% rename from src/core/services/google-maps-types.ts rename to packages/core/services/google-maps-types.ts diff --git a/src/core/services/managers/circle-manager.ts b/packages/core/services/managers/circle-manager.ts similarity index 100% rename from src/core/services/managers/circle-manager.ts rename to packages/core/services/managers/circle-manager.ts diff --git a/src/core/services/managers/data-layer-manager.ts b/packages/core/services/managers/data-layer-manager.ts similarity index 100% rename from src/core/services/managers/data-layer-manager.ts rename to packages/core/services/managers/data-layer-manager.ts diff --git a/src/core/services/managers/info-window-manager.ts b/packages/core/services/managers/info-window-manager.ts similarity index 100% rename from src/core/services/managers/info-window-manager.ts rename to packages/core/services/managers/info-window-manager.ts diff --git a/src/core/services/managers/kml-layer-manager.ts b/packages/core/services/managers/kml-layer-manager.ts similarity index 100% rename from src/core/services/managers/kml-layer-manager.ts rename to packages/core/services/managers/kml-layer-manager.ts diff --git a/src/core/services/managers/marker-manager.spec.ts b/packages/core/services/managers/marker-manager.spec.ts similarity index 100% rename from src/core/services/managers/marker-manager.spec.ts rename to packages/core/services/managers/marker-manager.spec.ts diff --git a/src/core/services/managers/marker-manager.ts b/packages/core/services/managers/marker-manager.ts similarity index 100% rename from src/core/services/managers/marker-manager.ts rename to packages/core/services/managers/marker-manager.ts diff --git a/src/core/services/managers/polygon-manager.spec.ts b/packages/core/services/managers/polygon-manager.spec.ts similarity index 100% rename from src/core/services/managers/polygon-manager.spec.ts rename to packages/core/services/managers/polygon-manager.spec.ts diff --git a/src/core/services/managers/polygon-manager.ts b/packages/core/services/managers/polygon-manager.ts similarity index 100% rename from src/core/services/managers/polygon-manager.ts rename to packages/core/services/managers/polygon-manager.ts diff --git a/src/core/services/managers/polyline-manager.spec.ts b/packages/core/services/managers/polyline-manager.spec.ts similarity index 100% rename from src/core/services/managers/polyline-manager.spec.ts rename to packages/core/services/managers/polyline-manager.spec.ts diff --git a/src/core/services/managers/polyline-manager.ts b/packages/core/services/managers/polyline-manager.ts similarity index 100% rename from src/core/services/managers/polyline-manager.ts rename to packages/core/services/managers/polyline-manager.ts diff --git a/src/core/services/maps-api-loader/lazy-maps-api-loader.spec.ts b/packages/core/services/maps-api-loader/lazy-maps-api-loader.spec.ts similarity index 100% rename from src/core/services/maps-api-loader/lazy-maps-api-loader.spec.ts rename to packages/core/services/maps-api-loader/lazy-maps-api-loader.spec.ts diff --git a/src/core/services/maps-api-loader/lazy-maps-api-loader.ts b/packages/core/services/maps-api-loader/lazy-maps-api-loader.ts similarity index 100% rename from src/core/services/maps-api-loader/lazy-maps-api-loader.ts rename to packages/core/services/maps-api-loader/lazy-maps-api-loader.ts diff --git a/src/core/services/maps-api-loader/maps-api-loader.ts b/packages/core/services/maps-api-loader/maps-api-loader.ts similarity index 100% rename from src/core/services/maps-api-loader/maps-api-loader.ts rename to packages/core/services/maps-api-loader/maps-api-loader.ts diff --git a/src/core/services/maps-api-loader/noop-maps-api-loader.ts b/packages/core/services/maps-api-loader/noop-maps-api-loader.ts similarity index 100% rename from src/core/services/maps-api-loader/noop-maps-api-loader.ts rename to packages/core/services/maps-api-loader/noop-maps-api-loader.ts diff --git a/src/core/utils/browser-globals.ts b/packages/core/utils/browser-globals.ts similarity index 100% rename from src/core/utils/browser-globals.ts rename to packages/core/utils/browser-globals.ts diff --git a/rollup.config.js b/rollup.core.config.js similarity index 100% rename from rollup.config.js rename to rollup.core.config.js diff --git a/scripts/create-package-json.js b/scripts/create-package-json.js index 46155ba03..ccb1a9aed 100644 --- a/scripts/create-package-json.js +++ b/scripts/create-package-json.js @@ -7,7 +7,12 @@ const path = require('path'); const pkgNames = ['core']; pkgNames.forEach(function(pkgName) { - const basePkgJson = JSON.parse(fs.readFileSync('./package.json', 'utf8')); + let basePkgJson; + if (fs.existsSync(`./packages/${pkgName}/package.tpl.json`)) { + basePkgJson = JSON.parse(fs.readFileSync(`./packages/${pkgName}/package.tpl.json`, 'utf8')); + } else { + basePkgJson = JSON.parse(fs.readFileSync('./package.json', 'utf8')); + } // define the package name basePkgJson.name = `@agm/${pkgName}` diff --git a/tsconfig.json b/tsconfig.json index f7eaa1507..8a05b81a5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,7 @@ "experimentalDecorators": true, "emitDecoratorMetadata": true, "outDir": ".tmp/esm", - "rootDir": ".", + "baseUrl": ".", "sourceMap": true, "removeComments": false, "moduleResolution": "node", @@ -17,7 +17,10 @@ ], "types": [ "jasmine" - ] + ], + "paths": { + "@agm/*": ["./packages/*"] + } }, "angularCompilerOptions": { "genDir": ".tmp", @@ -28,6 +31,6 @@ ".tmp" ], "include": [ - "src/**/*" + "packages/**/*" ] } diff --git a/webpack.config.js b/webpack.config.js index 1b1319a38..1ecacd395 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -92,29 +92,29 @@ module.exports = function makeWebpackConfig() { // Support for CSS as raw text // use 'null' loader in test mode (https://github.com/webpack/null-loader) - // all css in src/style will be bundled in an external css file + // all css in packages/style will be bundled in an external css file { test: /\.css$/, - exclude: root('src', 'app'), + exclude: root('packages', 'app'), loader: isTest ? 'null-loader' : ExtractTextPlugin.extract({ fallback: 'style-loader', use: ['css-loader', 'postcss-loader']}) }, // all css required in src/app files will be merged in js files - {test: /\.css$/, include: root('src', 'app'), loader: 'raw-loader!postcss-loader'}, + {test: /\.css$/, include: root('packages', 'app'), loader: 'raw-loader!postcss-loader'}, // support for .scss files // use 'null' loader in test mode (https://github.com/webpack/null-loader) - // all css in src/style will be bundled in an external css file + // all css in packages/style will be bundled in an external css file { test: /\.(scss|sass)$/, - exclude: root('src', 'app'), + exclude: root('packages', 'app'), loader: isTest ? 'null-loader' : ExtractTextPlugin.extract({ fallback: 'style-loader', use: ['css-loader', 'postcss-loader', 'sass-loader']}) }, - // all css required in src/app files will be merged in js files - {test: /\.(scss|sass)$/, exclude: root('src', 'style'), loader: 'raw-loader!postcss-loader!sass-loader'}, + // all css required in packages/app files will be merged in js files + {test: /\.(scss|sass)$/, exclude: root('packages', 'style'), loader: 'raw-loader!postcss-loader!sass-loader'}, // support for .html as raw text // todo: change the loader to something that adds a hash to images - {test: /\.html$/, loader: 'raw-loader', exclude: root('src', 'public')} + {test: /\.html$/, loader: 'raw-loader', exclude: root('packages', 'public')} ] }; @@ -137,7 +137,7 @@ module.exports = function makeWebpackConfig() { new webpack.ContextReplacementPlugin( // The (\\|\/) piece accounts for path separators in *nix and Windows /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/, - root('./src') // location of your src + root('./packages') // location of your src ) ]; @@ -147,7 +147,7 @@ module.exports = function makeWebpackConfig() { * Reference: http://webpack.github.io/docs/webpack-dev-server.html */ config.devServer = { - contentBase: './src/public', + contentBase: './packages/public', historyApiFallback: true, quiet: true, stats: 'minimal' // none (or false), errors-only, minimal, normal (or true) and verbose