Skip to content
This repository was archived by the owner on Feb 21, 2025. It is now read-only.

Commit 7e7e178

Browse files
committed
feat(tasks): add copy feature
1 parent d4754d2 commit 7e7e178

File tree

7 files changed

+66
-1
lines changed

7 files changed

+66
-1
lines changed

docs/features/copy.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copy any files to a destination folder (usefull for node_modules vendoring).
2+
3+
## Usage
4+
5+
You simply put the files (input) that you want to copy to output (dist).
6+
```yml
7+
copy:
8+
enabled: true
9+
files:
10+
- src: "node_modules/lodash/dist/lodash.js"
11+
dest: "dist/vendors/"
12+
- src: "node_modules/underscore/dist/*.js"
13+
dest: "dist/vendors/"
14+
concat: true # (optional) enable concat
15+
destName: "underscore.js" # (optional) concatened file name
16+
[...]
17+
```
18+
19+
## Commands
20+
21+
- `gulp copy` - Launch copy task
22+
- `gulp watch:copy` - Watch and copy
23+
24+
---

docs/features/js.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Compiles JS files using Babel. You can optionaly concat, uglify, and add sourcemaps.
22

33
!!! note ""
4-
We recommand to use [webpack](features/webpack.md) instead.
4+
We recommand to use [webpack](features/webpack.md) for big SPA.
55

66
## Commands
77

gulpfile.default.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,10 @@ drupal:
168168
- templates/**
169169
command: drush cr
170170
dir: './'
171+
copy:
172+
enabled: false
173+
# files:
174+
# - src: "node_modules/lodash/dist/*.js"
175+
# dest: "dist/"
176+
# concat: true
177+
# destName: "lodash.js"

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ module.exports = (gulp, userConfig, tasks) => {
3939
require('./lib/webpack')(gulp, config, tasks);
4040
}
4141

42+
if (config.copy.enabled) {
43+
require('./lib/copy')(gulp, config, tasks);
44+
}
45+
4246
/* eslint-enable global-require */
4347

4448
// This is a fix fo Gulp, because series and paparallel needs at least one task

lib/copy.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
const concat = require('gulp-concat');
4+
const gulpif = require('gulp-if');
5+
6+
module.exports = (gulp, config, tasks) => {
7+
function copyCurrentFiles(files) {
8+
return gulp.src(files.src)
9+
.pipe(gulpif(files.concat, concat(files.destName || 'undefined.js')))
10+
.pipe(gulp.dest(files.dest));
11+
}
12+
13+
copyCurrentFiles.description = 'Copies multiple files into a given destination (and optionally concat them).';
14+
15+
gulp.task('copy', gulp.parallel(config.copy.files.map(files => function copyFiles() {
16+
return copyCurrentFiles(files);
17+
})));
18+
19+
gulp.task('watch:copy', gulp.parallel(config.copy.files.map(files => function watchCopyFiles() {
20+
return gulp.watch(files.src, gulp.series(function copyFiles() {
21+
return copyCurrentFiles(files);
22+
}));
23+
})));
24+
25+
tasks.compile.push('copy');
26+
tasks.watch.push('watch:copy');
27+
};
28+

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pages:
1111
- Icons: features/icons.md
1212
- Drupal-Drush: features/drupal-drush.md
1313
- Browsersync: features/browser-sync.md
14+
- Copy: features/copy.md
1415
- Troubleshooting: troubleshooting.md
1516

1617
markdown_extensions:

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"gulp-babel": "^7.0.1",
4040
"gulp-cached": "^1.1.1",
4141
"gulp-concat": "^2.6.1",
42+
"gulp-copy": "^1.1.0",
4243
"gulp-csscombx": "^4.2.1",
4344
"gulp-eslint": "^4.0.2",
4445
"gulp-flatten": "^0.4.0",

0 commit comments

Comments
 (0)