Skip to content

Commit

Permalink
feat(publishing): remove unnecessary files from npm package & reduce …
Browse files Browse the repository at this point in the history
…library peer dependencies
  • Loading branch information
tinesoft committed Dec 28, 2016
1 parent a2bd83b commit 56704da
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 13 deletions.
60 changes: 58 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ const cssnano = require('cssnano');
const scss = require('postcss-scss');
const stripInlineComments = require('postcss-strip-inline-comments');

/** External command runner */
const exec = require('child_process').exec;

/** File Access */
const fs = require('fs');
const file = require('gulp-file');


const LIBRARY_NAME = 'ng2-sharebuttons';

const tsProject = typescript.createProject('tsconfig.json');

Expand Down Expand Up @@ -117,5 +126,52 @@ gulp.task('watch', function() {
gulp.watch([config.allSass, config.allHtml], ['styles']);
});

gulp.task('default', ['ts-lint', 'compile-ts']);
gulp.task('default', ['compile-ts']);
/** Npm Packaging Task */
gulp.task('npm', function () {
var pkgJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
var targetPkgJson = {};
var fieldsToCopy = ['version', 'description', 'keywords', 'author', 'repository', 'license', 'bugs', 'homepage'];

targetPkgJson['name'] = LIBRARY_NAME;

//only copy needed properties from project's package json
fieldsToCopy.forEach(function (field) { targetPkgJson[field] = pkgJson[field]; });

targetPkgJson['main'] = `index.js`;
targetPkgJson['module'] = 'index.js';
targetPkgJson['typings'] = 'index.d.ts';

// defines project's dependencies as 'peerDependencies' for final users
targetPkgJson.peerDependencies = {};
Object.keys(pkgJson.dependencies).forEach(function (dependency) {
targetPkgJson.peerDependencies[dependency] = `^${pkgJson.dependencies[dependency]}`;
});

// copy the needed additional files in the 'dist' folder
return gulp.src(['README.md', 'LICENSE', 'CHANGELOG.md'])
.pipe(file('package.json', JSON.stringify(targetPkgJson, null, 2)))
.pipe(gulp.dest('dist/'));
});

gulp.task('compile', ['ts-lint', 'compile-ts']);

/** Npm Publication Task */
gulp.task('publish', [ 'compile', 'npm'], function (done) {
// run npm publish terminal command to publish the 'dist' folder only
exec('npm publish ./dist',
function (error, stdout, stderr) {
if (stderr) {
gutil.log(gutil.colors.red(stderr));
} else if (stdout) {
gutil.log(gutil.colors.green(stdout));
}
// execute callback when its done
if (done) {
done();
}
}
);
});


gulp.task('default', ['compile']);
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,22 @@
"start": "gulp",
"prepublish": "gulp"
},
"peerDependencies": {
"@angular/common": "^2.2.4",
"@angular/compiler": "^2.2.4",
"@angular/core": "^2.2.4",
"@angular/http": "^2.2.4",
"@angular/platform-browser": "^2.2.4",
"@angular/router": "^3.2.4",
"core-js": "^2.4.1",
"rxjs": "^5.0.0-beta.12",
"zone.js": "^0.6.17"
"dependencies": {
"@angular/common": "2.0.0",
"@angular/core": "2.0.0",
"@angular/http": "2.0.0"
},
"devDependencies": {
"@angular/compiler": "2.0.0",
"@angular/platform-browser": "2.0.0",
"@angular/router": "3.0.0",
"angular2-template-loader": "^0.5.0",
"autoprefixer": "^6.4.0",
"core-js": "2.4.1",
"cssnano": "^3.7.4",
"del": "^2.2.2",
"gulp": "^3.9.1",
"gulp-file": "^0.3.0",
"gulp-inline-ng2-template": "^3.0.0",
"gulp-postcss": "^6.1.1",
"gulp-sass": "^2.3.2",
Expand All @@ -59,7 +58,9 @@
"merge2": "^1.0.2",
"postcss-scss": "^0.3.0",
"postcss-strip-inline-comments": "^0.1.5",
"rxjs": "5.0.0-beta.12",
"tslint": "^3.15.1",
"typings": "^1.3.3"
"typings": "^1.3.3",
"zone.js": "0.6.21"
}
}

0 comments on commit 56704da

Please sign in to comment.