Skip to content

Commit

Permalink
refactor: enable to develop multiple packages
Browse files Browse the repository at this point in the history
  • Loading branch information
sebholstein committed Jun 22, 2017
1 parent 2cfb0e7 commit d38d161
Show file tree
Hide file tree
Showing 38 changed files with 35 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion karma-test-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 6 additions & 1 deletion scripts/create-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
9 changes: 6 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"outDir": ".tmp/esm",
"rootDir": ".",
"baseUrl": ".",
"sourceMap": true,
"removeComments": false,
"moduleResolution": "node",
Expand All @@ -17,7 +17,10 @@
],
"types": [
"jasmine"
]
],
"paths": {
"@agm/*": ["./packages/*"]
}
},
"angularCompilerOptions": {
"genDir": ".tmp",
Expand All @@ -28,6 +31,6 @@
".tmp"
],
"include": [
"src/**/*"
"packages/**/*"
]
}
20 changes: 10 additions & 10 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
]
};

Expand All @@ -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
)
];

Expand All @@ -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
Expand Down

0 comments on commit d38d161

Please sign in to comment.