Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 41 additions & 36 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
let gulp = require('gulp'),
const gulp = require('gulp'),
childProcess = require('child_process'),
_ = require('lodash'),
uglify = require('gulp-uglify-es').default,
rename = require('gulp-rename'),
jsonEditor = require('gulp-json-editor'),
fs = require('fs'),
sass = require('gulp-sass');

let packageJson = JSON.parse(fs.readFileSync('./package.json')),
sass = require('gulp-sass'),
path = require('path'),
ngPackagr = require('ng-packagr'),
ngPackagePath = path.normalize(path.join(__dirname, './ng-package.json')),
tsConfigPath = path.normalize(path.join(__dirname, './tsconfig.dist.json')),
packageConfig = JSON.parse(fs.readFileSync('./package.json')),
paths = {
gulp: 'node_modules/gulp/bin/gulp.js',
ngPackagr: 'node_modules/ng-packagr/cli/main.js',
Expand All @@ -16,35 +19,33 @@ let packageJson = JSON.parse(fs.readFileSync('./package.json')),
root: 'images/'
},
src: {
css: `src/app/components/${packageJson.name}/${packageJson.name}.component.scss`
css: `src/app/components/${packageConfig.name}/${packageConfig.name}.component.scss`
},
dist: {
root: 'dist/',
package: 'dist/package.json',
bundles: {
root: 'dist/bundles/',
file: `dist/bundles/${packageJson.name}.umd.js`,
mapFile: `dist/bundles/${packageJson.name}.umd.js.map`,
minFile: `${packageJson.name}.umd.min.js`
file: `dist/bundles/${packageConfig.name}.umd.js`,
mapFile: `dist/bundles/${packageConfig.name}.umd.js.map`,
minFile: `${packageConfig.name}.umd.min.js`
},
esm5: {
root: 'dist/esm5/',
file: `dist/esm5/${packageJson.name}.js`,
minFile: `${packageJson.name}.min.js`
file: `dist/esm5/${packageConfig.name}.js`,
minFile: `${packageConfig.name}.min.js`
},
esm2015: {
root: 'dist/esm2015/',
file: `dist/esm2015/${packageJson.name}.js`,
minFile: `${packageJson.name}.min.js`
file: `dist/esm2015/${packageConfig.name}.js`,
minFile: `${packageConfig.name}.min.js`
}
}
};

function executeCommand(command, parameters) {
if (command === 'gulp') {
command = paths.gulp;
} else if (command === 'ng-packagr') {
command = paths.ngPackagr;
} else if (command === 'ionic') {
command = paths.ionic;
}
Expand All @@ -55,13 +56,13 @@ function executeCommand(command, parameters) {
childProcess.spawnSync('node', _parameters, { stdio: 'inherit' });
}

function copyCss() {
async function copyCss() {
return Promise.all([
new Promise(function (resolve, reject) {
// Copy original SCSS file to "module" folder from package.json.
// That's where Ionic will be looking for it.
fs.createReadStream(paths.src.css).pipe(
fs.createWriteStream(`${paths.dist.esm5.root}${packageJson.name}.component.scss`)
fs.createWriteStream(`${paths.dist.esm5.root}${packageConfig.name}.component.scss`)
.on('error', reject)
.on('close', resolve)
);
Expand All @@ -73,15 +74,15 @@ function copyCss() {
.pipe(sass({
outputStyle: 'compressed'
}))
.pipe(rename(`${packageJson.name}.component.min.css`))
.pipe(rename(`${packageConfig.name}.component.min.css`))
.pipe(gulp.dest(paths.dist.esm5.root))
.on('error', reject)
.on('end', resolve);
})
]);
}

function copyImages() {
async function copyImages() {
return new Promise(function (resolve, reject) {
gulp.src(`${paths.images.root}**/*`)
.pipe(gulp.dest(`${paths.dist.root}${paths.images.root}`))
Expand All @@ -90,7 +91,7 @@ function copyImages() {
});
}

function minifyJS() {
async function minifyJS() {
// Minify files.
return Promise.all([
new Promise(function (resolve, reject) {
Expand Down Expand Up @@ -120,7 +121,7 @@ function minifyJS() {
});
}

function modifyPackageJson() {
async function modifyPackageJson() {
return new Promise(function (resolve, reject) {
gulp.src(paths.dist.package)
.pipe(jsonEditor(function (json) {
Expand All @@ -138,23 +139,27 @@ function modifyPackageJson() {
});
}

gulp.task('heroku', function () {
executeCommand('ionic', ['build', '--minifyjs', '--minifycss', '--optimizejs']);
});
async function build() {
await ngPackagr
.ngPackagr()
.forProject(ngPackagePath)
.withTsConfig(tsConfigPath)
.build()
.catch(error => {
console.error(error);
process.exit(1);
});
await minifyJS();
await modifyPackageJson();
await copyCss();
await copyImages();

gulp.task('build', function () {
executeCommand('ng-packagr', ['-p', 'ng-package.json']);
// Remove archive created by ng-packagr.
fs.unlinkSync('dist.tgz');
}

minifyJS().then(function () {
modifyPackageJson().then(function () {
copyCss().then(function () {
copyImages().then(function () {
// Remove archive created by ng-packagr.
fs.unlinkSync('dist.tgz');
});
});
});
});
gulp.task('heroku', function () {
executeCommand('ionic', ['build', '--minifyjs', '--minifycss', '--optimizejs']);
});

gulp.task('build', build);
gulp.task('default', ['build']);
3 changes: 1 addition & 2 deletions ionic-selectable.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}
],
"settings": {
"editor.formatOnSave": true,
"editor.formatOnSave": false,
"editor.wordWrap": "on",
"editor.detectIndentation": false,
"search.exclude": {
Expand All @@ -21,7 +21,6 @@
"source.organizeImports": true
}
},
"beautify.tabSize": 2,
"editor.tabSize": 2
}
}
Loading