Skip to content
Snippets Groups Projects
Select Git revision
  • 5bce423b494dfda559f4cf455f4d5609f1bd90c7
  • master default protected
  • rednatco-v2
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • servers
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

deploy.js

Blame
  • deploy.js 1.66 KiB
    /**
     * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author Alexander Rose <alexander.rose@weirdbyte.de>
     */
    
    const git = require('simple-git')
    const path = require('path')
    const fs = require("fs")
    const fse = require("fs-extra")
    
    const remoteUrl = "https://github.com/molstar/molstar.github.io.git"
    const buildDir = path.resolve(__dirname, '../build/')
    const deployDir = path.resolve(buildDir, 'deploy/')
    const localPath = path.resolve(deployDir, 'molstar.github.io/')
    
    function log(command, stdout, stderr) {
        if (command) {
            console.log('\n###', command)
            stdout.pipe(process.stdout)
            stderr.pipe(process.stderr)
        }
    }
    
    function copyViewer() {
        console.log('\n###', 'copy viewer files')
        const viewerBuildPath = path.resolve(buildDir, '../build/viewer/')
        const viewerDeployPath = path.resolve(localPath, 'viewer/')
        fse.copySync(viewerBuildPath, viewerDeployPath, { overwrite: true })
    }
    
    if (!fs.existsSync(localPath)) {
        console.log('\n###', 'create localPath')
        fs.mkdirSync(localPath, { recursive: true })
    }
    
    process.chdir(localPath);
    
    if (!fs.existsSync(path.resolve(localPath, '.git/'))) {
        console.log('\n###', 'clone repository')
        git()
            .outputHandler(log)
            .clone(remoteUrl, localPath)
            .fetch(['--all'])
            .exec(copyViewer)
            .add(['-A'])
            .commit('updated viewer')
            .push()
    } else {
        console.log('\n###', 'update repository')
        git()
            .outputHandler(log)
            .fetch(['--all'])
            .reset(['--hard', 'origin/master'])
            .exec(copyViewer)
            .add(['-A'])
            .commit('updated viewer')
            .push()
    }