create app dir if not exists

This commit is contained in:
Kyle Spearrin 2018-05-16 21:38:45 -04:00
parent fc63fd32c8
commit b425b6f509
4 changed files with 37 additions and 22 deletions

13
package-lock.json generated
View File

@ -34,6 +34,15 @@
"integrity": "sha512-esk3CG25hRtHsVHm+LOjiSFYdw8be3uIY653WUwR43Bro914HSimPgPpqgajkhTJ0awK3RQfaIxP7zvbtCpcyg==", "integrity": "sha512-esk3CG25hRtHsVHm+LOjiSFYdw8be3uIY653WUwR43Bro914HSimPgPpqgajkhTJ0awK3RQfaIxP7zvbtCpcyg==",
"dev": true "dev": true
}, },
"@types/mkdirp": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/@types/mkdirp/-/mkdirp-0.5.2.tgz",
"integrity": "sha512-U5icWpv7YnZYGsN4/cmh3WD2onMY0aJIiTE6+51TwJCttdHvtCYmkBNOobHlXwrJRL0nkH9jH4kD+1FAdMN4Tg==",
"dev": true,
"requires": {
"@types/node": "10.0.8"
}
},
"@types/node": { "@types/node": {
"version": "10.0.8", "version": "10.0.8",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.0.8.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.0.8.tgz",
@ -3102,7 +3111,6 @@
"version": "0.5.1", "version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"dev": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
}, },
@ -3110,8 +3118,7 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
"dev": true
} }
} }
}, },

View File

@ -47,6 +47,7 @@
"@types/commander": "^2.12.2", "@types/commander": "^2.12.2",
"@types/lowdb": "^1.0.1", "@types/lowdb": "^1.0.1",
"@types/lunr": "^2.1.5", "@types/lunr": "^2.1.5",
"@types/mkdirp": "^0.5.2",
"@types/node": "^10.0.8", "@types/node": "^10.0.8",
"@types/node-forge": "^0.7.1", "@types/node-forge": "^0.7.1",
"@types/readline-sync": "^1.4.3", "@types/readline-sync": "^1.4.3",
@ -64,6 +65,7 @@
"chalk": "2.4.1", "chalk": "2.4.1",
"commander": "2.15.1", "commander": "2.15.1",
"lowdb": "1.0.0", "lowdb": "1.0.0",
"mkdirp": "0.5.1",
"node-fetch": "2.1.2", "node-fetch": "2.1.2",
"node-forge": "0.7.1", "node-forge": "0.7.1",
"readline-sync": "1.4.9" "readline-sync": "1.4.9"

View File

@ -64,18 +64,18 @@ export class Program {
program.on('--help', () => { program.on('--help', () => {
writeLn('\n Examples:'); writeLn('\n Examples:');
writeLn(''); writeLn('');
writeLn(' $ bw login'); writeLn(' bw login');
writeLn(' $ bw sync'); writeLn(' bw sync');
writeLn(' $ bw lock'); writeLn(' bw lock');
writeLn(' $ bw unlock myPassword321'); writeLn(' bw unlock myPassword321');
writeLn(' $ bw generate -lusn --length 18'); writeLn(' bw generate -lusn --length 18');
writeLn(' $ bw list items --search google'); writeLn(' bw list items --search google');
writeLn(' $ bw get item 99ee88d2-6046-4ea7-92c2-acac464b1412'); writeLn(' bw get item 99ee88d2-6046-4ea7-92c2-acac464b1412');
writeLn(' $ bw get password google.com'); writeLn(' bw get password google.com');
writeLn(' $ bw delete item 99ee88d2-6046-4ea7-92c2-acac464b1412'); writeLn(' bw delete item 99ee88d2-6046-4ea7-92c2-acac464b1412');
writeLn(' $ echo \'{"name":"My Folder"}\' | bw encode'); writeLn(' echo \'{"name":"My Folder"}\' | bw encode');
writeLn(' $ bw create folder eyJuYW1lIjoiTXkgRm9sZGVyIn0K'); writeLn(' bw create folder eyJuYW1lIjoiTXkgRm9sZGVyIn0K');
writeLn(' $ bw edit folder c7c7b60b-9c61-40f2-8ccd-36c49595ed72 eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg=='); writeLn(' bw edit folder c7c7b60b-9c61-40f2-8ccd-36c49595ed72 eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg==');
writeLn(''); writeLn('');
}); });
@ -87,7 +87,7 @@ export class Program {
.action(async (email: string, password: string, cmd: program.Command) => { .action(async (email: string, password: string, cmd: program.Command) => {
await this.exitIfAuthed(); await this.exitIfAuthed();
const command = new LoginCommand(this.main.authService, this.main.apiService, const command = new LoginCommand(this.main.authService, this.main.apiService,
this.main.cryptoFunctionService); this.main.cryptoFunctionService, this.main.syncService);
const response = await command.run(email, password, cmd); const response = await command.run(email, password, cmd);
this.processResponse(response); this.processResponse(response);
}); });

View File

@ -1,5 +1,8 @@
import * as fs from 'fs';
import * as lowdb from 'lowdb'; import * as lowdb from 'lowdb';
import * as FileSync from 'lowdb/adapters/FileSync'; import * as FileSync from 'lowdb/adapters/FileSync';
import * as mkdirp from 'mkdirp';
import * as path from 'path';
import { StorageService } from 'jslib/abstractions/storage.service'; import { StorageService } from 'jslib/abstractions/storage.service';
import { Utils } from 'jslib/misc/utils'; import { Utils } from 'jslib/misc/utils';
@ -8,17 +11,20 @@ export class LowdbStorageService implements StorageService {
private db: lowdb.LowdbSync<any>; private db: lowdb.LowdbSync<any>;
constructor(appDirName: string) { constructor(appDirName: string) {
let path = null; let p = null;
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
path = process.env.HOME + '/Library/Application Support'; p = path.join(process.env.HOME, 'Library/Application Support', appDirName);
} else if (process.platform === 'win32') { } else if (process.platform === 'win32') {
path = process.env.APPDATA; p = path.join(process.env.APPDATA, appDirName);
} else { } else {
path = process.env.HOME + '/.config'; p = path.join(process.env.HOME, '.config', appDirName);
} }
path += ('/' + appDirName + '/data.json'); if (!fs.existsSync(p)) {
mkdirp.sync(p, 755);
}
p = path.join(p, 'data.json');
const adapter = new FileSync(path); const adapter = new FileSync(p);
this.db = lowdb(adapter); this.db = lowdb(adapter);
} }