Skip to content

Commit 556c4b3

Browse files
committed
"flatten" shortcut mostly intended for CLI usage
1 parent d25dbd9 commit 556c4b3

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ gulp.src('foo.js')
100100
* `isonline` (boolean) lets you set the uploaded files to be avaliable
101101
without login.
102102

103+
* `flatten` all files are uploaded to the root path, regardless of their source path.
104+
103105
## nscabinet.download( files , [opts] )
104106

105107
```javascript
@@ -173,7 +175,7 @@ Uploading Views/view.html to /SuiteScripts
173175

174176
- If you add new funcionality, also add a new test!
175177

176-
At the time tests are ran locally. To set up the tests:
178+
At the time tests are run locally. To set up the tests:
177179

178180
- Install the restlet in an available account;
179181

@@ -184,7 +186,7 @@ At the time tests are ran locally. To set up the tests:
184186

185187

186188

187-
[npm-url]: https://npmjs.org/package/nscabinet
189+
[npm-url]: https://npmjs.org/package/nscabinet
188190
[npm-image]: http://img.shields.io/npm/v/nscabinet.svg
189191

190192
[david-url]: https://david-dm.org/suiteplus/nscabinet

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nscabinet",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "Upload and download files from netsuite.",
55
"engines": {
66
"node": ">=4.x",

src/cli.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var yarr = require('yargs')
1919
.describe('role')
2020
.describe('script','Script id.')
2121
.describe('deployment','Deployment id.')
22+
.describe('flatten')
2223
.argv;
2324

2425
var cabinet = require('./nscabinet.js'),

src/nscabinet.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ var PARAMS_DEF = [
1313
{name: 'script', required : true },
1414
{name: 'deployment', def: 1},
1515
{name: 'isCLI', def : false },
16-
{name: 'isonline', def : false}
16+
{name: 'isonline', def : false} ,
17+
{name: 'flatten', def : false}
1718
];
1819

1920

@@ -32,6 +33,10 @@ function upload (params) {
3233
fullCwd = path.resolve((params.isCLI) ? nsconfig.CONF_CWD : chunk.cwd),
3334
remotePath = chunk.path.substr(fullCwd.length+1);
3435

36+
if (params.flatten) {
37+
remotePath = path.basename(remotePath);
38+
}
39+
3540
console.log('Uploading ' + remotePath + ' to ' + params.rootPath );
3641

3742
var toRequest = _requestOpts(params);
@@ -73,6 +78,7 @@ function download (files,params,info) {
7378
function flush(cb) {
7479
var data = JSON.parse(buffer);
7580
if (data.error) {
81+
if (!data.error.length) data.error = [data.error];
7682
data.error = data.error.map( err => {
7783
try {
7884
return JSON.parse(err);

test/nscabinet-test.js

+17
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,21 @@ describe('nscabinet:', function() {
157157
})
158158
})
159159

160+
161+
it('Flatten.' , done => {
162+
fs.mkdirSync('test/_input/flatten');
163+
fs.writeFileSync('test/_input/flatten/flatten.txt', randContent());
164+
vinyl.src('test/_input/flatten/*.*')
165+
.pipe(nscabinet.upload({
166+
flatten : true
167+
}))
168+
.on('finish' , () => {
169+
nscabinet.download('flatten.txt').pipe(vinyl.dest('test/_output'))
170+
.on('finish' , () => {
171+
should(fs.existsSync('test/_output/flatten.txt')).be.true();
172+
done();
173+
})
174+
})
175+
})
176+
160177
});

0 commit comments

Comments
 (0)