Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Upgrade to Gulp 4 (fixes build) (#1957)
Browse files Browse the repository at this point in the history
Summary:
Fixed the build-- it was broken from using Gulp 3 on Node 10:
nodejs/node#19786
Pull Request resolved: #1957

Reviewed By: pakoito

Differential Revision: D13433181

Pulled By: pakoito

fbshipit-source-id: 0f224a3ff92e1cc6abdbd4cec88a5742f9d3ff9a
  • Loading branch information
mrkev authored and facebook-github-bot committed Dec 12, 2018
1 parent 83edf02 commit 85ad25c
Show file tree
Hide file tree
Showing 5 changed files with 1,557 additions and 414 deletions.
258 changes: 146 additions & 112 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var gulpUtil = require('gulp-util');
var header = require('gulp-header');
var packageData = require('./package.json');
var rename = require('gulp-rename');
var runSequence = require('run-sequence');
var StatsPlugin = require('stats-webpack-plugin');
var through = require('through2');
var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
Expand Down Expand Up @@ -127,118 +126,153 @@ var buildDist = function(opts) {
});
};

gulp.task('clean', function() {
return del([paths.dist, paths.lib]);
});

gulp.task('modules', function() {
return gulp
.src(paths.src)
.pipe(babel(babelOptsJS))
.pipe(flatten())
.pipe(gulp.dest(paths.lib));
});

gulp.task('flow', function() {
return gulp
.src(paths.src)
.pipe(babel(babelOptsFlow))
.pipe(flatten())
.pipe(rename({extname: '.js.flow'}))
.pipe(gulp.dest(paths.lib));
});

gulp.task('css', function() {
return (gulp
.src(paths.css)
gulp.task(
'clean',
gulp.series(function() {
return del([paths.dist, paths.lib]);
}),
);

gulp.task(
'modules',
gulp.series(function() {
return gulp
.src(paths.src)
.pipe(babel(babelOptsJS))
.pipe(flatten())
.pipe(gulp.dest(paths.lib));
}),
);

gulp.task(
'flow',
gulp.series(function() {
return gulp
.src(paths.src)
.pipe(babel(babelOptsFlow))
.pipe(flatten())
.pipe(rename({extname: '.js.flow'}))
.pipe(gulp.dest(paths.lib));
}),
);

gulp.task(
'css',
gulp.series(function() {
return (
gulp
.src(paths.css)
.pipe(
through.obj(function(file, encoding, callback) {
var contents = file.contents.toString();
var replaced = contents.replace(
// Regex based on MakeHasteCssModuleTransform: ignores comments,
// strings, and URLs
/\/\*.*?\*\/|'(?:\\.|[^'])*'|"(?:\\.|[^"])*"|url\([^)]*\)|(\.(?:public\/)?[\w-]*\/{1,2}[\w-]+)/g,
function(match, cls) {
if (cls) {
return cls.replace(/\//g, '-');
} else {
return match;
}
},
);
replaced = replaced.replace(
// MakeHasteCssVariablesTransform
/\bvar\(([\w-]+)\)/g,
function(match, name) {
var vars = {
'fig-secondary-text': '#9197a3',
'fig-light-20': '#bdc1c9',
};
if (vars[name]) {
return vars[name];
} else {
throw new Error('Unknown CSS variable ' + name);
}
},
);
file.contents = Buffer.from(replaced);
callback(null, file);
}),
)
.pipe(concatCSS('Draft.css'))
// Avoid rewriting rules *just in case*, just compress
.pipe(cleanCSS({advanced: false}))
.pipe(header(COPYRIGHT_HEADER, {version: packageData.version}))
.pipe(gulp.dest(paths.dist))
);
}),
);

gulp.task(
'dist',
gulp.series('modules', 'css', function() {
var opts = {
debug: true,
output: 'Draft.js',
};
return gulp
.src('./lib/Draft.js')
.pipe(buildDist(opts))
.pipe(derequire())
.pipe(
through.obj(function(file, encoding, callback) {
var contents = file.contents.toString();
var replaced = contents.replace(
// Regex based on MakeHasteCssModuleTransform: ignores comments,
// strings, and URLs
/\/\*.*?\*\/|'(?:\\.|[^'])*'|"(?:\\.|[^"])*"|url\([^)]*\)|(\.(?:public\/)?[\w-]*\/{1,2}[\w-]+)/g,
function(match, cls) {
if (cls) {
return cls.replace(/\//g, '-');
} else {
return match;
}
},
);
replaced = replaced.replace(
// MakeHasteCssVariablesTransform
/\bvar\(([\w-]+)\)/g,
function(match, name) {
var vars = {
'fig-secondary-text': '#9197a3',
'fig-light-20': '#bdc1c9',
};
if (vars[name]) {
return vars[name];
} else {
throw new Error('Unknown CSS variable ' + name);
}
},
);
file.contents = Buffer.from(replaced);
callback(null, file);
}),
gulpif(
'*.js',
header(COPYRIGHT_HEADER, {version: packageData.version}),
),
)
.pipe(concatCSS('Draft.css'))
// Avoid rewriting rules *just in case*, just compress
.pipe(cleanCSS({advanced: false}))
.pipe(header(COPYRIGHT_HEADER, {version: packageData.version}))
.pipe(gulp.dest(paths.dist)) );
});

gulp.task('dist', ['modules', 'css'], function() {
var opts = {
debug: true,
output: 'Draft.js',
};
return gulp
.src('./lib/Draft.js')
.pipe(buildDist(opts))
.pipe(derequire())
.pipe(
gulpif('*.js', header(COPYRIGHT_HEADER, {version: packageData.version})),
)
.pipe(gulp.dest(paths.dist));
});

gulp.task('dist:min', ['modules'], function() {
var opts = {
debug: false,
output: 'Draft.min.js',
};
return gulp
.src('./lib/Draft.js')
.pipe(buildDist(opts))
.pipe(
gulpif('*.js', header(COPYRIGHT_HEADER, {version: packageData.version})),
)
.pipe(gulp.dest(paths.dist));
});

gulp.task('check-dependencies', function() {
return gulp.src('package.json').pipe(gulpCheckDependencies());
});

gulp.task('watch', function() {
gulp.watch(paths.src, ['modules']);
});

gulp.task('dev', function() {
gulp.watch(paths.src, ['modules', 'dist']);
});

gulp.task('default', function(cb) {
runSequence(
.pipe(gulp.dest(paths.dist));
}),
);

gulp.task(
'dist:min',
gulp.series('modules', function() {
var opts = {
debug: false,
output: 'Draft.min.js',
};
return gulp
.src('./lib/Draft.js')
.pipe(buildDist(opts))
.pipe(
gulpif(
'*.js',
header(COPYRIGHT_HEADER, {version: packageData.version}),
),
)
.pipe(gulp.dest(paths.dist));
}),
);

gulp.task(
'check-dependencies',
gulp.series(function() {
return gulp.src('package.json').pipe(gulpCheckDependencies());
}),
);

gulp.task(
'watch',
gulp.series(function() {
gulp.watch(paths.src, ['modules']);
}),
);

gulp.task(
'dev',
gulp.series(function() {
gulp.watch(paths.src, ['modules', 'dist']);
}),
);

gulp.task(
'default',
gulp.series(
'check-dependencies',
'clean',
['modules', 'flow'],
['dist', 'dist:min'],
cb,
);
});
gulp.parallel('modules', 'flow'),
gulp.parallel('dist', 'dist:min'),
),
);
2 changes: 1 addition & 1 deletion meta/bundle-size-stats/Draft.js.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion meta/bundle-size-stats/Draft.min.js.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"eslint-plugin-relay": "^0.0.8",
"fbjs-scripts": "^0.8.0",
"flow-bin": "^0.70.0",
"gulp": "^3.9.0",
"gulp": "^4.0.0",
"gulp-babel": "^6.1.2",
"gulp-browserify-thin": "^0.1.5",
"gulp-clean-css": "^2.0.3",
Expand All @@ -77,7 +77,6 @@
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-test-renderer": "^16.0.0",
"run-sequence": "^1.1.2",
"stats-webpack-plugin": "^0.6.2",
"through2": "^2.0.1",
"uglifyjs-webpack-plugin": "^1.1.6",
Expand Down
Loading

0 comments on commit 85ad25c

Please sign in to comment.