Skip to content

Commit

Permalink
ADD: first release
Browse files Browse the repository at this point in the history
  • Loading branch information
farthinker committed Aug 3, 2016
1 parent e3bceb4 commit a682641
Show file tree
Hide file tree
Showing 31 changed files with 1,218 additions and 23 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
npm-debug.log
coverage
test/*.js
.token

.DS_Store
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

## V1.0.0 - 2016-08-03

* First release.
42 changes: 21 additions & 21 deletions LICENSE → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 彩程设计

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
## The MIT License (MIT)

Copyright (c) 2016 Mycolorway Design

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
148 changes: 146 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,146 @@
# qing-module
A simple base class providing necessary features to make its subclasses extensible
# Qing Module

[![Latest Version](https://img.shields.io/npm/v/qing-module.svg)](https://www.npmjs.com/package/qing-module)
[![Build Status](https://img.shields.io/travis/mycolorway/qing-module.svg)](https://travis-ci.org/mycolorway/qing-module)
[![Coveralls](https://img.shields.io/coveralls/mycolorway/qing-module.svg)](https://coveralls.io/github/mycolorway/qing-module)
[![David](https://img.shields.io/david/mycolorway/qing-module.svg)](https://david-dm.org/mycolorway/qing-module)
[![David](https://img.shields.io/david/dev/mycolorway/qing-module.svg)](https://david-dm.org/mycolorway/qing-module#info=devDependencies)
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/mycolorway/qing-module)

QingModule is a simple base class providing some necessary features to make its subclasses extendable.

## Features

#### Events

QingModule delegate events mothods to jQuery object:

```js
let module = new QingModule();

// bind namespace event
module.on('customEvent.test', function(data) {
console.log(data);
});
// equivalent to
$(module).on('customEvent.test', function(data) {
console.log(data);
});

// trigger a namespace event
module.trigger('customEvent.test', 'test');
// equivalent to
$(module).trigger('customEvent.test', 'test');
```

#### Mixins

Add class properties and methods to QingModule:

```js
var testMixins = {
classProperty: true,
classMethod: function() {}
};

QingModule.extend(testMixins);
```

Add instance properties and methods to QingModule:

```js
var testMixins = {
instanceProperty: true,
instanceMethod: function() {}
};

QingModule.include(testMixins);
```

#### Plugins

Register a plugin on QingModule:

```js
class TestPlugin extends QingModule {
constructor(module) {
super()
this.module = module;
this.test = true;
}
}

QingModule.plugin('testPlugin', TestPlugin);
```

Then pass the plugin name to options while creating instance:

```js
let module = new QingModule({
plugins: ['testPlugin']
});
console.log(module.plugins.testPlugin.test); // true
```

## Installation

Install via npm:

```bash
npm install --save qing-module
```

Install via bower:

```bash
bower install --save qing-module
```

## Development

Clone repository from github:

```bash
git clone https://github.com/mycolorway/qing-module.git
```

Install npm dependencies:

```bash
npm install
```

Run default gulp task to build project, which will compile source files, run test and watch file changes for you:

```bash
gulp
```

Now, you are ready to go.

## Publish

If you want to publish new version to npm and bower, please make sure all tests have passed before you publish new version, and you need do these preparations:

* Add new release information in `CHANGELOG.md`. The format of markdown contents will matter, because build scripts will get version and release content from this file by regular expression. You can follow the format of the older release information.

* Put your [personal API tokens](https://github.com/blog/1509-personal-api-tokens) in `/.token.json`, which is required by the build scripts to request [Github API](https://developer.github.com/v3/) for creating new release:

```json
{
"github": "[your github personal access token]"
}
```

Now you can run `gulp publish` task, which will do these work for you:

* Get version number from `CHANGELOG.md` and bump it into `package.json` and `bower.json`.
* Get release information from `CHANGELOG.md` and request Github API to create new release.

If everything goes fine, you can see your release at [https://github.com/mycolorway/qing-module/releases](https://github.com/mycolorway/qing-module/releases). At the End you can publish new version to npm with the command:

```bash
npm publish
```

Please be careful with the last step, because you cannot delete or republish a release on npm.
46 changes: 46 additions & 0 deletions build/compile.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
gulp = require 'gulp'
_ = require 'lodash'
coffeelint = require './helpers/coffeelint'
browserify = require './helpers/browserify'
sass = require './helpers/sass'
header = require './helpers/header'
rename = require './helpers/rename'
uglify = require './helpers/uglify'
umd = require './helpers/umd'
pkg = require '../package.json'

compileSass = ->
gulp.src 'src/**/*.scss'
.pipe sass()
.pipe header()
.pipe gulp.dest('dist/')
compileSass.displayName = 'compile-sass'

