I have directory structure like this.
dist
|--client
|--assets
|--images
|--bower_components
|--server
|--.bower.json
I am trying to clean dist folder, except assets/images folder.
But when i execute this command in dryRun mode, it doesn't remove assets/images file. But after disabling it, it remove all the files and folder.
gulp.task('clean:dist', () => {
del.sync([
`${paths.dist}/!(.git*|.openshift|Procfile)**`,
`${paths.dist}/client/**`,
`!${paths.dist}/client/assets`,
`!${paths.dist}/client/assets/**`], {
//dryRun: true
});
//console.log('dELETE FIELSE ARE: ' + JSON.stringify(value));
});
value of used constant is:
${paths.dist} ='dist';
The offical del documentation states the following:
The glob pattern ** matches all children and the parent.
So this won't work:
del.sync(['public/assets/**', '!public/assets/goat.png']);
You have to explicitly ignore the parent directories too:
del.sync(['public/assets/**', '!public/assets', '!public/assets/goat.png']);
In your case you delete dist/client/**, which includes the dist/client directory itself. If you just ignore dist/client/assets/** the dist/client directory is still deleted.
You need to explicitly ignore the dist/client directory:
gulp.task('clean:dist', () => {
del.sync([
`${paths.dist}/!(.git*|.openshift|Procfile)**`,
`${paths.dist}/client/**`,
`!${paths.dist}/client`,
`!${paths.dist}/client/assets/**`]);
});
Related
I need to check if a specific folder exists, I can not give the full path as some of the folder names will be different each time.
I used the below code -
echo "checking if folder exists"
def files = findFiles glob: '**/*example*'
echo """${files[0].name} ${files[0].path} ${files[0].directory} ${files[0].length} ${files[0].lastModified}"""
example is a folder which is inside -
java-maven-app/src/main/java/com/example
the error, I am getting in pipeline is -
You are getting that error because your files list doesn't have any content. AFAIK findFiles is not capable of finding directories recursively. If you have any known files within the directory you are looking for you may be able to get the full path to that file using findFiles and determine whether your directory exists. But it will not work if the directory is empty. As a better solution, you can use the following script to get a list of all directories recursively.
pipeline {
agent any
stages {
stage('Example') {
steps {
script {
def directories = getDirectories("$WORKSPACE")
echo "$directories"
}
}
}
}
}
#NonCPS
def getDirectories(path) {
def dir = new File(path);
def dirs = [];
dir.traverse(type: groovy.io.FileType.DIRECTORIES, maxDepth: -1) { d ->
dirs.add(d)
};
return dirs
}
I'm looking for something like..
fs.copy([dir1,dir2], 'destDirString').then(() => {
cb();
});
Is there an easy way to copy two directories' contents to another dir in Node? I have two NCP commands now, want to condense.
you might be looking for merge-dirs
Usage:
var mergedirs = require('merge-dirs');
// copy folder/a into folder/b
mergedirs('/folder/a', '/folder/b');
// copy folder/a into folder/b with conflict resolution 'overwrite'
mergedirs('/folder/a', '/folder/b', 'overwrite');
// copy folder/a into folder/b with conflict resolution 'ask'
mergedirs('/folder/a', '/folder/b', 'ask');
// copy folder/a into folder/b with conflict resolution 'skip'
mergedirs('/folder/a', '/folder/b', 'skip');
I'm trying to copy all my assets into my public dir but I want all assets except JavaScript and CSS files cause they are concatenated and minified into prod.min.js and prod.min.css so I want to make two exception for min.js and min.css files.
I have tried this (only for JS for now)
gulp.src([src + '/**/*', src + '/**/*.min.js', '!' + src + '/**/*.js'])
.pipe(gulp.dest(dest))
But it results in no JavaScript files at all.
How can do this?
Create separate glob arrays for CSS and JS. Then you can be more selective in which get moved.
I am also dealing with this problem at the moment.
The way I patched it (it's a patch because it's not really an optimal solution) is by making two passes:
First pass -> move all (**/*.*) files and negate all js extensions (!**/*.js)
Second pass -> move only the minified files (**/*.min.js)
A quick task example:
gulp.task('move-min-not-src', [], function() {
var paths = [
[
'source-folder/**/*.*',
'!source-folder/**/*.js'
],
[
'source-folder/**/*.min.js'
]
];
paths.forEach(function(path) {
gulp.src(path)
.pipe(
gulp.dest('destination-folder/')
);
});
});
I'm writing a task to extract a tarball into a directory. I don't control this tarball's contents.
The tarball contains a single directory which contains all the files I actually care about. I want to pull everything out of that directory and copy that into my destination.
Example:
/root/subdir
/root/subdir/file1
/root/file2
Desired:
/subdir
/subdir/file1
/file2
Here's what I tried so far, but this seems like a really goofy way of doing it:
copy {
eachFile {
def segments = it.getRelativePath().getSegments() as List
it.setPath(segments.tail().join("/"))
return it
}
from tarTree(resources.gzip('mytarfile.tar.gz'))
into destinationDir
}
For each file, I get the elements of its path, remove the first, join that with /, then set that as the file's path. And this works...sort of. The problem is that this creates the following structure as a result:
/root/subdir
/root/subdir/file1
/root/file2
/subdir
/subdir/file1
/file2
I'm fine with just removing the root directory myself as a final action of the task, but I feel like there should be a much simpler way of doing this.
AFAIK, the only way is to unpack the zip, tar, tgz file :(
There is an open issue here
Please go vote for it!
Until then, the solution isn't very pretty, but not that hard either. In the example below, I am assuming that you want to remove the 'apache-tomcat-XYZ' root-level directory from a 'tomcat' configuration that only includes the apache-tomcat zip file.
def unpackDir = "$buildDir/tmp/apache.tomcat.unpack"
task unpack(type: Copy) {
from configurations.tomcat.collect {
zipTree(it).matching {
// these would be global items I might want to exclude
exclude '**/EMPTY.txt'
exclude '**/examples/**', '**/work/**'
}
}
into unpackDir
}
def mainFiles = copySpec {
from {
// use of a closure here defers evaluation until execution time
// It might not be clear, but this next line "moves down"
// one directory and makes everything work
"${unpackDir}/apache-tomcat-7.0.59"
}
// these excludes are only made up for an example
// you would only use/need these here if you were going to have
// multiple such copySpec's. Otherwise, define everything in the
// global unpack above.
exclude '**/webapps/**'
exclude '**/lib/**'
}
task createBetterPackage(type: Zip) {
baseName 'apache-tomcat'
with mainFiles
}
createBetterPackage.dependsOn(unpack)
Using groovy's syntax, we can use a regex to eliminate the first path segment:
task myCopyTask(type: Copy) {
eachFile {
path -= ~/^.+?\//
}
from tarTree(resources.gzip('mytarfile.tar.gz'))
into destinationDir
includeEmptyDirs = false // ignore empty directories
}
I'm trying both gulp.js and grunt.js to convert from markdown to PDF, both of them use markdownpdf npm package.
This is my gulpfile.js
gulp.task('markdownpdf', function () {
gulp.src('_src/*.md')
.pipe(concat('document.md'))
.pipe(markdownpdf({
cssPath: '/_src/css/pdf.css',
paperFormat: 'A4',
paperOrientation: 'portrait',
paperBorder: '2cm'
}))
.pipe(gulp.dest('_dist'));
});
Without cssPath option, markdownpdf package picks node_modules/gulp-markdown-pdf/node_modules/markdown-pdf/pdf.css (I tired to edit this file to confirm that it was picked)
Please help how to setup custom css path.
Thanks.
What's worked for me is to start the path with a ./. The single dot represents the directory with the gulpfile in it.
e.g
gulp.task('docs', function () {
return gulp.src('./docs/*.md')
.pipe(markdownpdf({
'cssPath': './docs/assets/pdf.css'
}))
.pipe(gulp.dest('./web/docs/pdfs'));
});
so '/_src/css/pdf.css' maps to what?
It should respond to relative path notation, so if it picks node_modules/gulp-markdown-pdf/node_modules/markdown-pdf/pdf.css by default, then try setting your cssPath value to ../../../_src/css/pdf.css, assuming _src is in your project's root
Maybe you will need back 5 levels.
My gruntfile.js...
markdownpdf: {
options: {
cssPath: "../../../../../css/style.css",