Opening current project in dev mode


#1

So I’ve wanted this command for a while now, and I finally got annoyed enough to make it. It seems to work fine from my extensive testing of an entire ONE test, and it handles paths with spaces in them. Tree view folds and open files also seem to be maintained without any extra effort.

It should be pasted into your init.js file (or you could translate to CoffeeScript).

const child_process = require("child_process");

atom.commands.add("atom-text-editor", "window:open-project-in-dev-mode", () => {
  let rootPaths = atom.project.rootDirectories.map(dir => dir.realPath);
  child_process.exec(`atom --dev "${rootPaths.join('" "')}"`);
});

Please feel free to suggest refinements, etc. I would have preferred to run an internal command to make the new window, and to have some sort of control over it when it’s ready, but I couldn’t find any commands that let me do that (and I haven’t worked out if I can do what the built in new window command does).

Maybe it could close the existing window when the dev version opens?


#2

Some years ago, I created open-in-developer-mode which does the same thing in a different way. Worked fine for me.


#3

…serves me right. I did the same thing with custom folding. Worked on it for a day before looking for an existing package, and finding one that did nearly exactly what I wanted (and much better than what I had come up with).


#4

Updated version, using the actual command to open a new window + tree view support.

var treeView;
atom.packages.serviceHub.consume("tree-view", "^1.0.0", (t) => {
  treeView = t;
});

function getSelectedPaths() {
  if (!treeView) { atom.notifications.addError("Tree view provider not consumed"); return; }
  return treeView.selectedPaths();
}

function openNewWindow(mode, allRootPaths) {
  let paths;
  let dev = mode === "dev" ? true : false;
  let safe = mode === "safe" ? true : false;
  let normal = mode === "normal" ? true : false;
  let closeOriginalWindow = allRootPaths && !safe

  if (allRootPaths) {
    if (dev && atom.inDevMode()) {
      atom.notifications.addInfo("You're already in dev mode");
      return;
    } else if (normal && !atom.inDevMode()) {
      atom.notifications.addInfo("You're already in normal mode");
      return;
    }

    paths = atom.project.rootDirectories.map(dir => dir.realPath);

  } else {
    paths = getSelectedPaths();
    if (!paths) { return; }
  }

  atom.open({ newWindow: true, devMode: dev, safeMode: safe, pathsToOpen: paths});
  if (closeOriginalWindow) { atom.close(); }
}

atom.commands.add("atom-text-editor", {
  "window:open-project-in-dev-mode": () => { openNewWindow("dev", true); },
  "window:open-project-in-safe-mode": () => { openNewWindow("safe", true); },
  "window:open-project-in-normal-mode": () => { openNewWindow("normal", true); }
});

atom.commands.add(".tree-view", {
  "tree-view:open-selected-in-dev-mode": () => { openNewWindow("dev", false); },
  "tree-view:open-selected-in-safe-mode": () => { openNewWindow("safe", false); },
  "tree-view:open-selected-in-normal-mode": () => { openNewWindow("normal", false); }
});