compileCoffee = ->
gulp.src "src/#{pkg.name}.coffee"
.pipe coffeelint()
.pipe browserify()
.pipe umd()
.pipe header()
.pipe gulp.dest('dist/')
compileCoffee.displayName = 'compile-coffee'

compileUglify = ->
gulp.src ['dist/**/*.js', '!dist/**/*.min.js']
.pipe uglify()
.pipe header('simple')
.pipe rename
suffix: '.min'
.pipe gulp.dest('dist/')
compileUglify.displayName = 'compile-uglify'

compileAssets = gulp.parallel compileCoffee, compileSass, (done) -> done()

compile = gulp.series compileAssets, compileUglify, (done) -> done()

gulp.task 'compile', compile

module.exports = _.extend compile,
sass: compileSass
coffee: compileCoffee
uglify: compileUglify
51 changes: 51 additions & 0 deletions build/helpers/browserify.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
gutil = require 'gulp-util'
_ = require 'lodash'
through = require 'through2'
coffee = require 'coffee-script'
browserify = require 'browserify'
handleError = require './error'

module.exports = (opts) ->
b = browserify _.extend
transform: [coffeeify]
bundleExternal: false
, opts

through.obj (file, encoding, done) ->

try
b.require file.path,
expose: file.stem
b.bundle (error, buffer) =>
handleError(error, @) if error
file.contents = buffer
file.path = gutil.replaceExtension file.path, '.js'
@push file
done()
catch e
handleError e, @
done()

coffeeify = (filename, opts = {}) ->
return through() unless /\.coffee$/.test(filename)

opts = _.extend
inline: true
bare: true
header: false
, opts

chunks = []
through (chunk, encoding, done) ->
chunks.push chunk
done()
, (done) ->
str = Buffer.concat(chunks).toString()

try
result = coffee.compile str, opts
catch e
handleError e, @

@push result
done()
25 changes: 25 additions & 0 deletions build/helpers/changelogs.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
fs = require 'fs'

changelogs = fs.readFileSync('CHANGELOG.md').toString()

lastestVersion = do ->
result = changelogs.match /## V(\d+\.\d+\.\d+)/

if result and result.length > 1
result[1]
else
null

latestContent = do ->
re = new RegExp "## V#{lastestVersion.replace('.', '\\.')}\
.+\\n\\n((?:\\* .*\\n)+)"
result = changelogs.match re

if result and result.length > 1
result[1]
else
null

module.exports =
lastestVersion: lastestVersion
latestContent: latestContent
18 changes: 18 additions & 0 deletions build/helpers/coffee.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
gutil = require 'gulp-util'
through = require 'through2'
coffee = require 'coffee-script'
handleError = require './error'

module.exports = (opts) ->
through.obj (file, encoding, done) ->
str = file.contents.toString()

try
result = coffee.compile str, opts
catch e
handleError e, @

file.contents = new Buffer result
file.path = gutil.replaceExtension file.path, '.js'
@push file
done()
20 changes: 20 additions & 0 deletions build/helpers/coffeelint.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
through = require 'through2'
coffeelint = require 'coffeelint'
Reporter = require 'coffeelint/lib/reporters/default'
configFinder = require 'coffeelint/lib/configfinder'
handleError = require './error'

module.exports = ->
through.obj (file, encoding, done) ->
opts = configFinder.getConfig()
errorReport = coffeelint.getErrorReport()
errorReport.lint file.relative, file.contents.toString(), opts

summary = errorReport.getSummary()
if summary.errorCount > 0 || summary.warningCount > 0
reporter = new Reporter errorReport
reporter.publish()
handleError 'coffeelint failed with errors or warnings', @

@push file
done()
8 changes: 8 additions & 0 deletions build/helpers/data.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
through = require 'through2'
_ = require 'lodash'

module.exports = (data) ->
through.obj (file, encoding, done) ->
file.data = if _.isFunction(data) then data(file) else data
@push file
done()
13 changes: 13 additions & 0 deletions build/helpers/error.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
gutil = require 'gulp-util'

module.exports = (error, stream) ->
if stream
opts = if typeof error == 'string'
{}
else
stack: error.stack
showStack: !!error.stack

stream.emit 'error', new gutil.PluginError 'gulp-build', error, opts
else
gutil.log gutil.colors.red("gulp-build error: #{error.message || error}")
Loading

0 comments on commit a682641

Please sign in to comment.