it('selects the grammar with the longest fileType match', () => {
        const grammarPath1 = temp.path({ suffix: '.json' })
        fs.writeFileSync(
          grammarPath1,
          JSON.stringify({
            name: 'test1',
            scopeName: 'source1',
            fileTypes: ['test']
          })
        )
        const grammar1 = atom.grammars.loadGrammarSync(grammarPath1)
        expect(atom.grammars.selectGrammar('more.test', '')).toBe(grammar1)
        fs.removeSync(grammarPath1)

        const grammarPath2 = temp.path({ suffix: '.json' })
        fs.writeFileSync(
          grammarPath2,
          JSON.stringify({
            name: 'test2',
            scopeName: 'source2',
            fileTypes: ['test', 'more.test']
          })
        )
        const grammar2 = atom.grammars.loadGrammarSync(grammarPath2)
        expect(atom.grammars.selectGrammar('more.test', '')).toBe(grammar2)
        return fs.removeSync(grammarPath2)
      })
Example #2
0
  moveResult (result, filePath) {
    const originalOutputFilePath = result.outputFilePath
    result.outputFilePath = this.alterParentPath(filePath, originalOutputFilePath)
    if (fs.existsSync(originalOutputFilePath)) {
      fs.removeSync(result.outputFilePath)
      fs.moveSync(originalOutputFilePath, result.outputFilePath)
    }

    const originalSyncFilePath = originalOutputFilePath.replace(/\.pdf$/, '.synctex.gz')
    if (fs.existsSync(originalSyncFilePath)) {
      const syncFilePath = this.alterParentPath(filePath, originalSyncFilePath)
      fs.removeSync(syncFilePath)
      fs.moveSync(originalSyncFilePath, syncFilePath)
    }
  }
    it('displays all tags', async () => {
      await atom.workspace.open(directory.resolve('tagged.js'));
      expect(getWorkspaceView().querySelector('.symbols-view-plus')).toBeNull();
      atom.commands.dispatch(getWorkspaceView(), 'symbols-view-plus:toggle-project-symbols');

      await activationPromise;
      symbolsView = atom.workspace.getModalPanels()[0].item;

      await conditionPromise(() => symbolsView.element.querySelectorAll('li').length > 0);
      const directoryBasename = path.basename(directory.getPath());
      const taggedFile = path.join(directoryBasename, 'tagged.js');
      expect(symbolsView.selectListView.refs.loadingMessage).toBeUndefined();
      expect(document.body.contains(symbolsView.element)).toBe(true);
      expect(symbolsView.element.querySelectorAll('li').length).toBe(4);
      expect(symbolsView.element.querySelector('li:first-child .primary-line')).toHaveText('callMeMaybe');
      expect(symbolsView.element.querySelector('li:first-child .secondary-line')).toHaveText(taggedFile);
      expect(symbolsView.element.querySelector('li:last-child .primary-line')).toHaveText('thisIsCrazy');
      expect(symbolsView.element.querySelector('li:last-child .secondary-line')).toHaveText(taggedFile);
      atom.commands.dispatch(getWorkspaceView(), 'symbols-view-plus:toggle-project-symbols');
      fs.removeSync(directory.resolve('tags'));

      await conditionPromise(() => symbolsView.reloadTags);
      atom.commands.dispatch(getWorkspaceView(), 'symbols-view-plus:toggle-project-symbols');

      await conditionPromise(() => symbolsView.selectListView.refs.loadingMessage);
      await conditionPromise(() => symbolsView.element.querySelectorAll('li').length === 0);
    });
    it("emits a warning when a file can't be recovered", async () => {
      const mockWindow = {}
      const filePath = temp.path()
      fs.writeFileSync(filePath, 'content')

      let logs = []
      spies.stub(console, 'log', message => logs.push(message))
      spies.stub(dialog, 'showMessageBox')

      // Copy files to be recovered before mocking fs.createWriteStream
      await recoveryService.willSavePath(mockWindow, filePath)

      // Stub out fs.createWriteStream so that we can return a fake error when
      // attempting to copy the recovered file to its original location
      var fakeEmitter = new EventEmitter()
      var onStub = spies.stub(fakeEmitter, 'on')
      onStub
        .withArgs('error')
        .yields(new Error('Nope'))
        .returns(fakeEmitter)
      onStub.withArgs('open').returns(fakeEmitter)
      spies
        .stub(fsreal, 'createWriteStream')
        .withArgs(filePath)
        .returns(fakeEmitter)

      await recoveryService.didCrashWindow(mockWindow)
      let recoveryFiles = fs.listTreeSync(recoveryDirectory)
      assert.equal(recoveryFiles.length, 1)
      assert.equal(logs.length, 1)
      assert.match(logs[0], new RegExp(escapeRegExp(filePath)))
      assert.match(logs[0], new RegExp(escapeRegExp(recoveryFiles[0])))

      fs.removeSync(filePath)
    })
    it('restores the created recovery file when many windows attempt to save the same file and one of them crashes', async () => {
      const mockWindow = {}
      const anotherMockWindow = {}
      const filePath = temp.path()

      fs.writeFileSync(filePath, 'A')
      await recoveryService.willSavePath(mockWindow, filePath)
      fs.writeFileSync(filePath, 'B')
      await recoveryService.willSavePath(anotherMockWindow, filePath)
      assert.equal(fs.listTreeSync(recoveryDirectory).length, 1)

      fs.writeFileSync(filePath, 'C')

      await recoveryService.didCrashWindow(mockWindow)
      assert.equal(fs.readFileSync(filePath, 'utf8'), 'A')
      assert.equal(fs.listTreeSync(recoveryDirectory).length, 0)

      fs.writeFileSync(filePath, 'D')
      await recoveryService.willSavePath(mockWindow, filePath)
      fs.writeFileSync(filePath, 'E')
      await recoveryService.willSavePath(anotherMockWindow, filePath)
      assert.equal(fs.listTreeSync(recoveryDirectory).length, 1)

      fs.writeFileSync(filePath, 'F')

      await recoveryService.didCrashWindow(anotherMockWindow)
      assert.equal(fs.readFileSync(filePath, 'utf8'), 'D')
      assert.equal(fs.listTreeSync(recoveryDirectory).length, 0)

      fs.removeSync(filePath)
    })
Example #6
0
var createTarOpenVpn = function (done) {

	fs.removeSync('build');
	fs.makeTreeSync('build');

	var arch = process.arch === 'ia32' ? 'x86' : process.arch;
	var platform = process.platform === 'darwin' ? 'mac' : process.platform;

	var dirDest = fs.createWriteStream('build/openvpn-' + platform + '-' + arch + '.tar.gz');

	// we'll copy our openvpn.conf
	fs.createReadStream('openvpn.conf').pipe(fs.createWriteStream('openvpn/openvpn.conf'));

	var tarArchive = archiver('tar', {
	  gzip: true,
	  gzipOptions: {
	    level: 1
	  }
	});

	dirDest.on('close', function() {
	    console.log('done with the tar', 'build/openvpn-' + platform + '-' + arch + '.tar.gz');
		done();
	});

	tarArchive.pipe(dirDest);

	tarArchive.bulk([
	    { src: [ '**/*' ], cwd: path.resolve(__dirname, '..', 'openvpn'), expand: true }
	]);

	tarArchive.finalize()
}
Example #7
0
var downloadOpenVPN = function (done) {
	var arch, downloadURL, filename;
	arch = process.arch === 'ia32' ? 'x86' : process.arch;

	// we clean our download folder
	fs.removeSync('openvpn');

	downloadURL = config[process.platform][arch];

	if (process.platform === 'win32') {
		// if windows we need our dir so we'll create it
		fs.makeTreeSync('openvpn');
		filename = path.join('openvpn', "openvpn.exe");
	} else {
		// we tell him to extract in openvpn folder
		filename = path.join('openvpn');
	}

	// it's a EXE
	if (process.platform === 'win32') {
		downloadFileToLocation(downloadURL, filename, done);
	} else if (process.platform === 'linux') {
		var next = copyToLocation.bind(this, done, filename);
		downloadTarballAndExtract(downloadURL, filename, next);
	} else {
		var next = copyToLocation.bind(this, done, filename);
		downloadTarballAndExtract(downloadURL, filename, next);
	}
};
Example #8
0
 fs.readdirSync(dir).forEach((packageName) => {
   const packagePath = path.join(dir, packageName)
   const realPackagePath = fs.realpathSync(packagePath).replace('/private/', '/')
   if (realPackagePath !== packagePath) {
     console.log(`Copying ${realPackagePath} to ${packagePath}`);
     fs.removeSync(packagePath);
     fs.copySync(realPackagePath, packagePath);
   }
 });
  it('generates project symbols', async () => {
    if (process.platform == 'win32') { return; } // not supported

    atom.commands.dispatch(getWorkspaceView(), 'symbols-view-plus:generate-project-symbols');
    await conditionPromise(() => fs.existsSync(directory.resolve('.tags')));

    const tags = fs.readFileSync(directory.resolve('.tags'), 'utf8');
    expect(tags.split(/\n|\r\n/).length).toBeGreaterThan(13);

    fs.removeSync(directory.resolve('.tags'));
  });
      waitsForPromise(async () => {
        var rootNode = rootNodes[0];
        var fileNode = rootNode.getCachedChildren().get(1);

        var pathToRemove = fileNode.getItem().getPath();
        fs.removeSync(pathToRemove);

        var children = await rootNode.fetchChildren();
        var nodeKeys = children.map((childNode) => childNode.getKey());
        expect(nodeKeys).toEqual(getPathsInRoot(['/dir1/dir1/']));
        expect(fileTreeController.getStateForNodeKey(fileNode.getKey())).toBeUndefined();
      });
      it("doesn't display the tag", async () => {
        fs.removeSync(directory.resolve('tagged-duplicate.js'));
        await atom.workspace.open(directory.resolve('tagged.js'));

        editor = atom.workspace.getActiveTextEditor();
        editor.setCursorBufferPosition([8, 14]);
        spyOn(SymbolsView.prototype, 'moveToPosition').andCallThrough();
        atom.commands.dispatch(getEditorView(), 'symbols-view-plus:go-to-declaration');

        await conditionPromise(() => SymbolsView.prototype.moveToPosition.callCount === 1);
        expect(editor.getCursorBufferPosition()).toEqual([8, 0]);
      });
    it('restores the created recovery file and deletes it', async () => {
      const mockWindow = {}
      const filePath = temp.path()

      fs.writeFileSync(filePath, 'some content')
      await recoveryService.willSavePath(mockWindow, filePath)
      assert.equal(fs.listTreeSync(recoveryDirectory).length, 1)

      fs.writeFileSync(filePath, 'changed')
      await recoveryService.didCrashWindow(mockWindow)
      assert.equal(fs.listTreeSync(recoveryDirectory).length, 0)
      assert.equal(fs.readFileSync(filePath, 'utf8'), 'some content')

      fs.removeSync(filePath)
    })
    it("creates a recovery file and deletes it after saving", async () => {
      const mockWindow = {}
      const filePath = temp.path()

      fs.writeFileSync(filePath, "some content")
      await recoveryService.willSavePath(mockWindow, filePath)
      assert.equal(fs.listTreeSync(recoveryDirectory).length, 1)

      fs.writeFileSync(filePath, "changed")
      await recoveryService.didSavePath(mockWindow, filePath)
      assert.equal(fs.listTreeSync(recoveryDirectory).length, 0)
      assert.equal(fs.readFileSync(filePath, 'utf8'), "changed")

      fs.removeSync(filePath)
    })
    it('creates only one recovery file when many windows attempt to save the same file, deleting it when the last one finishes saving it', async () => {
      const mockWindow = {}
      const anotherMockWindow = {}
      const filePath = temp.path()

      fs.writeFileSync(filePath, 'some content')
      await recoveryService.willSavePath(mockWindow, filePath)
      await recoveryService.willSavePath(anotherMockWindow, filePath)
      assert.equal(fs.listTreeSync(recoveryDirectory).length, 1)

      fs.writeFileSync(filePath, 'changed')
      await recoveryService.didSavePath(mockWindow, filePath)
      assert.equal(fs.listTreeSync(recoveryDirectory).length, 1)
      assert.equal(fs.readFileSync(filePath, 'utf8'), 'changed')

      await recoveryService.didSavePath(anotherMockWindow, filePath)
      assert.equal(fs.listTreeSync(recoveryDirectory).length, 0)
      assert.equal(fs.readFileSync(filePath, 'utf8'), 'changed')

      fs.removeSync(filePath)
    })
 beforeEach(async () => fs.removeSync(directory.resolve('tagged.js')));
Example #16
0
 symlinkedPackages.forEach(({ realPackagePath, relativePackageDir }) => {
   const packagePath = path.join(buildPath, relativePackageDir);
   console.log(`  ---> Copying ${realPackagePath} to ${packagePath}`);
   fs.removeSync(packagePath);
   fs.copySync(realPackagePath, packagePath);
 });
Example #17
0
 afterEach(() => {
   delete process.env.ATOM_HOME
   fs.removeSync(electronUserDataPath)
   temp.cleanupSync()
   app.setPath('userData', defaultElectronUserDataPath)
 })
Example #18
0
 beforeEach(() => {
   delete process.env.ATOM_HOME
   fs.removeSync(portableAtomHomePath)
 })
Example #19
0
 beforeEach(() => {
   const gitPath = path.join(temp.dir, '.git')
   if (fs.isDirectorySync(gitPath)) fs.removeSync(gitPath)
 })
Example #20
0
 afterEach(function() {
   fs.removeSync(directory);
 });
 after(function (next) {
     Fs.removeSync(mockFilesDir + '/target/test2.txt');
     next();
 });
Example #22
0
 clear: function() {
   fs.removeSync(settingsFile);
 },
Example #23
0
var server = http.createServer(function(req, res) {
  serve(req, res, finalhandler(req, res));

  console.log("Request landed at " + req.url);

  if (req.url == "/frontendutils/hostname") {
    fs.writeFileSync(__dirname + "/frontend/hostname.txt", os.hostname());
  }

  if (url.parse(req.url, true).pathname == "/frontendutils/getenv") {
    var args = url.parse(req.url, true).query.args;

    fs.writeFileSync(__dirname + "/frontend/env.txt", GetEnv(args));
  }

  if (req.url == "/frontendutils/ls") {
    var errored = false;
    var FilesInCurrentDirectory;

    try {
      FilesInCurrentDirectory = fs.readdirSync(UserLocation);
    } catch(err) {
      if (err.code == "EACCES") {
        fs.writeFileSync(__dirname + "/frontend/lsfiles.txt", "ls: Cannot open " + UserLocation + ": Permission denied");
      }
      else {
        console.log(err);
      }
      errored = true;
    }

    if (errored == false) {
      fs.writeFileSync(__dirname + "/frontend/lsfiles.txt", FilesInCurrentDirectory);
    }
  }
  else

  if (url.parse(req.url, true).pathname == "/frontendutils/lsargs") {
    var LSArgs = url.parse(req.url, true).query.args;
    var files;
    var errored = false;

    if (LSArgs.startsWith("/")) {
      if (fs.isDirectorySync(fs.absolute(LSArgs)) == false) {
        if (fs.existsSync(fs.absolute(LSArgs)) == true) {
          fs.writeFileSync(__dirname + "/frontend/lsfiles.txt", fs.absolute(LSArgs));
          errored = true;
        }
        else {
          fs.writeFileSync(__dirname + "/frontend/lsfiles.txt", "ls: Invalid directory");
          errored = true;
        }
      }
      else {
        try {
          files = fs.readdirSync(fs.absolute(LSArgs));
        } catch(err) {
          if (err.code == "EACCES") {
            fs.writeFileSync(__dirname + "/frontend/lsfiles.txt", "ls: Cannot open " + LSArgs + ": Permission denied");
          }
          else {
            console.log(err);
          }
          errored = true;
        }
      }
    }
    else {
      if (fs.isDirectorySync(fs.absolute(UserLocation + "/" + LSArgs)) == false) {
        if (fs.existsSync(fs.absolute(UserLocation + "/" + LSArgs)) == true) {
          fs.writeFile(__dirname + "/frontend/lsfiles.txt", fs.absolute(UserLocation + "/" + LSArgs));
          errored = true;
        }
        else {
          fs.writeFileSync(__dirname + "/frontend/lsfiles.txt", "ls: Invalid directory");
          errored = true;
        }
      }
      else {
        try {
          files = fs.readdirSync(fs.absolute(UserLocation + "/" + LSArgs));
        } catch(err) {
          if (err.code == "EACCES") {
            fs.writeFileSync(__dirname + "/frontend/lsfiles.txt", "ls: Cannot open " + fs.absolute(UserLocation + "/" + LSArgs) + ": Permission denied");
          }
          else {
            console.log(err);
          }
          errored = true;
        }
      }
    }

	  if (errored == false) {
	    fs.writeFileSync(__dirname + "/frontend/lsfiles.txt", files);
	  }
  }
  else

  if (req.url == "/frontendutils/pwd") {
    fs.writeFileSync(__dirname + "/frontend/pwd.txt", UserLocation);
  }
  else

  if (url.parse(req.url, true).pathname == "/frontendutils/touch") {
    var args = url.parse(req.url, true).query.args;
    var SplitArgs = args.split("/");
    var ParentDirectory;
    var errored = false;

    if (SplitArgs.length > 1) {
      ParentDirectory = path.dirname(args);
    }

    if (ParentDirectory != null) {
      if (args.startsWith("/")) {
        if (fs.isDirectorySync(ParentDirectory) == false) {
          fs.writeFileSync(__dirname + "/frontend/touch_err.txt", "touch: Cannot create " + args + ": Invalid parent directory");
          errored = true;
        }
      }
      else {
        if (fs.isDirectorySync(UserLocation + "/" + ParentDirectory) == false) {
          fs.writeFileSync(__dirname + "/frontend/touch_err.txt", "touch: Cannot create " + args + ": Invalid parent directory");
          errored = true;
        }
      }
    }

    if (args.startsWith("/")) {
      if (fs.existsSync(args)) {
        fs.writeFileSync(__dirname + "/frontend/touch_err.txt", "touch: File already exists");
        errored = true;
      }

      if (errored == false) {
        fs.writeFile(args, "", function(err) {
          if (err) {
            if (err.code == "EACCES") {
              fs.writeFileSync(__dirname + "/frontend/touch_err.txt", "touch: Cannot create " + args + ": Permission denied");
            }
            else {
              console.log(err);
            }
          }
        });
      }
    }
    else {
      if (fs.existsSync(UserLocation + "/" + args)) {
        fs.writeFileSync(__dirname + "/frontend/touch_err.txt", "touch: File already exists");
        errored = true;
      }

      if (errored == false) {
        fs.writeFile(UserLocation + "/" + args, "", function(err) {
          if (err) {
            if (err.code == "EACCES") {
              fs.writeFileSync(__dirname + "/frontend/touch_err.txt", "touch: Cannot create " + args + ": Permission denied");
            }
            else {
              console.log(err);
            }
          }
        });
      }
    }
  }
  else

  if (req.url == "/frontendutils/delete_touch_err") {
    if (fs.existsSync(__dirname + "/frontend/touch_err.txt")) {
      fs.removeSync(__dirname + "/frontend/touch_err.txt");
    }
  }
  else

  if (url.parse(req.url, true).pathname == "/frontendutils/mkdir") {
    var args = url.parse(req.url, true).query.args;
    var SplitArgs = args.split("/");
    var ParentDirectory;
    var errored = false;

    if (SplitArgs.length > 1) {
      ParentDirectory = path.dirname(args);
    }

    if (ParentDirectory != null) {
      if (args.startsWith("/")) {
        if (fs.isDirectorySync(ParentDirectory) == false) {
          fs.writeFileSync(__dirname + "/frontend/mkdir_err.txt", "mkdir: Cannot create " + args + ": Invalid parent directory");
          errored = true;
        }
      }
      else {
        if (fs.isDirectorySync(UserLocation + "/" + ParentDirectory) == false) {
          fs.writeFile(__dirname + "/frontend/mkdir_err.txt", "mkdir: Cannot create " + args + ": Invalid parent directory");
          errored = true;
        }
      }
    }

    if (args.startsWith("/")) {
      if (fs.existsSync(args)) {
        fs.writeFileSync(__dirname + "/frontend/mkdir_err.txt", "mkdir: Directory already exists");
        errored = true;
      }

      if (errored == false) {
        fs.makeTree(args, function(err) {
          if (err) {
            if (err.code == "EACCES") {
              fs.writeFile(__dirname + "/frontend/mkdir_err.txt", "mkdir: Cannot create " + args + ": Permission denied", function(err) {
                if (err) {
                  console.log(err);
                }
              });
            }
            else {
              console.log(err);
            }
          }
        });
      }
    }
    else {
      if (fs.existsSync(UserLocation + "/" + args)) {
        fs.writeFileSync(__dirname + "/frontend/mkdir_err.txt", "mkdir: Directory already exists");
        errored = true;
      }

      if (errored == false) {
        fs.makeTree(UserLocation + "/" + args, function(err) {
          if (err) {
            if (err.code == "EACCES") {
              fs.writeFileSync(__dirname + "/frontend/mkdir_err.txt", "mkdir: Cannot create " + args + ": Permission denied");
            }
            else {
              console.log(err);
            }
          }
        });
      }
    }
  }
  else

  if (req.url == "/frontendutils/delete_mkdir_err") {
    if (fs.existsSync(__dirname + "/frontend/mkdir_err.txt")) {
      fs.removeSync(__dirname + "/frontend/mkdir_err.txt");
    }
  }
  else

  if (url.parse(req.url, true).pathname == "/frontendutils/cd") {
    var args = url.parse(req.url, true).query.args;
    var errored = false;

    if (args != undefined) {
      if (args.startsWith("/")) {
        if (fs.isDirectorySync(args) == false) {
          fs.writeFileSync(__dirname + "/frontend/cd_err.txt", "cd: Cannot cd to " + args + ": Invalid directory");
        }
      }
      else {
        if (fs.isDirectorySync(UserLocation + "/" + args) == false) {
          fs.writeFileSync(__dirname + "/frontend/cd_err.txt", "cd: Cannot cd to " + args + ": Invalid directory");
          errored = true;
        }
      }
    }
    else {
      UserLocation = GetEnv("HOME");
    }

    if (errored == false) {
      if (args.startsWith("/")) {
        UserLocation = args;
      }
      else {
        UserLocation = fs.absolute(UserLocation + "/" + args);
      }
    }
  }
  else

  if (req.url == "/frontendutils/delete_cd_err") {
    if (fs.existsSync(__dirname + "/frontend/cd_err.txt")) {
      fs.removeSync(__dirname + "/frontend/cd_err.txt");
    }
  }
  else

  if (url.parse(req.url, true).pathname == "/frontendutils/rm") {
    var args = url.parse(req.url, true).query.args;

    if (args.startsWith("/")) {
      if (fs.existsSync(args)) {
        fs.remove(args, function(err) {
          if (err) {
            if (err.code == "EACCES") {
              fs.writeFileSync(__dirname + "/frontend/rm_err.txt", "rm: " + args + ": permission denied");
            }
            else {
              console.log(err);
            }
          }
        });
      }
      else {
        fs.writeFileSync(__dirname + "/frontend/rm_err.txt", "rm: Invalid file/directory");
      }
    }
    else {
      if (fs.existsSync(UserLocation + "/" + args)) {
        fs.remove(UserLocation + "/" + args, function(err) {
          if (err) {
            if (err.code == "EACCES") {
              fs.writeFileSync(__dirname + "/frontend/rm_err.txt", "rm: " + args + ": permission denied");
            }
            else {
              console.log(err);
            }
          }
        });
      }
      else {
        fs.writeFileSync(__dirname + "/frontend/rm_err.txt", "rm: Invalid file/directory");
      }
    }
  }
  else

  if (req.url == "/frontendutils/delete_rm_err") {
    if (fs.existsSync(__dirname + "/frontend/rm_err.txt")) {
      fs.removeSync(__dirname + "/frontend/rm_err.txt");
    }
  }
});
Example #24
0
  return grunt.registerTask('docs-render', 'Builds html from the API docs', function() {
    let documentation, match, name, result, section, val;
    let classDocsOutputDir = grunt.config.get('classDocsOutputDir');

    // Parse API reference Markdown

    let classes = [];
    let apiJsonPath = path.join(classDocsOutputDir, 'api.json');
    let apiJSON = JSON.parse(grunt.file.read(apiJsonPath));

    for (var classname in apiJSON.classes) {
      // Parse a "@Section" out of the description if one is present
      let contents = apiJSON.classes[classname];
      let sectionRegex = /Section: ?([\w ]*)(?:$|\n)/;
      section = 'General';

      match = sectionRegex.exec(contents.description);
      if (match) {
        contents.description = contents.description.replace(match[0], '');
        section = match[1].trim();
      }

      classes.push({
        name: classname,
        documentation: contents,
        section,
      });
    }

    // Build Sidebar metadata we can hand off to each of the templates to
    // generate the sidebar
    let sidebar = {};
    for (var i = 0; i < classes.length; i++) {
      var current_class = classes[i];
      console.log(current_class.name + ' ' + current_class.section);

      if (!(current_class.section in sidebar)) {
        sidebar[current_class.section] = [];
      }
      sidebar[current_class.section].push(current_class.name);
    }

    // Prepare to render by loading handlebars partials
    let templatesPath = path.resolve(grunt.config('buildDir'), 'docs_templates');
    grunt.file.recurse(templatesPath, function(abspath, root, subdir, filename) {
      if (filename[0] === '_' && path.extname(filename) === '.html') {
        return Handlebars.registerPartial(filename, grunt.file.read(abspath));
      }
    });

    // Render Helpers

    let knownClassnames = {};
    for (classname in apiJSON.classes) {
      val = apiJSON.classes[classname];
      knownClassnames[classname.toLowerCase()] = val;
    }

    let expandTypeReferences = function(val) {
      let refRegex = /{([\w.]*)}/g;
      while ((match = refRegex.exec(val)) !== null) {
        let term = match[1].toLowerCase();
        let label = match[1];
        let url = false;
        if (Array.from(standardClasses).includes(term)) {
          url = standardClassURLRoot + term;
        } else if (thirdPartyClasses[term]) {
          url = thirdPartyClasses[term];
        } else if (knownClassnames[term]) {
          url = relativePathForClass(knownClassnames[term].name);
          grunt.log.ok('Found: ' + term);
        } else {
          console.warn(`Cannot find class named ${term}`);
        }

        if (url) {
          val = val.replace(match[0], `<a href='${url}'>${label}</a>`);
        }
      }
      return val;
    };

    let expandFuncReferences = function(val) {
      let refRegex = /{([\w]*)?::([\w]*)}/g;
      while ((match = refRegex.exec(val)) !== null) {
        var label;
        let [text, a, b] = Array.from(match);
        let url = false;
        if (a && b) {
          url = `${relativePathForClass(a)}#${b}`;
          label = `${a}::${b}`;
        } else {
          url = `#${b}`;
          label = `${b}`;
        }
        if (url) {
          val = val.replace(text, `<a href='${url}'>${label}</a>`);
        }
      }
      return val;
    };

    // DEBUG Render sidebar json
    // grunt.file.write(outputPathFor('sidebar.json'), JSON.stringify(sidebar, null, 2));

    // Render Class Pages
    let classTemplatePath = path.join(templatesPath, 'class.md');
    let classTemplate = Handlebars.compile(grunt.file.read(classTemplatePath));

    for ({ name, documentation, section } of Array.from(classes)) {
      // Recursively process `description` and `type` fields to process markdown,
      // expand references to types, functions and other files.
      processFields(documentation, ['description'], [expandFuncReferences]);
      processFields(documentation, ['type'], [expandTypeReferences]);

      result = classTemplate({ name, documentation, section });
      grunt.file.write(outputPathFor(name + '.md'), result);
    }

    let sidebarTemplatePath = path.join(templatesPath, 'sidebar.md');
    let sidebarTemplate = Handlebars.compile(grunt.file.read(sidebarTemplatePath));

    grunt.file.write(outputPathFor('Sidebar.md'), sidebarTemplate({ sidebar }));

    // Remove temp cjsx output
    return fs.removeSync(outputPathFor('temp-cjsx'));
  });
Example #25
0
 it('returns true if the path is deleted', () => {
   fs.removeSync(filePath)
   expect(repo.isPathModified(filePath)).toBeTruthy()
 })
Example #26
0
 targets[process.platform].forEach(function (target) {
   target = path.join(target, name)
   fs.removeSync(target)
   fs.copySync(source, target)
 })
Example #27
0
/**
 * Clean build directory
 */
function clean() {
  // Remove everything from the directory
  print(chalk.green('Build directory cleaned'))
  fs.removeSync(`${buildDirectory}/`)
}
Example #28
0
	'removePath': function (path) {
		atomFs.removeSync(path);
	}