mirror of
https://github.com/twbs/bootstrap.git
synced 2025-01-29 21:52:22 +01:00
build/*.js: ES6-ify files. (#24112)
This commit is contained in:
parent
17fd2c9f84
commit
3bc9402350
@ -11,34 +11,30 @@
|
|||||||
|
|
||||||
/* global Set */
|
/* global Set */
|
||||||
|
|
||||||
var fs = require('fs')
|
const fs = require('fs')
|
||||||
var path = require('path')
|
const path = require('path')
|
||||||
var sh = require('shelljs')
|
const sh = require('shelljs')
|
||||||
sh.config.fatal = true
|
sh.config.fatal = true
|
||||||
var sed = sh.sed
|
const sed = sh.sed
|
||||||
|
|
||||||
// Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37
|
// Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37
|
||||||
RegExp.quote = function (string) {
|
RegExp.quote = (string) => string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&')
|
||||||
return string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&')
|
RegExp.quoteReplacement = (string) => string.replace(/[$]/g, '$$')
|
||||||
}
|
|
||||||
RegExp.quoteReplacement = function (string) {
|
|
||||||
return string.replace(/[$]/g, '$$')
|
|
||||||
}
|
|
||||||
|
|
||||||
var DRY_RUN = false
|
const DRY_RUN = false
|
||||||
|
|
||||||
function walkAsync(directory, excludedDirectories, fileCallback, errback) {
|
function walkAsync(directory, excludedDirectories, fileCallback, errback) {
|
||||||
if (excludedDirectories.has(path.parse(directory).base)) {
|
if (excludedDirectories.has(path.parse(directory).base)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fs.readdir(directory, function (err, names) {
|
fs.readdir(directory, (err, names) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
errback(err)
|
errback(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
names.forEach(function (name) {
|
names.forEach((name) => {
|
||||||
var filepath = path.join(directory, name)
|
const filepath = path.join(directory, name)
|
||||||
fs.lstat(filepath, function (err, stats) {
|
fs.lstat(filepath, (err, stats) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
process.nextTick(errback, err)
|
process.nextTick(errback, err)
|
||||||
return
|
return
|
||||||
@ -60,19 +56,19 @@ function walkAsync(directory, excludedDirectories, fileCallback, errback) {
|
|||||||
function replaceRecursively(directory, excludedDirectories, allowedExtensions, original, replacement) {
|
function replaceRecursively(directory, excludedDirectories, allowedExtensions, original, replacement) {
|
||||||
original = new RegExp(RegExp.quote(original), 'g')
|
original = new RegExp(RegExp.quote(original), 'g')
|
||||||
replacement = RegExp.quoteReplacement(replacement)
|
replacement = RegExp.quoteReplacement(replacement)
|
||||||
var updateFile = !DRY_RUN ? function (filepath) {
|
const updateFile = !DRY_RUN ? (filepath) => {
|
||||||
if (allowedExtensions.has(path.parse(filepath).ext)) {
|
if (allowedExtensions.has(path.parse(filepath).ext)) {
|
||||||
sed('-i', original, replacement, filepath)
|
sed('-i', original, replacement, filepath)
|
||||||
}
|
}
|
||||||
} : function (filepath) {
|
} : (filepath) => {
|
||||||
if (allowedExtensions.has(path.parse(filepath).ext)) {
|
if (allowedExtensions.has(path.parse(filepath).ext)) {
|
||||||
console.log('FILE: ' + filepath)
|
console.log(`FILE: ${filepath}`)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log('EXCLUDED:' + filepath)
|
console.log(`EXCLUDED:${filepath}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
walkAsync(directory, excludedDirectories, updateFile, function (err) {
|
walkAsync(directory, excludedDirectories, updateFile, (err) => {
|
||||||
console.error('ERROR while traversing directory!:')
|
console.error('ERROR while traversing directory!:')
|
||||||
console.error(err)
|
console.error(err)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
@ -85,14 +81,14 @@ function main(args) {
|
|||||||
console.error('Got arguments:', args)
|
console.error('Got arguments:', args)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
var oldVersion = args[0]
|
const oldVersion = args[0]
|
||||||
var newVersion = args[1]
|
const newVersion = args[1]
|
||||||
var EXCLUDED_DIRS = new Set([
|
const EXCLUDED_DIRS = new Set([
|
||||||
'.git',
|
'.git',
|
||||||
'node_modules',
|
'node_modules',
|
||||||
'vendor'
|
'vendor'
|
||||||
])
|
])
|
||||||
var INCLUDED_EXTENSIONS = new Set([
|
const INCLUDED_EXTENSIONS = new Set([
|
||||||
// This extension whitelist is how we avoid modifying binary files
|
// This extension whitelist is how we avoid modifying binary files
|
||||||
'',
|
'',
|
||||||
'.css',
|
'.css',
|
||||||
|
@ -5,8 +5,8 @@ const pkg = require(path.resolve(__dirname, '../package.json'))
|
|||||||
const BUNDLE = process.env.BUNDLE === 'true'
|
const BUNDLE = process.env.BUNDLE === 'true'
|
||||||
const year = new Date().getFullYear()
|
const year = new Date().getFullYear()
|
||||||
|
|
||||||
var fileDest = 'bootstrap.js'
|
let fileDest = 'bootstrap.js'
|
||||||
var external = ['jquery', 'popper.js']
|
const external = ['jquery', 'popper.js']
|
||||||
const plugins = [
|
const plugins = [
|
||||||
babel({
|
babel({
|
||||||
exclude: 'node_modules/**', // only transpile our source code
|
exclude: 'node_modules/**', // only transpile our source code
|
||||||
|
Loading…
x
Reference in New Issue
Block a user