I would like to know if its possible to get the git version for my package.json
What i want to achieve is that i don't need to bump the version manually.
There is something like that in Java with gradle f.e.
https://github.com/palantir/gradle-git-version
It is using git describe to get the latest tag of the git repo and if it contains new commits/changes the repo is marked as dirty. On the dirty check it automatically returns the next development version for gradle.
I didn't find anything like that for gulp
Yes.
Check this npm module https://www.npmjs.com/package/git-version-json
You can use gulp-replace and git-version-json
use git-version-json to generate the json variable.
use gulp-replace to replace the version
As below:
var gulp = require('gulp');
var replace = require('gulp-replace');
var GitVersionJson = require('git-version-json');
// automatic use git-rev in version field of package.json
gulp.task('npm-git-rev', [GitVersionJson.task], ()=>{
return gulp.src('package.json')
.pipe(replace(/(\"version\"\s*:\s*\"\d+\.\d+\.)(\d+)(\")/,
"$1" + GitVersionJson.gitVer.rev + "$3"))
.pipe(gulp.dest('.'))
});
run it with gulp npm-git-rev
Related
I'm dipping my toes into cli tooling by building a simple program for automating Gerrit commits. Everything works locally, but after publishing the package to npm and installing it globally it looks like process.cwd() behaves differently. The program exits, but no console.log(). Even a simple console.log(process.cwd()) is ignored (again works locally). Is it possible to use process.cwd() when running a globally installed npm package?
console.log(process.cwd());
const getCurrentBranchName = (p = process.cwd()) => {
const gitHeadPath = `${p}/.git/HEAD`;
return fs.existsSync(gitHeadPath)
? fs.readFileSync(gitHeadPath, "utf-8").trim().split("/").pop()
: (console.log("not a git repo"), process.exit(0));
}
const currentBranch = getCurrentBranchName();
When ran locally (with node index):
$ /Users/jpap/.npm-packages/lib/node_modules/gittest
$ not a git repo
You haven't proved the problem is with process.cwd()
The code in your question and the results your describe only indicate that the console.log() calls aren't executing.
You could easily test this by adding the following to the top of your code:
console.log('My name is Inigo Montoya. You killed my father. Prepare to die!')
What you are publishing is likely not the same as what you are running locally
For example, you could be using a bundler (e.g. Rollup) configured to strip console.log calls.
This is easy to confirm. Simple look at the code of the npm installed version:
Use npm root -g to find out where your global packages are installed. For non-global packages, look in node_modules.
Find your package's subdir.
Look at the code, or diff it with the source code.
I suspect you will see all console.log statements removed.
I'm using gradle node plugin for my project and when I run the nodeSetup task it tries to install the node dist from https://nodejs.org/dist/v12.6.0/node-v12.6.0-darwin-x86_64.tar.gz which I know does not exists. The correct URL should be https://nodejs.org/dist/v12.6.0/node-v12.6.0-darwin-x64.tar.gz I'm not sure why its adding x86_64 instead of x64 and I was wondering if there is any way to directly specify the complete dist URL for gradle node plugin.
Here is my node config inside my build.gradle
node {
version = '12.6.0'
npmVersion = '6.0.0'
yarnVersion = '1.13.0'
download = true
workDir = file("${buildDepsDir}/nodejs")
npmWorkDir = file("${buildDepsDir}/npm")
yarnWorkDir = file("${buildDepsDir}/yarn")
nodeModulesDir = file("${project.projectDir}")
}
It sounds like you may be using an old version of the plugin, this exact issue has been fixed in 3.2.1
It would make sense for me to use some of gulp modules/plugins independently. E.g.: I have installed gulp-less globally (npm install --global gulp-less) and want to use it instead of lessc in the manner like grunt-less -options ./my/css/folder or grunt less -options ./my/css/folder. But my attempt end with an error message:
$ gulp less ./css/
Using gulpfile ~/temp/gulptest/gulpfile.js
Task 'less' is not in your gulpfile
Please check the documentation for proper gulpfile formatting
Ideally I also would like to use gulp plugins outside of any project as independent tools.
How to run gulp modules outside of the build context?
If this option is not provided: Is there a workaround?
Put in your gulpfile.js:
gulp.task('less', function () {
// as you wish
})
How can I create a gulp command to build documentation using jsdoc?
I don't want to use the gulp-jsdoc package, as it is not maintained. And the package I had been using to call it from the command line, gulp-shell, is on the gulp blacklist.
Use node's built-in child_process like this:
var child_exec = require('child_process').exec;
gulp.task('docs', function(done) {
child_exec('node ./node_modules/jsdoc/jsdoc.js ./lib -c ./jsdoc.json', undefined, done);
});
(This example assumes you have a config file ./jsdoc.json, but it's easy to change the calling syntax.)
I like to display my project version (from package.json), the git commit hash and working-copy status in the footer of my Ember app built using ember-cli and broccoli.
I can grab the version prefix easily enough by adding to my config/environment.js:
ENV.APP.version = require('../package.json').version
I was using grunt-git-describe previously to grab the revision hash and dirty/clean status. How can I do something similar in ember-cli?
Simply shelling out to git describe is problematic since child_process does not have a synchronous method of executing a shell command.
It there a way I can return a promise from somewhere and prevent config/environment.js from resolving until my async git describe completes?
The npm packages exec-sync and execSync don't seem to work well for me on Windows.
ember-git-version is an ember-cli addon that provides the current revision hash.
After installing the node package, the config/environment hash will have a property currentRevision. See initializers/print-git-info.js for how to access it from your app.
You can use the exec-sync package and then add something like this to Brocfile.js:
var execSync = require('exec-sync'),
gitVersion = execSync('git describe');
fs.writeFileSync('app/version.js', 'App.version = "' + gitVersion + '";';
You'll then need to import that somewhere.