npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-git-svn-version-filename

v2.0.4

Published

文件名中追加svn/git的对应文件版本号,要求传入文件的父层在svn/git仓库中

Downloads

8

Readme

Gulp Git/Svn Version Filename

此 gulp 插件用于在文件名中添加对应 Git/Svn 的版本号。

注意:gulpfile.js 文件所在目录需要是 Git/Svn 有效的版本仓库目录,并确保命令行中能正常运行 Git/Svn 命令。

如何使用

安装模块

npm i gulp-git-svn-version-filename

创建实例

var FileVer = require('gulp-git-svn-version-filename');
var fileVer = new FileVer({
	type: 'svn', // 仓库类型 支持svn、git
	cwd: process.cwd(), // 项目根目录
	user: '', // 仓库账号名
	pwd: '', // 仓库账号密码
	cache: true, // 是否缓存已查询版本信息
	formater: '{name}_{version}{ext}', // 文件名加版本号的规则(不提供目录结构修改)
});
  • type {String} 仓库类型 支持svn、git,默认为svn
  • cwd {String} 项目根目录,默认为process.cwd()
  • user {String} 仓库账号名,只支持SVN
  • pwd {String} 仓库账号密码 只支持SVN
  • cache {Boolean/Object} 是否缓存已查询版本信息
    • Boolean时:允许与否。注意:为true时使用的是全局缓存,所有引用共用一个缓存空间。
    • Object时:值为缓存对象,必须为普通对象(isPlainObject)。
  • formater {String/Function}
    • 值String时:文件名加版本号的规则(不提供目录结构修改) 默认值:'{name}_{version}{ext}';
    • 值为Function(pathObj, this)时:pathObj为pathObj. = Path.parse(path),并加入version信息,this指向fileVer。

FileVer.cloneGitBaseRemot(remoteUrl, branche, callback) 静态方法 同步仓库的.git文件夹到本地当前目录

  • remoteUrl {String} 远程仓库地址
  • branche {String} 待clone的分支名
  • callback(err) clone完成后的回调方法,如果出错返回的第一个参数为error信息,如果成功则返回null

fileVer.getCache([path]) 获取已查询过的文件版本列表,数据为所有引用共用

  • path: 待查文件路径
  • 返回结果:当传入path参数时只返回path的对应版本信息, 否则返回所有缓存信息Map 如:{'/home/user/git/project/js/a.js': '34ae3'}

fileVer.delCache([path]) 删除缓存信息

  • path: 删除指定Key的缓存信息,如不传则删除所有缓存

fileVer.get(fullPath, callback) 获取指定URL的版本信息

  • fullPath {String} 绝对路径地址
  • callback(version) {Function} 获取到信息后的回调方法
    • version {String} 为fullPath对应的版本号,当仓库中无版本号或获取失败时值为0

fileVer.formaterPath(fullPath, version) 按照this.formater规则给fullPath加上version信息

  • fullPath {String} 要加版本号的文件路径
  • version {String} 待加入的版本号值
  • 返回结果:加入版本号信息后的文件路径

fileVer.getForTransform(callback) 获取gulp(Transform方式)传入file的版本号信息

  • callback(version, file) {Function} 获取到信息后的回调方法
    • version {String} 为fullPath对应的版本号,当仓库中无版本号或获取失败时值为null
    • file 当前处理的文件对象

fileVer.setForTransform(callback) 按formater给的规则设置gulp(TransForm方式)传入file的版本号

  • callback(oldFullFilePath, versionFullFilePath) 给file.path加完版本后的回调方法

配置中user、pwd参数目前只有SVN支持,Git仓库请走ssh方式

gulpfile.js 中

var FileVer = require('gulp-git-svn-version-filename');
var cacheObj = {};
var fileVer = new FileVer({
    type: 'svn', // 仓库类型 支持svn、git
    cache: cacheObj, // 指定缓存对象
    cwd: process.cwd(), // 项目根目录
    user: '', // 仓库账号名
    pwd: '', // 仓库账号密码
});
gulp.task('addSvnVersion', function(){
    return gulp.src(['./js/**/*.js', './css/**/*.css'])
        .pipe(fileVer.setForTransform(function(oldPath, versionPath){
            console.log(versionPath, fileVer.getCache());
        })
        .pipe(gulp.dest('./build'))
});