Skip to content

Instantly share code, notes, and snippets.

@mindspank
Last active January 21, 2019 20:27

Revisions

  1. mindspank revised this gist Apr 15, 2016. No changes.
  2. mindspank created this gist Sep 18, 2015.
    36 changes: 36 additions & 0 deletions app2json.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    var qsocks = require('qsocks')
    var serializeApp = require('serializeapp')
    var fs = require('fs-extra')
    var Promise = require('promise')

    function create(docname) {
    qsocks.Connect({appname: docname})
    .then(function(global) {
    return global.openDoc(docname)
    })
    .then(function(app) {
    return serializeApp(app)
    })
    .then(function(data) {
    return writeJson(data)
    })
    .then(function() {
    return console.log('Done')
    })
    .catch(function(error) {
    console.log(error)
    }).done(function() {
    process.exit(1)
    });
    };

    function writeJson(data) {
    return new Promise(function(resolve, reject) {
    fs.writeJson(data.properties.qTitle + '.json', data, function (err) {
    if(err) { return reject(err); }
    return resolve();
    })
    });
    };

    create(process.argv[2] || 'Executive Dashboard');
    33 changes: 33 additions & 0 deletions json2app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    var qsocks = require('qsocks')
    var buildapp = require('buildapp')
    var fs = require('fs-extra')
    var Promise = require('promise')

    function read(filename) {
    return qsocks.Connect().then(function(global) {
    return readJson(filename).then(function(data) {
    return buildapp(global, data, {
    filename: data.properties.qTitle + Date.now(),
    reload: true
    });
    });
    })
    };

    function readJson(filename) {
    return new Promise(function(resolve, reject) {
    return fs.readJson(filename, function (err, data) {
    return resolve(data)
    })
    });
    };

    read(process.argv[2] || 'Telecom Customer Retention.json').then(function() {
    console.log('Done')
    })
    .catch(function(error) {
    console.log(error)
    })
    .done(function() {
    process.exit(1)
    });