Skip to content

Commit 4908842

Browse files
author
Willian Krueger
committed
CLI WIP before merge
1 parent 1ce39ea commit 4908842

File tree

6 files changed

+79
-5
lines changed

6 files changed

+79
-5
lines changed

CHANGELOG.MD

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
77
## 0.2.x
88

99
* `nscabinet.download`
10-
10+
11+
## 0.3.x
12+
13+
* CLI

README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,22 @@ The following priority is taken for each parameter (using `_.extend`)
7676

7777

7878
[npm-url]: https://npmjs.org/package/nscabinet
79-
[npm-image]: http://img.shields.io/npm/v/nscabinet.svg
79+
[npm-image]: http://img.shields.io/npm/v/nscabinet.svg
80+
81+
82+
## CLI
83+
84+
npm install -g nscabinet
85+
86+
```bash
87+
$ nscabinet u file.txt --rootpath /SuiteScripts/MyProject
88+
$ nscabinet u file.txt -p /SuiteScripts/MyProject
89+
$ nscabinet u file.txt
90+
$ nscabinet d remote.txt --rootPath /Downloads
91+
$ nscabinet d remote.txt -p /Downloads
92+
$ nscabinet d remote.txt
93+
```
94+
95+
Takes in the same arguments (lowercased).
96+
97+
As usual, the arguments are defaulted from `nsconfig.json`.

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"npm": ">=2.1.5"
88
},
99
"main": "src/nscabinet.js",
10+
"bin": {
11+
"nscabinet": "./src/cli.js"
12+
},
1013
"scripts": {
1114
"test": "mocha"
1215
},
@@ -41,6 +44,7 @@
4144
"osenv": "^0.1.3",
4245
"request": "^2.64.0",
4346
"through2": "^2.0.0",
44-
"vinyl-fs": "^2.1.1"
47+
"vinyl-fs": "^2.1.1",
48+
"yargs": "^3.26.0"
4549
}
4650
}

restlet/nscabinet-restlet.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ var post = function (datain) {
1313

1414
//ROUTER
1515

16+
log(datain)
17+
1618
switch(datain.action) {
1719
case 'download':
1820
return download(datain)
@@ -36,7 +38,7 @@ var upload = function(datain) {
3638
file.setFolder(info.folderid)
3739
var r = JSON.stringify(nlapiSubmitFile(file))
3840
nlapiLogExecution('ERROR', 'up!', r)
39-
return {message: 'Uploaded to file id ' + r, fileid: Number(r)}
41+
return {message: 'Uploaded ' + info.filename + ' to file id ' + r , fileid: Number(r)}
4042
}
4143

4244
}

src/cli.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var yarr = require('yargs')
2+
.usage('Usage: nscabinet <command> <file> [options]')
3+
.command('u','Upload.')
4+
.command('d','Download.')
5+
.demand(1)
6+
.demand(2)
7+
//.describe('config','Point to a nsconfig.json file.')
8+
.describe('rootpath','Netsuite origin path.')
9+
.alias('rootpath','p')
10+
.describe('email','Account email.')
11+
.describe('password','Account password.')
12+
.describe('account','Account id.')
13+
.describe('realm','*.netsuite.com')
14+
.describe('role')
15+
.describe('script','Script id.')
16+
.describe('deployment','Deployment id.')
17+
.argv
18+
19+
var cabinet = require('./nscabinet.js'),
20+
vinylfs = require('vinyl-fs')
21+
22+
var action = yarr._[0],
23+
file = yarr._[1]
24+
25+
26+
27+
var opts = {}
28+
29+
for (var it in yarr) {
30+
if (yarr[it] !== undefined) opts[it] = yarr[it]
31+
}
32+
if (opts.rootpath) opts.rootPath = opts.rootpath
33+
34+
if ( action == 'u' ) {
35+
36+
vinylfs.src(file).pipe(cabinet(opts))
37+
38+
} else if ( action == 'd' ) {
39+
40+
cabinet.download(file,opts).pipe(vinylfs.dest('.'))
41+
42+
}
43+
44+
process.on('exit' , () => { console.log('\n') })

src/nscabinet.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ out.download = (files,params) => {
7373
contents : new Buffer(file.contents,'base64')
7474
})
7575

76+
console.log(`Got file ${file.path}.`)
77+
7678
this.emit('data',vynFile)
7779

7880
})
@@ -84,6 +86,7 @@ out.download = (files,params) => {
8486
)
8587

8688
return request( toRequest )
89+
.pipe(es.split())
8790
.pipe(es.parse())
8891
.pipe(emitter)
8992

@@ -109,4 +112,4 @@ function requestOpts(params) {
109112
}
110113
}
111114

112-
}
115+
}

0 commit comments

Comments
 (0)