Removed local gulp
This commit is contained in:
parent
19eb67763c
commit
d2f97eaed0
22
gulp/LICENSE
22
gulp/LICENSE
@ -1,22 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Linus Miller
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
@ -1,23 +0,0 @@
|
||||
# gulp
|
||||
|
||||
## Tasks
|
||||
|
||||
### browserify.js
|
||||
|
||||
### browser-sync.js
|
||||
|
||||
### fonts.js
|
||||
|
||||
### nodemon.js
|
||||
|
||||
### raster.js
|
||||
|
||||
### sass.js
|
||||
|
||||
### static.js
|
||||
|
||||
### svg.js
|
||||
|
||||
### watch.js
|
||||
|
||||
### wipe.js
|
||||
121
gulp/config.js
121
gulp/config.js
@ -1,121 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const p = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
const port = fs.existsSync(p.join(PWD, 'server/config/port.js')) ?
|
||||
require(p.join(PWD, 'server/config/port')) : 10000
|
||||
|
||||
module.exports = {
|
||||
browserSync: {
|
||||
browser: null,
|
||||
ghostMode: false,
|
||||
proxy: 'localhost:' + port,
|
||||
port: 1337,
|
||||
ui: {
|
||||
port: 1338
|
||||
},
|
||||
files: [
|
||||
p.join(PWD, 'public/css/**/*.css'),
|
||||
p.join(PWD, 'public/js/**/*.js'),
|
||||
]
|
||||
},
|
||||
|
||||
browserify: {
|
||||
suffix: true,
|
||||
debug: true,
|
||||
dest: p.join(PWD, 'public/js'),
|
||||
extensions: [ '.js', '.jsx', '.json' ],
|
||||
// PWD/node_modules is added so symlinked ridge does not break. used to
|
||||
// work without this in browserify 9
|
||||
paths: [ p.join(PWD, 'node_modules'), p.join(PWD, 'modules') ],
|
||||
// outputs only need to be used if output names are different from entries.
|
||||
// Otherwise the entries array is copied into the outputs array.
|
||||
entries: [
|
||||
'src/app.js'
|
||||
],
|
||||
src: p.join(PWD, 'src')
|
||||
},
|
||||
|
||||
less: {
|
||||
suffix: true,
|
||||
src: [
|
||||
p.join(PWD, 'less/*.less'),
|
||||
],
|
||||
dest: p.join(PWD, 'public/css'),
|
||||
autoprefixer: {
|
||||
browsers: [
|
||||
'safari >= 5',
|
||||
'ie >= 8',
|
||||
'ios >= 6',
|
||||
'opera >= 12.1',
|
||||
'firefox >= 17',
|
||||
'chrome >= 30',
|
||||
'android >= 4'
|
||||
],
|
||||
cascade: true
|
||||
},
|
||||
functions: require('./less/functions'),
|
||||
options: {
|
||||
paths: [
|
||||
p.join(PWD, 'node_modules/spineless/less')
|
||||
],
|
||||
}
|
||||
},
|
||||
|
||||
nodemon: {
|
||||
ext: 'js, marko',
|
||||
watch: [
|
||||
'server',
|
||||
'src',
|
||||
],
|
||||
ignore: [
|
||||
'*.marko.js',
|
||||
// only watch marko files in src folders.
|
||||
'src/**/*.js'
|
||||
],
|
||||
script: fs.existsSync(p.join(PWD, 'package.json')) ? require(p.join(PWD, 'package.json')).main.replace(/^\./, PWD) : 'server/server.js',
|
||||
env: {
|
||||
BABEL_ENV: 'server',
|
||||
// what port you actually put into the browser... when using browser-sync
|
||||
// this will differ from the internal port used by express
|
||||
EXTERNAL_PORT: 1337,
|
||||
// needed to force debug to use colors despite tty.istty(0) being false,
|
||||
// which it is in a child process
|
||||
DEBUG_COLORS: true,
|
||||
// needed to force chalk to use when running gulp nodemon tasks.
|
||||
FORCE_COLOR: true,
|
||||
PWD,
|
||||
NODE_ENV: ENV,
|
||||
DEBUG: 'mypaper:*'
|
||||
}
|
||||
},
|
||||
|
||||
raster: {
|
||||
src: p.join(PWD, 'img/raster/**/*.{png,gif,jpg}'),
|
||||
dest: p.join(PWD, 'public/img')
|
||||
},
|
||||
|
||||
static: {
|
||||
src: p.join(PWD, 'static/**/*'),
|
||||
dest: p.join(PWD, 'public')
|
||||
},
|
||||
|
||||
svg: {
|
||||
src: p.join(PWD, 'img/svg/**/*.svg'),
|
||||
dest: p.join(PWD, 'public/img')
|
||||
},
|
||||
|
||||
tasks: {
|
||||
development: [ 'wipe', [ 'browserify', 'less', 'raster', 'static', 'svg' ], [ 'nodemon' ], [ 'watch', 'browser-sync' ] ],
|
||||
production: [ 'wipe', [ 'browserify', 'less', 'raster', 'static', 'svg' ]]
|
||||
}[ENV],
|
||||
|
||||
watch: {
|
||||
less: p.join(PWD, 'less/**/*.less')
|
||||
},
|
||||
|
||||
wipe: {
|
||||
src: [ p.join(PWD, 'public') ]
|
||||
}
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
// modules > 3rd party
|
||||
const _ = require('lodash')
|
||||
|
||||
// modules > gulp
|
||||
const gulp = require('gulp')
|
||||
|
||||
global.ENV = process.env.NODE_ENV || 'development'
|
||||
global.PWD = process.env.PWD
|
||||
|
||||
const args = process.argv.slice(2)
|
||||
|
||||
// use tasks from arguments list if present, otherwise use tasks from
|
||||
// configuration (environment specific)
|
||||
let tasks = args.length > 0 ? args : require('./config').tasks
|
||||
|
||||
// only require used tasks
|
||||
_.flatten(tasks, true).forEach((task) => require('./tasks/' + task))
|
||||
|
||||
tasks = tasks.map((task) => {
|
||||
if (Array.isArray(task)) {
|
||||
return gulp.parallel(...task)
|
||||
}
|
||||
|
||||
return task
|
||||
})
|
||||
|
||||
// set up the 'default' task to use runSequence to run all tasks
|
||||
gulp.task('default', gulp.series(...tasks))
|
||||
@ -1,42 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const p = require('path')
|
||||
|
||||
module.exports = {
|
||||
'img-url': function (value) {
|
||||
const tree = this.context.pluginManager.less.tree
|
||||
|
||||
return new tree.URL(new tree.Quoted('"', p.join('/img', value.value)), this.index, this.currentFileInfo)
|
||||
},
|
||||
|
||||
rem: function (value, context) {
|
||||
const tree = this.context.pluginManager.less.tree
|
||||
|
||||
if (value.type === 'Expression')
|
||||
return new tree.Expression(value.value.map((value) => {
|
||||
if (value.unit.backupUnit === 'px')
|
||||
return new tree.Dimension(value.value / 14, 'rem')
|
||||
|
||||
return new tree.Dimension(value.value, 'rem')
|
||||
}))
|
||||
|
||||
return new tree.Dimension(value.value / 14, 'rem')
|
||||
},
|
||||
|
||||
px: function (value) {
|
||||
const tree = this.context.pluginManager.less.tree
|
||||
|
||||
if (value.type === 'Expression')
|
||||
return new tree.Expression(value.value.map((value) => {
|
||||
if (value.unit.backupUnit === 'px')
|
||||
return value
|
||||
|
||||
return new tree.Dimension(value.value * 14, 'px')
|
||||
}))
|
||||
|
||||
if (value.unit.backupUnit === 'px')
|
||||
return value
|
||||
|
||||
return new tree.Dimension(value.value * 14, 'px')
|
||||
}
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const gulp = require('gulp')
|
||||
const browserSync = require('browser-sync')
|
||||
|
||||
const TASK_NAME = 'browser-sync'
|
||||
const config = require('../config').browserSync
|
||||
|
||||
gulp.task(TASK_NAME, () => browserSync(config))
|
||||
@ -1,126 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
// native modules
|
||||
const p = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
// 3rd party modules
|
||||
const _ = require('lodash')
|
||||
const browserify = require('browserify')
|
||||
const buffer = require('vinyl-buffer')
|
||||
const chalk = require('chalk')
|
||||
const es = require('event-stream')
|
||||
const gulp = require('gulp')
|
||||
const gutil = require('gulp-util')
|
||||
const rename = require('gulp-rename')
|
||||
const source = require('vinyl-source-stream')
|
||||
const sourcemaps = require('gulp-sourcemaps')
|
||||
const uglify = require('gulp-uglify')
|
||||
const watchify = require('watchify')
|
||||
const babelify = require('babelify')
|
||||
const markoify = require('markoify')
|
||||
|
||||
require('marko/compiler').defaultOptions.writeToDisk = false
|
||||
|
||||
process.env.BABEL_ENV = 'client'
|
||||
|
||||
const config = require('../config').browserify
|
||||
const suffix = config.suffix && ENV === 'production' ? '-' + Date.now().toString(16) : ''
|
||||
|
||||
const errorHandler = require('../util/error-handler')
|
||||
|
||||
function formatError(err) {
|
||||
err.task = 'browserify'
|
||||
|
||||
const matchFileName = err.message.match(/\/[^\s:]*/)
|
||||
|
||||
if (matchFileName) {
|
||||
let fileName = matchFileName[0]
|
||||
|
||||
if (fileName.indexOf(PWD) > -1)
|
||||
fileName = './' + p.relative(PWD, fileName)
|
||||
|
||||
fileName = chalk.yellow(fileName)
|
||||
|
||||
const matchNumbers = err.message.match(/ \((.*)\)/)
|
||||
|
||||
if (matchNumbers) {
|
||||
const arr = matchNumbers[1].split(':')
|
||||
|
||||
err.message = err.message.slice(0, matchNumbers.index) +
|
||||
' at line ' + arr[0] + ', col ' + arr[1]
|
||||
}
|
||||
|
||||
err.message = err.message.split(matchFileName[0]).join(fileName)
|
||||
}
|
||||
|
||||
err.message = err.message.split(/:\s*/).join('\n')
|
||||
|
||||
errorHandler.call(this, err)
|
||||
}
|
||||
|
||||
if (typeof config.entries === 'string') config.entries = [config.entries]
|
||||
|
||||
const TASK_NAME = 'browserify'
|
||||
gulp.task(TASK_NAME, (cb) => {
|
||||
cb = _.after(config.entries.length, cb)
|
||||
|
||||
if (config.suffix)
|
||||
fs.writeFileSync(config.dest + '.json', JSON.stringify({ suffix }))
|
||||
|
||||
const tasks = config.entries.map((entry, index) => {
|
||||
function bundler(bundle) {
|
||||
let outputPath = config.outputs && config.outputs[index] || entry
|
||||
|
||||
let pipe = bundle.bundle()
|
||||
.on('error', formatError)
|
||||
.pipe(source(outputPath))
|
||||
.pipe(rename((path) => {
|
||||
if (outputPath === entry) {
|
||||
// remove first level of directores, eg `src/` or `src-widget/`
|
||||
path.dirname = path.dirname.replace(/^src[^\/]*\/?/, '')
|
||||
|
||||
outputPath = path.dirname + path.basename + (path.suffix || '') + path.extname
|
||||
}
|
||||
|
||||
path.basename += suffix
|
||||
|
||||
return path
|
||||
}))
|
||||
.on('end', (...args) => {
|
||||
gutil.log(chalk.cyan(TASK_NAME) + ' wrote ' + chalk.magenta(outputPath) + '.')
|
||||
|
||||
cb()
|
||||
})
|
||||
|
||||
if (ENV !== 'development')
|
||||
pipe = pipe.pipe(buffer())
|
||||
.pipe(sourcemaps.init({ loadMaps: true }))
|
||||
.pipe(uglify())
|
||||
.pipe(sourcemaps.write('./'))
|
||||
|
||||
return pipe.pipe(gulp.dest(config.dest))
|
||||
}
|
||||
|
||||
const bundle = browserify(_.defaults({
|
||||
entries: [ entry ],
|
||||
cache: {},
|
||||
packageCache: {}
|
||||
}, config))
|
||||
|
||||
if (ENV !== 'production')
|
||||
bundle.plugin(watchify, {
|
||||
ignoreWatch: [ '/public/**', '**/node_modules/**', '**/bower_components/**']
|
||||
})
|
||||
|
||||
bundle.transform(babelify)
|
||||
bundle.transform(markoify)
|
||||
|
||||
bundle.on('update', () => bundler(bundle))
|
||||
|
||||
return bundler(bundle)
|
||||
})
|
||||
|
||||
// return a single stream from all bundle streams
|
||||
return es.merge.apply(null, tasks)
|
||||
})
|
||||
@ -1,49 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const gulp = require('gulp')
|
||||
const _less = require('less')
|
||||
const less = require('gulp-less')
|
||||
const sourcemaps = require('gulp-sourcemaps')
|
||||
const rename = require('gulp-rename')
|
||||
const mkdirp = require('mkdirp')
|
||||
|
||||
const postcss = require('gulp-postcss')
|
||||
const autoprefixer = require('autoprefixer')
|
||||
|
||||
const config = require('../config').less
|
||||
|
||||
|
||||
const errorHandler = require('../util/error-handler')
|
||||
|
||||
_less.functions.functionRegistry.addMultiple(config.functions)
|
||||
|
||||
const processors = [
|
||||
autoprefixer(config.autoprefixer),
|
||||
]
|
||||
|
||||
if (ENV === 'production') {
|
||||
const csswring = require('csswring')
|
||||
|
||||
processors.push(csswring(config.csswring))
|
||||
}
|
||||
|
||||
const suffix = config.suffix && ENV === 'production' ? '-' + Date.now().toString(16) : undefined
|
||||
|
||||
gulp.task('less', function () {
|
||||
mkdirp(config.dest)
|
||||
|
||||
if (suffix)
|
||||
fs.writeFile(config.dest + '.json', JSON.stringify({ suffix }))
|
||||
|
||||
let pipe = gulp.src(config.src)
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(less(config.options).on('error', errorHandler))
|
||||
.pipe(postcss(processors))
|
||||
|
||||
if (suffix)
|
||||
pipe = pipe.pipe(rename({ suffix }))
|
||||
|
||||
return pipe.pipe(sourcemaps.write('./maps'))
|
||||
.pipe(gulp.dest(config.dest))
|
||||
})
|
||||
@ -1,35 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const _ = require('lodash')
|
||||
|
||||
const gulp = require('gulp')
|
||||
const browserSync = require('browser-sync')
|
||||
const nodemon = require('nodemon')
|
||||
|
||||
const config = require('../config').nodemon
|
||||
|
||||
// for some reason, this was needed somewhere before
|
||||
//process.stdout.isTTY = true
|
||||
|
||||
gulp.task('nodemon', (cb) => {
|
||||
nodemon(_.defaults({ stdout: false }, config))
|
||||
.on('log', function (log) {
|
||||
console.log(log.colour)
|
||||
})
|
||||
.on('readable', function () {
|
||||
this.stdout.pipe(process.stdout)
|
||||
this.stderr.pipe(process.stderr)
|
||||
|
||||
this.stdout.on('data', (chunk) => {
|
||||
if (/HTTP server (running|listening|started) on|at port/i.test(chunk.toString('utf-8').trim())) {
|
||||
if (cb)
|
||||
cb()
|
||||
|
||||
cb = null
|
||||
|
||||
if (browserSync.active)
|
||||
browserSync.reload()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -1,27 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
// modules > native
|
||||
const p = require('path')
|
||||
|
||||
// modules > 3rd party
|
||||
const chalk = require('chalk')
|
||||
|
||||
// modules > gulp:utilities
|
||||
const gulp = require('gulp')
|
||||
const gutil = require('gulp-util')
|
||||
|
||||
const TASK_NAME = 'raster'
|
||||
const config = require('../config').raster
|
||||
|
||||
gulp.task(TASK_NAME, () => {
|
||||
let count = 0
|
||||
|
||||
return gulp.src(config.src)
|
||||
.pipe(gulp.symlink((file) => {
|
||||
count++
|
||||
return p.join(config.dest)
|
||||
}, { log: false }))
|
||||
.on('end', () => {
|
||||
gutil.log(chalk.cyan(TASK_NAME) + ' done symlinking ' + chalk.bold.blue(count) + ' files')
|
||||
})
|
||||
})
|
||||
@ -1,39 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
// modules > native
|
||||
const p = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
// modules > 3rd party
|
||||
const chalk = require('chalk')
|
||||
|
||||
// modules > gulp:utilities
|
||||
const gulp = require('gulp')
|
||||
const through = require('through2')
|
||||
const gutil = require('gulp-util')
|
||||
|
||||
const TASK_NAME = 'static'
|
||||
const config = require('../config').static
|
||||
|
||||
gulp.task(TASK_NAME, () => {
|
||||
let count = 0
|
||||
|
||||
return gulp.src(config.src)
|
||||
// we use through so that we can skip directories
|
||||
// we skip directories because we want to merge file structure
|
||||
.pipe(through.obj((file, enc, callback) => {
|
||||
fs.stat(file.path, (err, stats) => {
|
||||
if (stats.isDirectory())
|
||||
file = null
|
||||
|
||||
callback(null, file)
|
||||
})
|
||||
}))
|
||||
.pipe(gulp.symlink((file) => {
|
||||
count++
|
||||
return p.join(config.dest)
|
||||
}))
|
||||
.on('end', () => {
|
||||
gutil.log(chalk.cyan(TASK_NAME) + ' done symlinking ' + chalk.bold.blue(count) + ' files')
|
||||
})
|
||||
})
|
||||
@ -1,27 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
// modules > native
|
||||
const p = require('path')
|
||||
|
||||
// modules > 3rd party
|
||||
const chalk = require('chalk')
|
||||
|
||||
// modules > gulp:utilities
|
||||
const gulp = require('gulp')
|
||||
const gutil = require('gulp-util')
|
||||
|
||||
const TASK_NAME = 'svg'
|
||||
const config = require('../config').svg
|
||||
|
||||
gulp.task(TASK_NAME, () => {
|
||||
let count = 0
|
||||
|
||||
return gulp.src(config.src)
|
||||
.pipe(gulp.symlink((file) => {
|
||||
count++
|
||||
return p.join(config.dest)
|
||||
}))
|
||||
.on('end', () => {
|
||||
gutil.log(chalk.cyan(TASK_NAME) + ' done symlinking ' + chalk.bold.blue(count) + ' files')
|
||||
})
|
||||
})
|
||||
@ -1,16 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
// modules > 3rd party
|
||||
const _ = require('lodash')
|
||||
|
||||
// modules > gulp:utilities
|
||||
const gulp = require('gulp')
|
||||
|
||||
const TASK_NAME = 'watch'
|
||||
const config = require('../config').watch
|
||||
|
||||
gulp.task(TASK_NAME, () => {
|
||||
_.forIn(config, (value, key) => {
|
||||
gulp.watch(value, gulp.series(key))
|
||||
})
|
||||
})
|
||||
@ -1,44 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
// native modules
|
||||
const fs = require('fs')
|
||||
|
||||
// 3rd party modules
|
||||
const mkdirp = require('mkdirp')
|
||||
const chalk = require('chalk')
|
||||
const gulp = require('gulp')
|
||||
const gutil = require('gulp-util')
|
||||
const rimraf = require('rimraf')
|
||||
|
||||
const TASK_NAME = 'wipe'
|
||||
|
||||
const config = require('../config').wipe
|
||||
|
||||
gulp.task(TASK_NAME, (cb) => {
|
||||
let count = 0
|
||||
config.src.forEach((folder) => {
|
||||
fs.exists(folder, (exists) => {
|
||||
if (exists) {
|
||||
rimraf(folder, (err) => {
|
||||
if (err) throw err
|
||||
gutil.log('Folder ' + chalk.magenta(folder) + ' removed')
|
||||
|
||||
mkdirp.sync(folder)
|
||||
|
||||
count++
|
||||
if (count >= config.src.length) {
|
||||
cb()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
count++
|
||||
|
||||
mkdirp.sync(folder)
|
||||
|
||||
if (count >= config.src.length) {
|
||||
cb()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -1,16 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const util = require('gulp-util')
|
||||
const chalk = require('chalk')
|
||||
|
||||
module.exports = function (err) {
|
||||
util.log(chalk.red('ERROR') + (err.task ? ' in task \'' + chalk.cyan(err.task) : ' in plugin \'' + chalk.cyan(err.plugin)) + '\'')
|
||||
|
||||
console.log('\n' + err.message.trim() + '\n')
|
||||
|
||||
// needed for error handling not thrown by gulp-watch
|
||||
if (this.emit) {
|
||||
// Keep gulp from hanging on this task
|
||||
this.emit('end')
|
||||
}
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
require('./gulp');
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
process.exit(0);
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user