Commit 6fa0ee1b authored by Cédric Moreau's avatar Cédric Moreau

[fix] #1037 Migrate system lib "directory" "unix2dos"

parent 10eee954
......@@ -12,6 +12,7 @@ app/lib/dal/fileDALs/*.js
app/lib/dal/fileDAL.js
app/service/*.js
app/lib/rules/*.js
app/lib/system/directory.js
app/modules/wizard.js
app/modules/router.js
app/modules/revert.js
......
......@@ -49,6 +49,7 @@ app/lib/dal/fileDALs/*.js*
app/lib/dal/fileDAL.js*
app/lib/rules/*.js*
app/lib/logger*js*
app/lib/system/directory.js*
app/service/*.js*
app/lib/wot.js*
app/modules/prover/*.js*
......
"use strict";
const co = require('co');
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const SQLiteDriver_1 = require("../dal/drivers/SQLiteDriver");
const CFSCore_1 = require("../dal/fileDALs/CFSCore");
const opts = require('optimist').argv;
const path = require('path');
const CFSCore = require('../dal/fileDALs/CFSCore').CFSCore
const qfs = require('q-io/fs');
const fs = require('fs');
const SQLiteDriver = require("../dal/drivers/SQLiteDriver").SQLiteDriver
const qfs = require('q-io/fs');
const fs = require('fs');
const DEFAULT_DOMAIN = "duniter_default";
const DEFAULT_HOME = (process.platform == 'win32' ? process.env.USERPROFILE : process.env.HOME) + '/.config/duniter/';
const getLogsPath = (profile, directory) => path.join(getHomePath(profile, directory), 'duniter.log');
const getHomePath = (profile, directory) => path.normalize(getUserHome(directory) + '/') + getDomain(profile);
const getUserHome = (directory) => (directory || DEFAULT_HOME);
const getDomain = (profile) => (profile || DEFAULT_DOMAIN);
const getLogsPath = (profile, directory = null) => path.join(getHomePath(profile, directory), 'duniter.log');
const getHomePath = (profile, directory = null) => path.normalize(getUserHome(directory) + '/') + getDomain(profile);
const getUserHome = (directory = null) => (directory || DEFAULT_HOME);
const getDomain = (profile = null) => (profile || DEFAULT_DOMAIN);
const dir = module.exports = {
INSTANCE_NAME: getDomain(opts.mdb),
INSTANCE_HOME: getHomePath(opts.mdb, opts.home),
INSTANCE_HOMELOG_FILE: getLogsPath(opts.mdb, opts.home),
DUNITER_DB_NAME: 'duniter',
WOTB_FILE: 'wotb.bin',
getHome: (profile, directory) => getHomePath(profile, directory),
getHomeFS: (isMemory, theHome) => co(function *() {
const home = theHome || dir.getHome();
yield someDelayFix();
const params = {
home: home
};
if (isMemory) {
params.fs = require('q-io/fs-mock')({});
} else {
params.fs = qfs;
}
yield params.fs.makeTree(home);
return params;
}),
getHomeParams: (isMemory, theHome) => co(function *() {
const params = yield dir.getHomeFS(isMemory, theHome);
const home = params.home;
yield someDelayFix();
if (isMemory) {
params.dbf = () => new SQLiteDriver(':memory:');
params.wotb = require('../wot').WoTBObject.memoryInstance();
} else {
const sqlitePath = path.join(home, dir.DUNITER_DB_NAME + '.db');
params.dbf = () => new SQLiteDriver(sqlitePath);
const wotbFilePath = path.join(home, dir.WOTB_FILE);
let existsFile = yield qfs.exists(wotbFilePath);
if (!existsFile) {
fs.closeSync(fs.openSync(wotbFilePath, 'w'));
}
params.wotb = require('../wot').WoTBObject.fileInstance(wotbFilePath);
}
return params;
}),
createHomeIfNotExists: (fileSystem, theHome) => co(function *() {
const fsHandler = new CFSCore(theHome, fileSystem);
return fsHandler.makeTree('');
})
INSTANCE_NAME: getDomain(opts.mdb),
INSTANCE_HOME: getHomePath(opts.mdb, opts.home),
INSTANCE_HOMELOG_FILE: getLogsPath(opts.mdb, opts.home),
DUNITER_DB_NAME: 'duniter',
WOTB_FILE: 'wotb.bin',
getHome: (profile = null, directory = null) => getHomePath(profile, directory),
getHomeFS: (isMemory, theHome) => __awaiter(this, void 0, void 0, function* () {
const home = theHome || dir.getHome();
yield someDelayFix();
const params = {
home: home
};
if (isMemory) {
params.fs = require('q-io/fs-mock')({});
}
else {
params.fs = qfs;
}
yield params.fs.makeTree(home);
return params;
}),
getHomeParams: (isMemory, theHome) => __awaiter(this, void 0, void 0, function* () {
const params = yield dir.getHomeFS(isMemory, theHome);
const home = params.home;
yield someDelayFix();
if (isMemory) {
params.dbf = () => new SQLiteDriver_1.SQLiteDriver(':memory:');
params.wotb = require('../wot').WoTBObject.memoryInstance();
}
else {
const sqlitePath = path.join(home, dir.DUNITER_DB_NAME + '.db');
params.dbf = () => new SQLiteDriver_1.SQLiteDriver(sqlitePath);
const wotbFilePath = path.join(home, dir.WOTB_FILE);
let existsFile = yield qfs.exists(wotbFilePath);
if (!existsFile) {
fs.closeSync(fs.openSync(wotbFilePath, 'w'));
}
params.wotb = require('../wot').WoTBObject.fileInstance(wotbFilePath);
}
return params;
}),
createHomeIfNotExists: (fileSystem, theHome) => __awaiter(this, void 0, void 0, function* () {
const fsHandler = new CFSCore_1.CFSCore(theHome, fileSystem);
return fsHandler.makeTree('');
})
};
const someDelayFix = () => new Promise((resolve) => {
setTimeout(resolve, 100);
setTimeout(resolve, 100);
});
//# sourceMappingURL=directory.js.map
\ No newline at end of file
import {SQLiteDriver} from "../dal/drivers/SQLiteDriver"
import {CFSCore} from "../dal/fileDALs/CFSCore"
const opts = require('optimist').argv;
const path = require('path');
const qfs = require('q-io/fs');
const fs = require('fs');
const DEFAULT_DOMAIN = "duniter_default";
const DEFAULT_HOME = (process.platform == 'win32' ? process.env.USERPROFILE : process.env.HOME) + '/.config/duniter/';
const getLogsPath = (profile:string, directory:string|null = null) => path.join(getHomePath(profile, directory), 'duniter.log');
const getHomePath = (profile:string|null, directory:string|null = null) => path.normalize(getUserHome(directory) + '/') + getDomain(profile);
const getUserHome = (directory:string|null = null) => (directory || DEFAULT_HOME);
const getDomain = (profile:string|null = null) => (profile || DEFAULT_DOMAIN);
const dir = module.exports = {
INSTANCE_NAME: getDomain(opts.mdb),
INSTANCE_HOME: getHomePath(opts.mdb, opts.home),
INSTANCE_HOMELOG_FILE: getLogsPath(opts.mdb, opts.home),
DUNITER_DB_NAME: 'duniter',
WOTB_FILE: 'wotb.bin',
getHome: (profile:string|null = null, directory:string|null = null) => getHomePath(profile, directory),
getHomeFS: async (isMemory:boolean, theHome:string) => {
const home = theHome || dir.getHome();
await someDelayFix();
const params:any = {
home: home
};
if (isMemory) {
params.fs = require('q-io/fs-mock')({});
} else {
params.fs = qfs;
}
await params.fs.makeTree(home);
return params;
},
getHomeParams: async (isMemory:boolean, theHome:string) => {
const params:any = await dir.getHomeFS(isMemory, theHome)
const home = params.home;
await someDelayFix()
if (isMemory) {
params.dbf = () => new SQLiteDriver(':memory:');
params.wotb = require('../wot').WoTBObject.memoryInstance();
} else {
const sqlitePath = path.join(home, dir.DUNITER_DB_NAME + '.db');
params.dbf = () => new SQLiteDriver(sqlitePath);
const wotbFilePath = path.join(home, dir.WOTB_FILE);
let existsFile = await qfs.exists(wotbFilePath)
if (!existsFile) {
fs.closeSync(fs.openSync(wotbFilePath, 'w'));
}
params.wotb = require('../wot').WoTBObject.fileInstance(wotbFilePath);
}
return params;
},
createHomeIfNotExists: async (fileSystem:any, theHome:string) => {
const fsHandler = new CFSCore(theHome, fileSystem);
return fsHandler.makeTree('');
}
}
const someDelayFix = () => new Promise((resolve) => {
setTimeout(resolve, 100);
})
"use strict";
const dos2unix = require('duniter-common').dos2unix;
const util = require('util');
const stream = require('stream');
module.exports = function (str) {
if (str)
return unix2dos(str);
else
return new Unix2DosStream();
};
function unix2dos(str){
return dos2unix(str).replace(/\n/g, '\r\n');
}
function Unix2DosStream () {
stream.Transform.apply(this);
this._write = function (str, enc, done) {
this.push(unix2dos(str.toString()));
done();
}
}
util.inherits(Unix2DosStream, stream.Transform);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment