Sym - 一个用 Java 实现的现代化社区平台 • 源码 • 注册

Pipe - 小而美的开源博客平台 • 体验 • 皮肤
Solo - 一个用 Java 实现的博客系统,为你或你的团队创建个博客吧! • 源码下载 
Wide - 一个基于 Web 的 Go 语言 IDE • 教程试用

如何编写 gulp 插件

1.  编写 package.json

注意填写 name, version, main, description, keywords, dependencies 

可参见 https://github.com/Vanessa219/gulp-header-license/blob/master/package.json

{
  "name": "gulp-header-license",
  "version": "1.0.0",
  "description": "Gulp extension to add license to file(s) in the pipeline.",
  "main": "./index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git://github.com/Vanessa219/gulp-header-license.git"
  },
  "keywords": [
    "header",
    "license",
    "gulpplugin"
  ],
  "author": "Vanessa <lly219@gmail.com> (http://vanessa.b3log.org)",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/Vanessa219/gulp-header-license/issues"
  },
  "dependencies": {
    "concat-with-sourcemaps": "*",
    "object-assign": "*",
    "through2": "*"
  },
  "homepage": "https://github.com/Vanessa219/gulp-header-license#readme",
  "maintainers": [
    {
      "name": "Vanessa",
      "email": "lly219@gmail.com"
    }
  ]

 

2. 编写 index.js

基础:BufferStream

可参见:https://github.com/Vanessa219/gulp-header-license/blob/master/index.js

module.exports = function (template, config) {
return through.obj(function (file, enc, cb) {
    // fils is exit
    if (file.isNull()) {
        this.push(file);
        return cb();
    }

    // process file
    if (file.isBuffer()) {
        file.contents = Buffer.concat([prefixText, file.contents]);
    }
    if (file.isStream()) {
        file.contents = file.contents.pipe(prefixStream(prefixText));
    }

    // do something

    // for pipe
    this.push(file);
    cb();
});

};

 

3. 注册 npmjs

 https://www.npmjs.com/

4. 添加用户信息

npm adduser
npm login

5. 发布

npm publish

啦啦啦,不要重名,此时,你就可以看到你的插件上传上去了

https://www.npmjs.com/package/gulp-header-license

6. update

更新 package.json 中的 version, `npm publish`

 

具体实现可参见 :gulp-header-license


欢迎注册黑客派社区,开启你的博客之旅。让学习和分享成为一种习惯!

留下你的脚步