Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #19 from farism/browsersync
Browse files Browse the repository at this point in the history
More improvements
  • Loading branch information
farism authored Aug 31, 2017
2 parents 7d3d315 + c0de7e2 commit bc2b7db
Show file tree
Hide file tree
Showing 15 changed files with 1,467 additions and 796 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ sudo: false

os:
- linux
- osx

env:
matrix:
Expand Down
1 change: 0 additions & 1 deletion bin/cmds/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ module.exports = {
},
handler: function(argv) {
require('../../src/tasks').build(argv)
gulp.start('build')
},
}
1 change: 0 additions & 1 deletion bin/cmds/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ module.exports = {
},
handler: function(argv) {
require('../../src/tasks').dev(argv)
gulp.start('dev')
},
}
1 change: 0 additions & 1 deletion bin/cmds/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ module.exports = {
},
handler: function(argv) {
require('../../src/tasks').init(argv)
gulp.start('init')
},
}
15 changes: 15 additions & 0 deletions elm-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "1.0.0",
"summary": "helpful summary of your project, less than 80 characters",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"."
],
"exposed-modules": [],
"dependencies": {
"elm-lang/core": "5.1.1 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0"
},
"elm-version": "0.18.0 <= v < 0.19.0"
}
15 changes: 5 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,30 @@
"test": "nyc --reporter=html --reporter=text mocha"
},
"dependencies": {
"connect-livereload": "^0.6.0",
"browser-sync": "^2.18.13",
"cssnano": "^3.10.0",
"del": "^3.0.0",
"elm-css": "^0.6.1",
"execa": "^0.8.0",
"express": "^4.15.2",
"find-elm-dependencies": "^1.0.1",
"find-up": "^2.1.0",
"fkill": "^5.0.0",
"glob-promise": "^3.1.0",
"gulp": "^3.9.1",
"gulp-any-template": "^0.3.1",
"gulp-debug": "^3.1.0",
"gulp-elm": "^0.7.2",
"gulp-elm-basic": "^0.1.0",
"gulp-elm-css": "^0.1.0",
"gulp-elm-extract-assets": "^0.1.0",
"gulp-elm-find-dependencies": "^0.1.0",
"gulp-filter": "^5.0.1",
"gulp-flatten": "^0.3.1",
"gulp-if": "^2.0.2",
"gulp-plumber": "^1.1.0",
"gulp-postcss": "^7.0.0",
"gulp-rename": "^1.2.2",
"gulp-rev-all": "^0.9.7",
"gulp-through": "^0.4.0",
"gulp-uglify": "^3.0.0",
"hook-std": "^0.4.0",
"http-proxy-middleware": "^0.17.4",
"nocache": "^2.0.0",
"postcss": "^6.0.9",
"ora": "^1.3.0",
"postcss-url": "^7.1.2",
"run-sequence": "^2.1.0",
"tiny-lr": "^1.0.5",
Expand All @@ -67,7 +63,6 @@
"chai": "^4.1.1",
"chai-as-promised": "^7.1.1",
"chai-fs": "^1.0.0",
"chokidar": "^1.7.0",
"coveralls": "^2.13.1",
"husky": "^0.14.3",
"lint-staged": "^4.0.4",
Expand Down
148 changes: 74 additions & 74 deletions src/tasks/build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const cssnano = require('cssnano')
const del = require('del')
const elm = require('gulp-elm')
const elm = require('gulp-elm-basic')
const elmCss = require('gulp-elm-css')
const elmExtractAssets = require('gulp-elm-extract-assets')
const flatten = require('gulp-flatten')
Expand All @@ -10,7 +10,6 @@ const path = require('path')
const postcss = require('gulp-postcss')
const postcssUrl = require('postcss-url')
const rev = require('gulp-rev-all')
const runSequence = require('run-sequence')
const uglify = require('gulp-uglify')
const urljoin = require('url-join')
const xxh = require('xxhashjs')
Expand Down Expand Up @@ -40,35 +39,39 @@ const buildCss = (
minify = true,
cwd = process.cwd()
) =>
gulp
.src(stylesheets, { base: cwd })
.pipe(elmCss({ cwd }))
.pipe(
postcss([
postcssUrl({
url: 'copy',
basePath: process.cwd(),
assetsPath: outputPath,
useHash: true,
hashOptions: {
method: getHash,
},
}),
postcssUrl({
url: asset => getPublicPath(publicPath, asset.url),
}),
minify ? cssnano() : contents => contents,
])
)
.pipe(
rev.revision({
fileNameManifest: 'css-manifest.json',
transformFilename: getTransformedFilename,
})
)
.pipe(gulp.dest(outputPath))
.pipe(rev.manifestFile())
.pipe(gulp.dest(outputPath))
new Promise((resolve, reject) => {
gulp
.src(stylesheets, { base: cwd })
.pipe(elmCss({ cwd }))
.pipe(
postcss([
postcssUrl({
url: 'copy',
basePath: process.cwd(),
assetsPath: outputPath,
useHash: true,
hashOptions: {
method: getHash,
},
}),
postcssUrl({
url: asset => getPublicPath(publicPath, asset.url),
}),
minify ? cssnano() : contents => contents,
])
)
.pipe(
rev.revision({
fileNameManifest: 'css-manifest.json',
transformFilename: getTransformedFilename,
})
)
.pipe(gulp.dest(outputPath))
.pipe(rev.manifestFile())
.pipe(gulp.dest(outputPath))
.on('error', reject)
.on('finish', resolve)
})

const buildMain = (
main,
Expand All @@ -77,52 +80,49 @@ const buildMain = (
minify = true,
cwd = process.cwd()
) =>
gulp
.src(main)
.pipe(elm({ cwd }))
.pipe(elmExtractAssets({ cwd, tag: 'AssetUrl' }))
.pipe(
rev.revision({
dontUpdateReference: ['Main.js'],
fileNameManifest: 'js-manifest.json',
replacer: (fragment, replaceRegExp, newReference, referencedFile) => {
const filename = newReference.split('/').pop()
const newPath = getPublicPath(publicPath, filename)
new Promise((resolve, reject) => {
gulp
.src(main)
.pipe(elm({ cwd }))
.pipe(elmExtractAssets({ cwd, tag: 'AssetUrl' }))
.pipe(
rev.revision({
dontUpdateReference: [path.basename(main).replace('.elm', '.js')],
fileNameManifest: 'js-manifest.json',
replacer: (fragment, replaceRegExp, newReference, referencedFile) => {
const filename = newReference.split('/').pop()
const newPath = getPublicPath(publicPath, filename)

fragment.contents = fragment.contents.replace(
replaceRegExp,
`$1${newPath}$3$4`
)
},
transformFilename: getTransformedFilename,
})
)
.pipe(flatten())
.pipe(gulpif(file => minify && path.extname(file.path) === '.js', uglify()))
.pipe(gulp.dest(outputPath))
.pipe(rev.manifestFile())
.pipe(gulp.dest(outputPath))
fragment.contents = fragment.contents.replace(
replaceRegExp,
`$1${newPath}$3$4`
)
},
transformFilename: getTransformedFilename,
})
)
.pipe(flatten())
.pipe(
gulpif(file => minify && path.extname(file.path) === '.js', uglify())
)
.pipe(gulp.dest(outputPath))
.pipe(rev.manifestFile())
.pipe(gulp.dest(outputPath))
.on('error', reject)
.on('finish', resolve)
})

const task = options => {
const build = options => {
const opts = Object.assign({}, defaults, options)

/* istanbul ignore next */
gulp.task('_clean', () => del(opts.outputPath))

/* istanbul ignore next */
gulp.task('_css', () =>
buildCss(opts.stylesheets, opts.outputPath, opts.publicPath, opts.cwd)
)

/* istanbul ignore next */
gulp.task('_main', () =>
buildMain(opts.main, opts.outputPath, opts.publicPath, opts.cwd)
)

/* istanbul ignore next */
gulp.task('build', () => runSequence('_clean', '_css', '_main'))

return gulp
return del(opts.outputPath)
.then(() =>
buildCss(opts.stylesheets, opts.outputPath, opts.publicPath, opts.cwd)
)
.then(() =>
buildMain(opts.main, opts.outputPath, opts.publicPath, opts.cwd)
)
.catch(console.error)
}

module.exports = {
Expand All @@ -131,5 +131,5 @@ module.exports = {
getTransformedFilename,
buildCss,
buildMain,
task,
build,
}
Loading

0 comments on commit bc2b7db

Please sign in to comment.