<commit_before>var app = require('app'),
  BrowserWindow = require('browser-window'),
  Menu = require('menu'),
  dialog = require('dialog'),
  config = {},
  fs = require('fs');
//
// report crashes to atom-shell
require('crash-reporter').start();

//--------------------------------------------------------------------------------
// Add Project Dialog
//--------------------------------------------------------------------------------

var showAddExistingProjectDialog = (function(){

  var options = {
    title: "Select an existing project (project.clj)",
    properties: ["openFile"],
    filters: [
      {
        name: "Leiningen project config",
        extensions: ["clj"],
      }
    ],
  };

  function callback(filenames) {
    mainWindow.webContents.send('add-existing-project', filenames[0]);
  }

  return function() {
    dialog.showOpenDialog(options, callback);
  };

})();

//--------------------------------------------------------------------------------
// Menu Builder
//--------------------------------------------------------------------------------

menu_template = [
  {
    label: "File", // NOTE: On Mac, the first menu item is always the name of the Application
    submenu: [
      {
        label: "Add Existing Project",
        click: showAddExistingProjectDialog,
      },
    ],
  }
];

menu = Menu.buildFromTemplate(menu_template);
Menu.setApplicationMenu(menu);

//--------------------------------------------------------------------------------
// Main
//--------------------------------------------------------------------------------

// load config
// NOTE: this is mostly for development purposes
if (fs.existsSync(__dirname + '/config.json')) {
  config = require(__dirname + '/config.json');
}

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null;

// Quit when all windows are closed.
app.on('window-all-closed', function() {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

function onWindowClose() {
  // dereference the window object
  mainWindow = null;
}

// send the OS-normalized app data path to the webpage
// NOTE: this event triggers the "global app init" on the webpage side
function onFinishLoad() {
  mainWindow.webContents.send('config-file-location', app.getDataPath());
}

// NOTE: a lot of the browserWindow options listed on the docs page aren't
// working - need to investigate
var browserWindowOptions = {
  height: 850,
  icon: __dirname + '/img/clojure-logo.png',
  title: 'ClojureScript Compiler',
  width: 1000
};

function startApp() {
  // create the browser window
  mainWindow = new BrowserWindow(browserWindowOptions);

  // load index.html
  mainWindow.loadUrl('file://' + __dirname + '/index.html');

  // send info to the webpage
  mainWindow.webContents.on('did-finish-load', onFinishLoad);

  // Emitted when the window is closed.
  mainWindow.on('closed', onWindowClose);

  // optionally launch dev tools
  if (config.hasOwnProperty("dev-tools") && config["dev-tools"] === true) {
    mainWindow.openDevTools();
  }
}

// This method will be called when atom-shell has done everything
// initialization and ready for creating browser windows.
app.on('ready', startApp);
<commit_msg>update projects.json when adding existing project<commit_after>var app = require('app'),
  BrowserWindow = require('browser-window'),
  path = require('path'),
  Menu = require('menu'),
  dialog = require('dialog'),
  config = {},
  fs = require('fs');
//
// report crashes to atom-shell
require('crash-reporter').start();

//--------------------------------------------------------------------------------
// Add Project Dialog
//--------------------------------------------------------------------------------

var showAddExistingProjectDialog = (function(){

  var options = {
    title: "Select an existing project (project.clj)",
    properties: ["openFile"],
    filters: [
      {
        name: "Leiningen project config",
        extensions: ["clj"],
      }
    ],
  };

  function addToProjectsJson(filename) {
    var projectsFilename = path.join(app.getDataPath(), "projects.json");

    var projects = JSON.parse(fs.readFileSync(projectsFilename, 'utf8'));
    projects.push(filename);

    fs.writeFileSync(
      projectsFilename,
      JSON.stringify(projects, null, 2),
      {encoding: "utf8"});
  }

  function callback(filenames) {
    var filename = filenames[0];
    addToProjectsJson(filename);
    mainWindow.webContents.send('add-existing-project', filename);
  }

  return function() {
    dialog.showOpenDialog(options, callback);
  };

})();

//--------------------------------------------------------------------------------
// Menu Builder
//--------------------------------------------------------------------------------

menu_template = [
  {
    label: "File", // NOTE: On Mac, the first menu item is always the name of the Application
    submenu: [
      {
        label: "Add Existing Project",
        click: showAddExistingProjectDialog,
      },
    ],
  }
];

menu = Menu.buildFromTemplate(menu_template);
Menu.setApplicationMenu(menu);

//--------------------------------------------------------------------------------
// Main
//--------------------------------------------------------------------------------

// load config
// NOTE: this is mostly for development purposes
if (fs.existsSync(__dirname + '/config.json')) {
  config = require(__dirname + '/config.json');
}

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null;

// Quit when all windows are closed.
app.on('window-all-closed', function() {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

function onWindowClose() {
  // dereference the window object
  mainWindow = null;
}

// send the OS-normalized app data path to the webpage
// NOTE: this event triggers the "global app init" on the webpage side
function onFinishLoad() {
  mainWindow.webContents.send('config-file-location', app.getDataPath());
}

// NOTE: a lot of the browserWindow options listed on the docs page aren't
// working - need to investigate
var browserWindowOptions = {
  height: 850,
  icon: __dirname + '/img/clojure-logo.png',
  title: 'ClojureScript Compiler',
  width: 1000
};

function startApp() {
  // create the browser window
  mainWindow = new BrowserWindow(browserWindowOptions);

  // load index.html
  mainWindow.loadUrl('file://' + __dirname + '/index.html');

  // send info to the webpage
  mainWindow.webContents.on('did-finish-load', onFinishLoad);

  // Emitted when the window is closed.
  mainWindow.on('closed', onWindowClose);

  // optionally launch dev tools
  if (config.hasOwnProperty("dev-tools") && config["dev-tools"] === true) {
    mainWindow.openDevTools();
  }
}

// This method will be called when atom-shell has done everything
// initialization and ready for creating browser windows.
app.on('ready', startApp);

{'fraction_non_alphanumeric': 0.25506876506451154, 'fraction_numerical': 0.0026938891251949526, 'mean_word_length': 2.017108639863131, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3349962', 'n_tokens_mistral': 1859, 'n_tokens_neox': 1796, 'n_words': 529}