本文整理匯總了TypeScript中@nodulus/data.connect函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript connect函數的具體用法?TypeScript connect怎麽用?TypeScript connect使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了connect函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
router.get('/languages', function (req: any, res: any) {
var lang = req.query.lang;
dal.connect(function (err: any, db: any) {
if (db === null) {
return res.json(err);
}
db.collection("Languages").find({ "name": lang }).toArray(function (err: any, data: any) {
var result: any = {}
if (data !== null && data.length > 0) {
data = data[0]
for (var i = 0; i < data.values.length; i++) {
result[data.values[i].Key] = data.values[i].Value;
}
}
return res.json(result);
});
});
});
示例2: JSZip
fs.readFile(path.join(global.nodulsRepo, module_name + ".zip"), (err: any, data: any) => {
if (err) throw err;
var zip = new JSZip(data);
var fileData = zip.file(consts.MANIFEST_NAME).asText();
fs.writeFileSync(path.join(baseFolder, consts.MANIFEST_NAME), fileData, 'utf8');
var manifest_file = fs.readJsonSync(path.join(baseFolder, consts.MANIFEST_NAME), { throws: true });
if (manifest_file.files !== undefined) {
for (var i = 0; i < manifest_file.files.length; i++) {
var filename = manifest_file.files[i];
if (zip.file(filename)) {
var fileData = zip.file(filename).asText();
if (filename.indexOf('/') > -1) {
var directoryPath = (path.join(baseFolder, path.normalize(filename)));
directoryPath = path.dirname(directoryPath);//.substr(0, directoryPath.lastIndexOf('\\'));
if (!fs.existsSync(directoryPath))
mkdirp.sync(directoryPath);
}
fs.writeFileSync(path.join(baseFolder, filename), fileData, 'utf8');
}
}
}
if (manifest_file.routes !== undefined) {
for (var i = 0; i < manifest_file.routes.length; i++) {
var filename = manifest_file.routes[i].path;
if (zip.folder("routes").file(filename)) {
var fileData = zip.folder("routes").file(filename).asText();
fs.writeFileSync(path.join(serverRoot, "routes", filename), fileData, 'utf8');
}
//attach the new route to express
app.use(module_name, require('../routes/' + filename));
}
}
if (manifest_file.scripts !== undefined) {
fs.ensureDirSync(path.join(baseFolder, "scripts"));
for (var i = 0; i < manifest_file.scripts.length; i++) {
var filename = manifest_file.scripts[i];
if (zip.folder("scripts").file(filename)) {
var fileData = zip.folder("scripts").file(filename).asText();
fs.writeFileSync(path.join(baseFolder, "scripts", filename), fileData, 'utf8');
}
}
}
var aboutfilename = "about.html";
if (zip.file(aboutfilename) !== null) {
var fileData = zip.file(aboutfilename).asText();
fs.writeFileSync(path.join(baseFolder, aboutfilename), fileData, 'utf8');
}
var modules_file: any = {};
modules_file = config.modulesSettings;
if (modules_file[module_name] === undefined) {
modules_file[module_name] = {}
}
//merge the manifest into the file
if (manifest_file === null)
callback("invalid json, try using ascii file");
//update navigation
if (manifest_file.navigation)
dal.connect((err: any, db: any) => {
for (var i = 0; i < manifest_file.navigation.length; i++) {
db.collection("Navigation").save(manifest_file.navigation[i], (err: any, data: any) => {
});
}
})
modules_file[module_name] = manifest_file;
if (manifest_file.npm !== undefined) {
var arr: Array<any> = [];
for (var x in manifest_file.npm) {
arr.push({ name: x, ver: manifest_file.npm[x] });
}
//install npm dependencies
//.........這裏部分代碼省略.........
示例3: function
function (error: any, stdout: any, stderr: any) {
//callback(stderr, stdout);
//console.log('stdout: ' + stdout);
//console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
var basePath = path.join(process.cwd(), 'node_modules', module_name);
app.use('/' + module_name, app.static(path.join(basePath, 'public')));
var manifest_file = require(path.join(basePath, consts.MANIFEST_NAME));
var modules_file: any = {};
modules_file = config.modulesSettings;
if (modules_file[module_name] === undefined) {
modules_file[module_name] = {}
}
if (manifest_file.routes !== undefined) {
for (var x = 0; x < manifest_file.routes.length; x++) {
try {
var pathRoute = path.join(basePath, 'routes', manifest_file.routes[x].path);
app.use('/' + module_name + manifest_file.routes[x].route, require(pathRoute));
}
catch (error) {
console.error(error);
}
}
}
//merge the manifest into the modules.js file
if (manifest_file === null)
callback("invalid json, try using ascii file");
//update navigation
if (manifest_file.navigation)
dal.connect((err: any, db: any) => {
for (var i = 0; i < manifest_file.navigation.length; i++) {
db.collection("Navigation").save(manifest_file.navigation[i], (err: any, data: any) => {
});
}
})
modules_file[module_name] = manifest_file;
if (manifest_file.npm !== undefined) {
var arr: Array<any> = [];
for (var f in manifest_file.npm) {
arr.push({ name: f, ver: manifest_file.npm[f] });
}
//install npm dependencies
var async = require("async");
async.each(arr, instance.npm_install, () => {
//fs.writeFileSync(modules_configuration_path, JSON.stringify(modules_file));
config.persistModules();
callback(null, manifest_file);
})
}
else {
config.persistModules();
// fs.writeFileSync(modules_configuration_path, JSON.stringify(modules_file));
callback(null, manifest_file);
}
});