Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Promise = require("bluebird");
- var _ = require("underscore");
- var fs = Promise.promisifyAll(require("fs"));
- var Nightmare = require("nightmare");
- var iframe = require('nightmare-iframe');
- var nightmare = new Nightmare({
- show: false, openDevTools: true, webPreferences: {
- partition: 'nopersist'
- },
- typeInterval:1
- });
- var names = ["code.html", "style.css", "client.js", "server.js"];
- var args = process.argv;
- var baseURL = "https://smartdev.service-now.com/sp_config?id=widget_editor&sys_id=";
- var id = args[2];
- var username = args[3];
- var password = args[4];
- var readFilePromise = (file) => {
- return new Promise((f,r)=>{
- fs.readFile(file,"utf-8",function(err,data){
- if(err){
- console.log("Error reading file");
- r(err);
- return;
- }
- //console.log("Success reading file");
- f(data);
- });
- });
- }
- nightmare.goto(baseURL + id)
- .wait("#username")
- .type("input#username", username)
- .type("input#password", password)
- .click("button.btn-block")
- .wait("input[ng-model='section.display']")
- .evaluate(function () {
- $("input.ng-empty[ng-model='section.display']").click()
- })
- .evaluate(function () {
- var editors = $("div.CodeMirror");
- return [
- $(editors[0]).prop("CodeMirror").getValue(),
- $(editors[1]).prop("CodeMirror").getValue(),
- $(editors[2]).prop("CodeMirror").getValue(),
- $(editors[3]).prop("CodeMirror").getValue()
- ];
- })
- .then((srcs) => {
- console.log("Loading Content for the first time");
- var data = _.zip.apply(null, [names, srcs]);
- return Promise.all(data.map((data) => {
- return fs.writeFile("./" + data[0], data[1])
- }));
- })
- .then(() => {
- console.log("watching");
- fs.watch("./", (action, filename) => {
- if (!_.contains(names,filename))return;
- console.log("action = " + action + " filename = " + filename);
- Promise.all(names.map((n)=>readFilePromise("./"+n)))
- .then((contents)=>{
- return nightmare.evaluate(function(contents){
- var editors = $("div.CodeMirror");
- $(editors[0]).prop("CodeMirror").setValue(contents[0]);
- $(editors[1]).prop("CodeMirror").setValue(contents[1]);
- $(editors[2]).prop("CodeMirror").setValue(contents[2]);
- $(editors[3]).prop("CodeMirror").setValue(contents[3]);
- },contents);
- })
- .then(()=>nightmare.evaluate(()=>$("button[ng-click='c.save()']").click()));
- });
- })
- .catch((e) => {
- console.log(e);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement