Skip to content

Commit f87eb6e

Browse files
committed
updating readme
1 parent 43b1585 commit f87eb6e

File tree

11 files changed

+92
-26
lines changed

11 files changed

+92
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ node_modules/
1414
/dist/
1515

1616
## only ignore in git
17+
.henkrc

package-lock.json

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"chai": "^4.2.0",
2525
"commander": "^2.19.0",
2626
"fs-extra": "^7.0.1",
27+
"glob-promise": "^3.4.0",
2728
"inquirer": "^6.2.2",
2829
"mocha": "^6.0.2",
2930
"opener": "^1.5.1",

src/index.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ module.exports = async (data = {}, cli) => {
6464
{ name: 'Mediamonks Preview', value: 'mm-preview' },
6565
{ name: 'Amazon S3', value: 's3' },
6666
{ name: 'FTP (alpha)', value: 'ftp' },
67+
{ name: 'SFTP (alpha)', value: 'sftp' },
6768
{ name: 'Netflix Monet', value: 'monet', disabled: true },
6869
{ name: 'Google DoubleClick Studio', value: 'doubleclick', disabled: true },
6970
],
@@ -73,7 +74,7 @@ module.exports = async (data = {}, cli) => {
7374
const target = targets[data.type];
7475

7576
if (!target) {
76-
throw new Error(`inknown target ${data.type}`);
77+
throw new Error(`unknown target ${data.type}`);
7778
}
7879

7980
data = await conditionalPrompt(data, {
@@ -93,19 +94,5 @@ module.exports = async (data = {}, cli) => {
9394

9495
await target.action(data);
9596

96-
console.log(`
97-
+hho.
98-
-MMMMm
99-
.dMMMMm
100-
\`oNMMMMM/\`\`\`\`
101-
\`\`\`\`\`\` ./dMMMMMMNmmmmdh:
102-
dmmmmm//mMMMMMMMMMMMMMMMN
103-
MMMMMMooMMMMMMMMMMMMMMMMo
104-
MMMMMMooMMMMMMMMMMMMMMMM:
105-
MMmmMMooMMMMMMMMMMMMMMMd
106-
MM//MMooMMMMMMMMMMMMMMM/
107-
hddddd::dmMMMMMMMMMMMMh
108-
\`-/oyhhddhy+\`
109-
110-
`);
97+
console.log(`Done, Have a nice day.`);
11198
};

src/target/mm-preview.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ const preview = {
3939
type: 'input',
4040
name: 'outputDir',
4141
description: 'Please fill in the target directory:',
42-
default: () => {
43-
return `${uuid()}/`
44-
},
42+
default: () => `${uuid()}/`,
4543
validate: validateNotEmpty,
4644
errorMessage: 'Missing target ',
4745
required: true,

src/target/s3.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,20 @@ module.exports = {
3030
errorMessage: 'Missing secretAccessKey',
3131
required: true,
3232
},
33-
3433
{
3534
type: 'input',
3635
name: 'outputDir',
3736
description: 'Please fill in the target directory:',
3837
validate: validateNotEmpty,
39-
errorMessage: 'Missing target ',
38+
errorMessage: 'Missing outputDir',
4039
required: true,
4140
},
4241
],
4342
async action(data) {
4443
validateActionInput(data, this.questions);
4544

4645
await new Uploader({
47-
config: './.previewsrc', // can also use environment variables
46+
config: './.henkrc', // can also use environment variables
4847
bucket: data.bucket,
4948
localPath: `${data.inputDir}`,
5049
remotePath: `${data.outputDir}`,

src/target/sftp.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ const validateActionInput = require('../util/validateActionInput');
22
const validateNotOutsideWorkingDir = require('../util/validate/validateNotOutsideWorkingDir');
33
const validateNotEmpty = require('../util/validate/validateNotEmpty');
44
const Client = require('ssh2-sftp-client');
5+
const glob = require('glob-promise');
6+
const path = require('path');
7+
const isFile = require('../util/isFile');
8+
const ProgressBar = require('progress');
59

610
module.exports = {
711
questions: [
@@ -55,9 +59,40 @@ module.exports = {
5559
secure: data.secure,
5660
});
5761

58-
const fileList = await sftp.list('./');
62+
try {
63+
await sftp.mkdir(data.outputDir, true);
64+
} catch (e) {}
65+
66+
if (/\*/.test(data.inputDir)) {
67+
throw new Error('Globbing pattern is not allowed');
68+
}
69+
70+
const inputDir = path.join(data.inputDir, '**/*');
71+
const files = await glob(inputDir);
72+
73+
const bar = new ProgressBar('[:bar] :percent | :etas | :current / :total | :rate/fps ', {
74+
total: files.length,
75+
complete: '=',
76+
incomplete: ' ',
77+
width: 20,
78+
});
79+
80+
const relativeFiles = files.map(file => path.relative(data.inputDir, file));
81+
for (let i = 0; i < relativeFiles.length; i++) {
82+
const inputFilePath = files[i];
83+
const outputFilePath = path.join(data.outputDir, relativeFiles[i]);
84+
85+
if(!(await isFile(inputFilePath))){
86+
try {
87+
await sftp.mkdir(outputFilePath, true);
88+
} catch (e) {}
89+
} else {
90+
await sftp.fastPut(inputFilePath, outputFilePath);
91+
}
92+
93+
bar.tick();
94+
}
5995

60-
console.log(fileList);
6196
} catch (err) {
6297
console.log(err);
6398
}

src/util/conditionalPrompt.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ module.exports = async function conditionalPrompt(data, questions) {
1414
// check if data is already there, or validate with validator if validate is there.
1515
if (
1616
data[question.name] === undefined ||
17-
(question.validate && question.validate(data[question.name]) !== true )
17+
(question.validate && question.validate(data[question.name]) !== true)
1818
) {
19-
if(data[question.name] !== undefined && (question.validate && question.validate(data[question.name]) !== true)){
19+
// show message
20+
if (
21+
data[question.name] !== undefined &&
22+
(question.validate && question.validate(data[question.name]) !== true)
23+
) {
2024
console.log(error(question.validate(data[question.name])));
2125
}
2226

src/util/isFile.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const fs = require('fs');
2+
module.exports = function isFile(path) {
3+
return new Promise(resolve => {
4+
fs.lstat(path, (err, stats) => {
5+
resolve(stats.isFile());
6+
});
7+
});
8+
};

test/files/test.js

Whitespace-only changes.

0 commit comments

Comments
 (0)