Skip to content

Commit

Permalink
update README.md, support init command
Browse files Browse the repository at this point in the history
  • Loading branch information
zmmbreeze committed Jan 13, 2013
1 parent da0ddb4 commit 441ef1f
Show file tree
Hide file tree
Showing 52 changed files with 745 additions and 235 deletions.
20 changes: 20 additions & 0 deletions MIT-LICENTSE.txt
@@ -0,0 +1,20 @@
Copyright (c) 2013 mzhou, http://mzhou.me/

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.
44 changes: 35 additions & 9 deletions README.md
@@ -1,11 +1,37 @@
**blogin** is A simple static blog framework, powered by Node.js. **blogin** is A simple static blog framework, powered by Node.js.


Usage: How to install

---
deploy Generate static files and deploy to github. 1. Install [node.js](http://nodejs.org/) and [npm](https://npmjs.org/).
server Start a server on http://localhost:3000 . 2. `npm install -g blogin`
update Generate the static files. 3. `blogin init blogdir`
post New post. 4. `cd blogdir`
page New page. 4. `blogin update`
init Init the project directory. 5. `blogin server`
help Display help. 6. Open `http://127.0.0.1:3000` in browser.

Create post
---
1. `blogin post this is my first post`
2. Then edit "blogindir/data/posts/2013/this-is-my-first-post.md". Blogin use markdown format to write blog.
3. `blogin update`
4. `blogin server`

Usage
---
blogin command:

deploy Generate static files and deploy to git server, like github.
server Start a server on http://localhost:3000 .
update Generate the static files.
post Create post.
page Create page.
init Init the project directory.
help Display help.

Custom theme
---
Edit the file at "blogindir/public/" to custom your own theme.


Please feel free to use blogin.
4 changes: 2 additions & 2 deletions lib/command.coffee
Expand Up @@ -19,5 +19,5 @@ module.exports =
page: (args) -> page: (args) ->
require('./page.js')(args) require('./page.js')(args)
init: (args) -> init: (args) ->
util.puts('This methods was not implemented') require('./init')(args)

#util.puts('This methods was not implemented')
2 changes: 1 addition & 1 deletion lib/command.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/deploy.coffee
Expand Up @@ -21,6 +21,7 @@ module.exports = (args) ->
arg = parseArg(args) arg = parseArg(args)
projectDir = path.resolve(process.cwd(), arg.req[0] || './') projectDir = path.resolve(process.cwd(), arg.req[0] || './')
if not MyUtil.checkProjectDir(projectDir) if not MyUtil.checkProjectDir(projectDir)
usage.puts('deploy')
return return


exec 'git', ['add', '-A'], () => exec 'git', ['add', '-A'], () =>
Expand Down
1 change: 1 addition & 0 deletions lib/deploy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 20 additions & 3 deletions lib/file.coffee
Expand Up @@ -57,10 +57,27 @@ exports.writeIfNotExist = (src, content) ->
return true return true
else else
return false return false
###
src: '/home/user/a'
dest: '/home/user/b'
force: true
###
copy = exports.copy = (src, dest, force) ->
destExist = fs.existsSync(dest)
if not force and destExist
return false


copy = exports.copy = (src, dest) -> if fs.statSync(src).isDirectory()
content = read(src) # mkdir
write(dest, content) if not destExist
mkdir(dest)
# copy child
fs.readdirSync(src).forEach (filename, i) =>
copy(path.resolve(src, filename), path.resolve(dest, filename), force)
else
fs.createReadStream(src).pipe(fs.createWriteStream(dest))

return true


readJSON = exports.readJSON = (src) -> readJSON = exports.readJSON = (src) ->
content = read(src) content = read(src)
Expand Down
29 changes: 25 additions & 4 deletions lib/file.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions lib/init.coffee
@@ -0,0 +1,58 @@
path = require('path')
moment = require('moment')
util = require('util')
parseArg = require('./arg').parse
MyUtil = require('./MyUtil')
usage = require('./usage')
file = require('./file')

projectDir = './'

module.exports = (args) ->
arg = parseArg(args)
projectDir = path.resolve(process.cwd(), arg.req[0] || './')

if file.copy(path.resolve(__dirname, '../prototype/'), projectDir)
util.puts('Blog created at "' + projectDir + '".')
else
util.puts('Directory "' + projectDir + '" existed!')
util.puts('Still create blog? (Y/N)')
process.stdin.resume();
process.stdin.setEncoding('utf8');

yesCallback = () ->
file.copy(path.resolve(__dirname, '../prototype/'), projectDir, true)
util.puts('Blog created at "' + projectDir + '".')
util.puts('Init complete.')
process.exit()

noCallback = () ->
process.exit()

callback = () ->
util.puts('Please input Y/N.')
process.exit()

process.stdin.on 'data', (chunk) =>
if chunk[chunk.length - 1] isnt '\n'
callback()
return
switch chunk.slice(0, -1)
when 'Y'
yesCallback()
when 'y'
yesCallback()
when 'yes'
yesCallback()
when 'YES'
yesCallback()
when 'N'
noCallback()
when 'n'
noCallback()
when 'no'
noCallback()
when 'NO'
noCallback()
else
callback()
69 changes: 69 additions & 0 deletions lib/init.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 14 additions & 9 deletions lib/usage.coffee
Expand Up @@ -2,23 +2,23 @@ util = require('util')
clc = require('cli-color') clc = require('cli-color')
# command description # command description
commandsDesc = commandsDesc =
deploy: 'Generate static files and deploy to github.' deploy: 'Deploy static files to git server, like github.'
server: 'Start a server on http://localhost:3000 .' server: 'Start a server on http://localhost:3000 .'
update: 'Generate the static files.' update: 'Generate the static files.'
post: 'New post.' post: 'Create post.'
page: 'New page.' page: 'Create page.'
init: 'Init the project directory.' init: 'Init the blog directory.'
help: 'Display help.' help: 'Display help.'
#command usage #command usage
commandsUsage = commandsUsage =
deploy: 'Generate static files and deploy to github.' deploy: ''
server: 'Start a server on http://localhost:3000 .' server: 'Start a server on http://localhost:3000 .'
update: update:
''' '''
[-q] [project directory] [-q] [blog directory]
[-q] Use quiet mod, do not print log. [-q] Use quiet mod, do not print log.
[project directory] If not set directory then use current directory. [blog directory] If not set directory then use current directory.
''' '''
post: post:
''' '''
Expand All @@ -33,7 +33,12 @@ commandsUsage =
-f Force to rewrite exist file. -f Force to rewrite exist file.
''' '''
init: 'Init the project directory.' init:
'''
[blog directory]
[blog directory] If not set directory then use current directory.
'''
# create space to display # create space to display
createSpace = (command, maxLength) -> createSpace = (command, maxLength) ->
spaceLength = maxLength - command.length spaceLength = maxLength - command.length
Expand Down
14 changes: 7 additions & 7 deletions lib/usage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions prototype/blogin.json
@@ -1,9 +1,9 @@
{ {
"name": "Blogin's blog", "name": "[Blog name]",
"description": "A static blog base on blogin.", "description": "[Blog description]",
"keywords": "website,blog,framework,static,blogin", "keywords": "[Blog keyowrds]",
"author": "MZhou / @zhoumm", "author": "[Your name]",
"email": "zmmbreeze0825@gmail.com", "email": "[Blog email]",
"siteUrl": "http://nodejs.in", "siteUrl": "http://nodejs.in",
"favicon": "https://github.com//favicon.ico" "favicon": "https://github.com//favicon.ico"
} }

0 comments on commit 441ef1f

Please sign in to comment.