Skip to content

Instantly share code, notes, and snippets.

@scottrippey
Created July 5, 2019 20:19

Revisions

  1. scottrippey created this gist Jul 5, 2019.
    45 changes: 45 additions & 0 deletions test-migration.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@

    async function main() {
    // Do the thing:
    console.log(`
    This script copies settings and sign-in creds from prod to dev.
    It should prompt you for your system creds (twice), to access the prod creds.
    `);

    await copyPassword('credentials', 'InVision Studio', 'InVision Studio (Dev)');
    await copyAppDataFolder('InVision Studio', 'InVision Studio (Dev)');

    console.log('Copied credentials successfully!');
    }


    async function copyAppDataFolder(src, dest) {
    const electron = require('electron');
    const fse = require('fs-extra');

    const appData = electron.app.getPath('appData');

    console.log(`Copying '${appData}/${src}' to '${dest}'...`);

    await fse.rmdir(`${appData}/${dest}`).catch(err => null);
    await fse.copy(`${appData}/${src}`, `${appData}/${dest}`);

    }


    async function copyPassword(key, source, dest) {
    const keytar = require('keytar');

    console.log(`Copying '${key}' from '${source}' to '${dest}'...`);

    const value = await keytar.getPassword(source, key);
    await keytar.setPassword(dest, key, value);
    }


    main().then(() => {
    process.exit(0);
    }, (err) => {
    console.error(err);
    process.exit(1);
    });
    3 changes: 3 additions & 0 deletions test-migration.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    #!/bin/bash

    npx electron ./test-migration.js