Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'gulp' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
it( 'reduces all .less files to a single .css file', function ( done ) {
gulp.start.apply( gulp, ['lessReduce'] );
gulp.on('task_stop', function ( e ) {
expect( path.join( __dirname, './tmp/lessReduce/root.css' ) ).to.be.a.file().and.not.empty;
expect( path.join( __dirname, './tmp/lessReduce/root.css' ) ).to.have.content( fs.readFileSync( path.join( __dirname, './expected/lessReduce/root.css'), 'utf8'));
// Todo: doesn't work
//expect( path.join( __dirname, './tmp/lessReduce/variables.css' ) ).to.not.be.a.file();
//expect( path.join( __dirname, './tmp/lessReduce/whatever.css' ) ).to.not.be.a.file();
done();
});
} );
}));
return mergeStreams(scripts, bundledScripts)
.pipe(gulp.dest('lib'));
});
gulp.step('client-scripts', gulp.series('client-scripts-bundle', 'client-scripts-templates-render'));
gulp.step('server-scripts-compile', () => {
return childProcess
.spawn('tsc -p src/tsconfig.json', { shell: true, stdio: 'inherit' });
});
// TODO: get rid of this step when we migrate to proper ES6 default imports
gulp.step('server-scripts-add-exports', () => {
const transform = new Transform({
objectMode: true,
transform (file, enc, cb) {
const fileSource = file.contents.toString();
if (fileSource.indexOf('exports.default =') >= 0) {
const sourceMapIndex = fileSource.indexOf('//# sourceMappingURL');
const modifiedSource = fileSource.slice(0, sourceMapIndex) + 'module.exports = exports.default;\n' + fileSource.slice(sourceMapIndex);
file.contents = Buffer.from(modifiedSource);
}
cb(null, file);
}
});
}));
const bundledScripts = scripts
.pipe(clone())
.pipe(uglify())
.pipe(rename(file => {
file.extname = '.min.js';
}));
return mergeStreams(scripts, bundledScripts)
.pipe(gulp.dest('lib'));
});
gulp.step('client-scripts', gulp.series('client-scripts-bundle', 'client-scripts-templates-render'));
gulp.step('server-scripts-compile', () => {
return childProcess
.spawn('tsc -p src/tsconfig.json', { shell: true, stdio: 'inherit' });
});
// TODO: get rid of this step when we migrate to proper ES6 default imports
gulp.step('server-scripts-add-exports', () => {
const transform = new Transform({
objectMode: true,
transform (file, enc, cb) {
const fileSource = file.contents.toString();
if (fileSource.indexOf('exports.default =') >= 0) {
const sourceMapIndex = fileSource.indexOf('//# sourceMappingURL');
const modifiedSource = fileSource.slice(0, sourceMapIndex) + 'module.exports = exports.default;\n' + fileSource.slice(sourceMapIndex);
console.log( 'Compiling templates...' );
gulp.src( sourcePaths.libraryTemplates )
.pipe( rename( function ( path ) {
path.dirname = 'templates';
} ) )
.pipe( templateCache( libraryName + '-templates.js', {
module: libraryTemplatesModule,
standalone: true,
root: '/' + libraryName + '/'
} ) )
.pipe( gulp.dest( buildPaths.root ) );
} );
gulp.task( 'compile-library-styles', function () {
console.log( 'Compiling styles...' );
gulp.src( sourcePaths.libraryStyles )
// The onerror handler prevents Gulp from crashing when you make a mistake in your SASS
.pipe(sourcemaps.init())
.pipe( sass( {
errLogToConsole: true,
sourceComments: 'map'
} ) )
.pipe(sourcemaps.write())
.pipe( rename( function ( path ) {
path.dirname = '';
} ) )
.pipe( concat( libraryName + '.css' ) )
.pipe( gulp.dest( buildPaths.root ) );
gulp.task('basic', function() {
console.log('Toto je task.');
});
/* gulp-src (minimatch) */
gulp.task('src', function() {
var result = gulp.src('input/*.+(js|txt)');
console.log('src', result);
});
/* gulp-dest (vinyl) */
gulp.task('dest', function() {
gulp.src('input/**/*')
.pipe(gulp.dest('output'));
});
/* gulp-watch */
gulp.task('watch', function() {
gulp.watch('input/*', function(event) {
console.log('event', event.type, event.path);
});
});
/* watch and call task */
function serve(path) {
// Serve files from the root of this project
browserSync.init({
server: {
baseDir: path,
index: "index-dev.html"
}
});
gulp.watch("index-dev.html").on("change", reload);
gulp.watch("partials/*.html").on("change", reload);
gulp.watch("js/*.js").on("change", reload);
gulp.watch("codemirror/*").on("change", reload);
gulp.watch("nomnoml/*").on("change", reload);
gulp.watch("css/*.css").on("change", reload);
}
.pipe((page.replace_js && page.replace_js.length > 2) ? replace(page.replace_js[2].match, page.replace_js[2].replacement) : through.obj())
.pipe(gulp.dest(destDir));
});
gulp.task('copy:assets:local', () => {
return gulp.src([configDir + 'assets/*'], {base: configDir}).pipe(gulp.dest(destDir))
});
gulp.task('copy:assets:global', () => {
return gulp.src(['src/assets/*'], {base: 'src'}).pipe(gulp.dest(destDir))
});
gulp.task('build:html', gulp.series(gulp.parallel('copy:assets:local', 'copy:assets:global'), () => {
/* HTMLをビルドする */
let page = JSON.parse(fs.readFileSync(configDir + 'pageconfig.json'));
if (process.env.NODE_ENV !== 'production') {
page.siteUrl = null;
}
let values = {
page: page,
url: page.siteUrl,
head: ejs.render(fs.readFileSync('./src/html/head.ejs', {encoding: 'utf8'}), {url: page.siteUrl}),
body: fs.readFileSync('./src/html/body.ejs', {encoding: 'utf8'}),
script: ejs.render(fs.readFileSync('./src/html/script.ejs', {encoding: 'utf8'}), {url: page.siteUrl})
};
console.log(configDir + 'index.html')
return gulp.src(['index.html'], {cwd: configDir})
.pipe(gulpEjs(values, {}, {ext: ".html"}))
.pipe(gulp.dest(destDir))
}
setSettings(argv);
if (global.settings.production) {
// in production mode, make sure environment is production
process.env.NODE_ENV = 'production';
}
// Customize CLI behavior
// Make gulp think we have tasks so that it doesn't error
if (argv._) {
if (argv._[0] && argv._[0].indexOf(':') > -1) {
gutil.log(gutil.colors.red('Running subtasks is not allowed due to unknown behavior.'));
process.exit();
}
const tasks = Object.keys(gulp.tasks);
// fill in missing tasks
const toFillIn = ['_', 'platform', 'recipe'];
toFillIn.forEach((key) => {
if (argv[key]) {
const vals = Array.isArray(argv[key]) ? argv[key] : [argv[key]];
vals.forEach((taskName) => {
if (tasks.indexOf(taskName) === -1) {
gulp.task(taskName, () => {});
}
});
}
});
}
require('./boilerplate/scripts/analyze.js');
require('./boilerplate/scripts/build.js');
return function (done){
// console.log(this.storage.get('me'))
/**
* Set options.generator equal to the context of the current gulp taks;
* @type {Object};
*/
options.generator = new Generator( this, options, __this );
_.extend(gulp.tasks.default, options.generator);
options.doneCallback = done;
return __stream.validate( options )
.then( __stream.flow )
.then( __stream.defaults )
.then( __stream.prompts )
.then( __stream.configuration )
.then( __stream.filter )
.then( __stream.paths )
.then( __stream.use )
.catch( done )
}
}
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const exec = require('child_process').exec;
const Karma = require('karma').Server;
const mocha = require('gulp-mocha');
const runSequence = require('gulp4-run-sequence');
const gulpIstanbul = require('gulp-istanbul');
const sourcemaps = require('gulp-sourcemaps');
const packageJSON = require('./package.json');
const gzip = require('gulp-gzip');
const unzip = require('gulp-unzip');
// increase mocha timeout from default of 2000 to allow long running async tests to complete
const mochaTimeout = 5000;
gulp.on('error', process.exit.bind(process, 1));
gulp.task('clean', () => {
return gulp
.src(['lib', 'dist', 'coverage', 'upload'], { read: false, allowEmpty: true })
.pipe(clean());
});
gulp.task('babel', () => {
return gulp
.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('lib'));
});
gulp.task('unzip_titanium_sdk', () => {