Skip to content

Commit

Permalink
Revises Project Structure
Browse files Browse the repository at this point in the history
This commit revises project structure to allow for a large client. It looks like we are going to combine the FMS Admin API, the FMS Client CLI, and the Migration Tool.

Signed-off-by: Lui de la Parra <lui@mutesymphony.com>
  • Loading branch information
Luidog committed Nov 3, 2018
1 parent afd105d commit c1300d8
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 42 deletions.
24 changes: 14 additions & 10 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@ connect('nedb://memory')
});

return admin.save().then(admin => {
admin.migration.execute({
force: true,
clone_path: './migration/Test-DB-Clone.fmp12',
src_path: './migration/Test-DB-Prod.fmp12'
});
admin.migration
.execute({
force: true,
clone_path: './migration/Test-DB-Clone.fmp12',
src_path: './migration/Test-DB-Prod.fmp12'
})
.then(migration => console.log(migration))
.catch(error => {
console.log('ERROR',error);
});
return admin;
});
})
.then(admin => {
setTimeout(function() {
Admin.find().then(admins=>console.log(admins[0].toJSON()))
setTimeout(function() {
Admin.find().then(admins => console.log(admins[0].toJSON()));
}, 1000);
setTimeout(function() {
Admin.find().then(admins=>console.log(admins[0].toJSON()))
setTimeout(function() {
Admin.find().then(admins => console.log(admins[0].toJSON()));
}, 10000);

})
.catch(error => console.log('error', error));
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { Admin } = require('./admin.model');
const { Admin } = require('./models');

module.exports = {
Admin
Expand Down
6 changes: 3 additions & 3 deletions src/admin.model.js → src/models/admin.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { Document } = require('marpat');
const { CLI } = require('./cli.model');
const { Migration } = require('./migration.model');
const { API } = require('./cli.model');
const { API } = require('./api.model');
/**
/**
Expand Down Expand Up @@ -38,9 +38,9 @@ class Admin extends Document {
* @return {null} The preInit hook does not return anything
*/
preInit(data) {
this.migration = Migration.create({ path: data.path });
this.api = API.create()
this.cli = CLI.create({ user: data.user, password: data.password });
this.migration = Migration.create({ path: data.path });
this.api = API.create({});
}

preSave() {
Expand Down
3 changes: 1 addition & 2 deletions src/api.model.js → src/models/api.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ const { EmbeddedDocument } = require('marpat');
class API extends EmbeddedDocument {
constructor() {
super();
this.schema({
});
this.schema({});
}
}
/**
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/models/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

const { Admin } = require('./admin.model');

module.exports = { Admin };
42 changes: 16 additions & 26 deletions src/migration.model.js → src/models/migration.model.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

const { Document } = require('marpat');
const { spawn, exec } = require('child_process');
const _ = require('lodash');
const { spawn } = require('child_process');
const { convertCommands } = require('../utilities');

/**
* @class Credentials
* @classdesc The class used to authenticate with into the FileMaker API.
Expand Down Expand Up @@ -30,37 +31,26 @@ class Migration extends Document {
}

execute(commands) {
this.session = [];
let commandArray = _.flatten(
_.compact(
_.values(
_.mapValues(commands, (value, key, object) => {
if (value === true) {
return [`-${key}`];
} else if (value !== false) {
return [`-${key}`, value];
}
return;
})
)
)
);
let thisProcess = spawn(this.path, commandArray);

thisProcess.stdout.on('data', data => this.log(data));
thisProcess.stderr.on('error', error => this.log(error));
thisProcess.on('close', () => this.end());
this.process = thisProcess.pid;

let newProcess = spawn(this.path, convertCommands(commands));
this._attach(newProcess);
return this.save();
}

log(data) {
_attach(newProcess) {
this.session = [];
this.process = newProcess.pid;
newProcess.on('error', error => this._log(error));
newProcess.stdout.on('data', data => this._log(data));
newProcess.stderr.on('error', error => this._log(error));
newProcess.on('close', () => this._end());
}

_log(data) {
this.session.push(data.toString());
return this.save();
}

end() {
_end() {
this.process = undefined;
return this.save();
}
Expand Down
21 changes: 21 additions & 0 deletions src/utilities/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const _ = require('lodash');

const convertCommands = object =>
_.flatten(
_.compact(
_.values(
_.mapValues(object, (value, key, object) => {
if (value === true) {
return [`-${key}`];
} else if (value !== false) {
return [`-${key}`, value];
}
return;
})
)
)
);

module.exports = { convertCommands };

0 comments on commit c1300d8

Please sign in to comment.