mirror of
https://github.com/sismics/docs.git
synced 2024-11-21 21:47:57 +01:00
Closes #188: Quiet mode for the file importer
This commit is contained in:
parent
1479b818ea
commit
2771e56357
3
.gitignore
vendored
3
.gitignore
vendored
@ -11,3 +11,6 @@
|
|||||||
*.iml
|
*.iml
|
||||||
node_modules
|
node_modules
|
||||||
import_test
|
import_test
|
||||||
|
docs-importer-linux
|
||||||
|
docs-importer-macos
|
||||||
|
docs-importer-win.exe
|
@ -17,6 +17,11 @@ docs-importer-win.exe (for Windows)
|
|||||||
|
|
||||||
A wizard will ask you for the import configuration and write it in `~/.config/preferences/com.sismics.docs.importer.pref`
|
A wizard will ask you for the import configuration and write it in `~/.config/preferences/com.sismics.docs.importer.pref`
|
||||||
|
|
||||||
|
For the next start, pass the `-d` argument to skip the wizard:
|
||||||
|
```console
|
||||||
|
./docs-importer-linux -d
|
||||||
|
```
|
||||||
|
|
||||||
Daemon mode
|
Daemon mode
|
||||||
-----------
|
-----------
|
||||||
The daemon mode scan the input directory every 30 seconds for new files. Once a file is found and imported, it is **deleted**.
|
The daemon mode scan the input directory every 30 seconds for new files. Once a file is found and imported, it is **deleted**.
|
||||||
|
@ -5,6 +5,7 @@ const ora = require('ora');
|
|||||||
const inquirer = require('inquirer');
|
const inquirer = require('inquirer');
|
||||||
const preferences = require('preferences');
|
const preferences = require('preferences');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const argv = require('minimist')(process.argv);
|
||||||
const request = require('request').defaults({
|
const request = require('request').defaults({
|
||||||
jar: true
|
jar: true
|
||||||
});
|
});
|
||||||
@ -55,7 +56,6 @@ const askBaseUrl = () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
askBaseUrl();
|
|
||||||
|
|
||||||
// Ask for credentials
|
// Ask for credentials
|
||||||
const askCredentials = () => {
|
const askCredentials = () => {
|
||||||
@ -162,12 +162,29 @@ const askDaemon = () => {
|
|||||||
// Save daemon
|
// Save daemon
|
||||||
prefs.importer.daemon = answers.daemon;
|
prefs.importer.daemon = answers.daemon;
|
||||||
|
|
||||||
|
// Save all preferences in case the program is sig-killed
|
||||||
|
prefs.save();
|
||||||
|
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Start the import
|
// Start the importer
|
||||||
const start = () => {
|
const start = () => {
|
||||||
|
request.post({
|
||||||
|
url: prefs.importer.baseUrl + '/api/user/login',
|
||||||
|
form: {
|
||||||
|
username: prefs.importer.username,
|
||||||
|
password: prefs.importer.password,
|
||||||
|
remember: true
|
||||||
|
}
|
||||||
|
}, function (error, response) {
|
||||||
|
if (error || !response || response.statusCode !== 200) {
|
||||||
|
console.error('\nUsername or password incorrect');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the actual import
|
||||||
if (prefs.importer.daemon) {
|
if (prefs.importer.daemon) {
|
||||||
console.log('\nPolling the input folder for new files...');
|
console.log('\nPolling the input folder for new files...');
|
||||||
|
|
||||||
@ -180,6 +197,7 @@ const start = () => {
|
|||||||
} else {
|
} else {
|
||||||
importFiles(false, () => {});
|
importFiles(false, () => {});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Import the files
|
// Import the files
|
||||||
@ -228,3 +246,15 @@ const importFile = (file, remove, resolve) => {
|
|||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Entrypoint: daemon mode or wizard
|
||||||
|
if (argv.hasOwnProperty('d')) {
|
||||||
|
console.log('Starting in quiet mode with the following configuration:\n' +
|
||||||
|
'Base URL: ' + prefs.importer.baseUrl + '\n' +
|
||||||
|
'Username: ' + prefs.importer.username + '\n' +
|
||||||
|
'Password: ***********\n' +
|
||||||
|
'Daemon mode: ' + prefs.importer.daemon);
|
||||||
|
start();
|
||||||
|
} else {
|
||||||
|
askBaseUrl();
|
||||||
|
}
|
15
docs-importer/package-lock.json
generated
15
docs-importer/package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "docs-importer",
|
"name": "docs-importer",
|
||||||
"version": "1.0.0",
|
"version": "1.5.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -476,9 +476,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "0.0.8",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
||||||
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
|
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
|
||||||
},
|
},
|
||||||
"mkdirp": {
|
"mkdirp": {
|
||||||
"version": "0.5.1",
|
"version": "0.5.1",
|
||||||
@ -486,6 +486,13 @@
|
|||||||
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
||||||
"requires": {
|
"requires": {
|
||||||
"minimist": "0.0.8"
|
"minimist": "0.0.8"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"minimist": {
|
||||||
|
"version": "0.0.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
|
||||||
|
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mute-stream": {
|
"mute-stream": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "docs-importer",
|
"name": "docs-importer",
|
||||||
"version": "1.0.0",
|
"version": "1.5.1",
|
||||||
"description": "Import files to Sismics Docs",
|
"description": "Import files to Sismics Docs",
|
||||||
"bin": "main.js",
|
"bin": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -18,6 +18,7 @@
|
|||||||
"homepage": "https://github.com/sismics/docs#readme",
|
"homepage": "https://github.com/sismics/docs#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"inquirer": "^5.1.0",
|
"inquirer": "^5.1.0",
|
||||||
|
"minimist": "^1.2.0",
|
||||||
"ora": "^2.0.0",
|
"ora": "^2.0.0",
|
||||||
"preferences": "^1.0.2",
|
"preferences": "^1.0.2",
|
||||||
"recursive-readdir": "^2.2.2",
|
"recursive-readdir": "^2.2.2",
|
||||||
|
Loading…
Reference in New Issue
Block a user