Skip to content

Commit

Permalink
Lot of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrancois committed Mar 30, 2016
1 parent f35b0c1 commit d9e901c
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 459 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- "0.10"
- "4.4.1"
after_script: NODE_ENV=test istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Jsio.js


![Npm Version](https://img.shields.io/npm/v/jsiojs.svg)
![Power](https://img.shields.io/badge/power-%E2%88%9E-green.svg)
![Licence](https://img.shields.io/npm/l/jsiojs.svg)
![Node Required](https://img.shields.io/node/v/jsiojs.svg)
![Npm Version](https://img.shields.io/npm/v/jsiojs.svg)
[![Build Status](https://travis-ci.org/nfrancois/jsio.js.svg?branch=master)](https://travis-ci.org/nfrancois/jsio.js)
[![Code Climate](https://codeclimate.com/github/nfrancois/jsio.js/badges/gpa.svg)](https://codeclimate.com/github/nfrancois/jsio.js)
[![Coverage Status](https://coveralls.io/repos/nfrancois/jsio.js/badge.svg)](https://coveralls.io/r/nfrancois/jsio.js)
Expand Down
64 changes: 32 additions & 32 deletions bin/jsio.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,58 +10,58 @@ program.version("42.0.0")
program
.command("create [filename]")
.description("Create a new js file")
.action(function(filename){
jsiojs.createFile(filename).then(function(){
success('File '+filename+' created with success !')
}).fail(fail)
});
.action((filename) =>
jsiojs
.createFile(filename)
.then(() => success(`File '${filename}' created with success !`))
.fail(fail)
)

program
.command("delete [filename]")
.description("Delete a js file")
.action(function(filename){
jsiojs.deleteFile(filename).then(function(){
success('File '+filename+' deleted with success !')
}).fail(fail)
});
.action((filename) =>
jsiojs
.deleteFile(filename)
.then(() => success(`File '${filename}' deleted with success !`))
.fail(fail)
)

program
.command("rename [oldname] [newname]")
.description("Rename a js file")
.action(function(oldname, newname) {
jsiojs.renameFile(oldname, newname).then(function(){
success('File '+oldname+' moved to '+newname+' with success !')
}).fail(fail)
})
.action((oldname, newname) =>
jsiojs
.renameFile(oldname, newname)
.then(() => success(`File '${oldname}' moved to '${newname}' with success !`))
.fail(fail)
)

program
.command("copy [source] [destination]")
.description("Copy a js file")
.action(function(source, destination) {
jsiojs.copyFile(source, destination).then(function(){
success('File '+source+' copied to '+destination+' with success !')
}).fail(fail)
})
.action((source, destination) =>
jsiojs
.copyFile(source, destination)
.then(() => success(`File '${source}' copied to '${destination}' with success !`))
.fail(fail)
)

program
.command("show [filename]")
.description("Show a js file")
.action(function(filename) {
jsiojs.showFile(filename).then(function(content){
console.info(content)
}).fail(fail)
})
.action((filename) =>
jsiojs
.showFile(filename)
.then((content) => console.info(content))
.fail(fail)
)

program.parse(process.argv)

if (!process.argv.slice(2).length) {
program.outputHelp();
}

function success(message){
console.info(message .green)
}

function fail(message){
console.error(message .red)
}
function success(message){ console.info(message .green) }
function fail(message) { console.error(message .red) }
8 changes: 6 additions & 2 deletions example/tonic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
var jsiojs = require("jsiojs")
// Start of my wonderfull project
jsiojs.createFile("wonderful.js")
// Oh my god, the file contains a typo. I should fix !
jsiojs.renameFile("wonderful.js", "wonderfull.js")
.then(function(){
// Oh my god, the file contains a typo. I should fix !
return jsiojs.renameFile("wonderful.js", "wonderfull.js")
}).then(function(){
console.log("Ready for a wonderfull project !")
})
115 changes: 36 additions & 79 deletions lib/jsiojs_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,112 +6,69 @@ var Q = require("q");

var exports = module.exports = {};

exports.createFile = function(filename){
return Q()
.then(function(){
return checkJsFile(filename)
})
.then(function(){
return checkFileNotExist(filename)
})
.then(function(){
return FS.write(filename, '// Generated by JsIo.js\n')
});
}
exports.createFile = (filename) =>
Q()
.then(() => checkJsFile(filename))
.then(() => checkFileNotExist(filename))
.then(() => FS.write(filename, '// Generated by JsIo.js\n'))

exports.deleteFile = function(filename){
return Q()
.then(function(){
return checkJsFile(filename)
})
.then(function(){
return checkFileExist(filename)
})
.then(function(){
return FS.remove(filename)
})
}
exports.deleteFile = (filename) =>
Q()
.then(() => checkJsFile(filename))
.then(() => checkFileExist(filename))
.then(() => FS.remove(filename))

exports.renameFile = function(oldname, newname){
return Q()
.then(function(){
return checkJsFile(oldname)
})
.then(function(){
return checkJsFile(newname)
})
.then(function(){
return checkFileExist(oldname)
})
.then(function(){
return checkFileNotExist(newname)
})
.then(function(){
return FS.rename(oldname, newname)
})
}
exports.renameFile = (oldname, newname) =>
Q()
.then(() => checkJsFile(oldname))
.then(() => checkJsFile(newname))
.then(() => checkFileExist(oldname))
.then(() => checkFileNotExist(newname))
.then(() => FS.rename(oldname, newname))

exports.copyFile = function(source, destination){
return Q()
.then(function(){
return checkJsFile(source)
})
.then(function(){
return checkJsFile(destination)
})
.then(function(){
return checkFileExist(source)
})
.then(function(){
return checkFileNotExist(destination)
})
.then(function(){
return FS.copy(source, destination)
})
}
exports.copyFile = (source, destination) =>
Q()
.then(() => checkJsFile(source))
.then(() => checkJsFile(destination))
.then(() => checkFileExist(source))
.then(() => checkFileNotExist(destination))
.then(() => FS.copy(source, destination))

exports.showFile = function(filename){
return Q()
.then(function(){
return checkJsFile(filename)
})
.then(function(){
return checkFileExist(filename)
})
.then(function(){
return FS.read(filename, "r")
})
}
exports.showFile = (filename) =>
Q()
.then(() => checkJsFile(filename))
.then(() => checkFileExist(filename))
.then(() => FS.read(filename, "r"))

function checkJsFile(filename){
var deferred = Q.defer()
if(filename === undefined) {
deferred.reject("file name is missing")
deferred.reject("filename is missing")
} else if(filename.length < 4 || filename.substring(filename.length-3) !== ".js"){
deferred.reject(filename+" is not a valid javascript file name")
deferred.reject(`'${filename}' is not a valid javascript filename`)
} else {
deferred.resolve()
}
return deferred.promise
}
}

function checkFileExist(filename){
var deferred = Q.defer();
FS.exists(filename).then(function(result){
FS.exists(filename).then((result) => {
if(result){
deferred.resolve()
} else {
deferred.reject(filename+" does not exist")
deferred.reject(`'${filename}' does not exist`)
}
})
return deferred.promise
}

function checkFileNotExist(filename){
var deferred = Q.defer();
FS.exists(filename).then(function(result){
FS.exists(filename).then((result) => {
if(result){
deferred.reject(filename+" already exists")
deferred.reject(`'${filename}' already exists`)
} else {
deferred.resolve()
}
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"jsiojs": "./bin/jsio.js"
},
"engines": {
"node": ">= 0.10.0"
"node": ">= 4.4.1"
},
"dependencies": {
"colors" : "~1.1.2",
Expand All @@ -39,10 +39,11 @@
"q-io": "~1.13.2 "
},
"devDependencies": {
"mocha": "~1.17.1",
"chai": "~2.2.0",
"coveralls": "~2.11.2",
"istanbul": "~0.3.1"
"mocha": "~2.4.5",
"chai": "~3.5.0",
"chai-as-promised": "~5.3.0",
"coveralls": "~2.11.9",
"istanbul": "~0.4.2"
},
"tonicExampleFilename": "example/tonic.js"
}
Loading

0 comments on commit d9e901c

Please sign in to comment.