Пример #1
0
    it('opens an empty text editor and loads its parent directory in the tree-view when launched with a new file path in a remote directory', async function () {
      // Disable the tree-view because it will try to enumerate the contents of
      // the remote directory and, since it doesn't exist, throw an error.
      const configPath = path.join(process.env.ATOM_HOME, 'config.cson')
      const config = season.readFileSync(configPath)
      if (!config['*'].core) config['*'].core = {}
      config['*'].core.disabledPackages = ['tree-view']
      season.writeFileSync(configPath, config)

      const atomApplication = buildAtomApplication()
      const newRemoteFilePath = 'remote://server:3437/some/directory/path'
      const window = atomApplication.launch(parseCommandLine([newRemoteFilePath]))
      await focusWindow(window)
      const {projectPaths, editorTitle, editorText} = await evalInWebContents(window.browserWindow.webContents, function (sendBackToMainProcess) {
        atom.workspace.observeActivePaneItem(function (editor) {
          if (editor) {
            sendBackToMainProcess({
              projectPaths: atom.project.getPaths(),
              editorTitle: editor.getTitle(),
              editorText: editor.getText()
            })
          }
        })
      })
      assert.deepEqual(projectPaths, [newRemoteFilePath])
      assert.equal(editorTitle, path.basename(newRemoteFilePath))
      assert.equal(editorText, '')
    })
Пример #2
0
function buildPlatformMenuMetadata () {
  const menuPath = path.join(CONFIG.repositoryRootPath, 'menus', `${process.platform}.cson`)
  if (fs.existsSync(menuPath)) {
    return CSON.readFileSync(menuPath)
  } else {
    return null
  }
}
Пример #3
0
  readLocalSettings(path) {
    let data = null;
    try {
      data = CSON.readFileSync(`${path}/project.cson`);
    } catch (e) {
    }

    return data;
  }
Пример #4
0
function buildPlatformKeymapsMetadata () {
  const invalidPlatforms = ['darwin', 'freebsd', 'linux', 'sunos', 'win32'].filter(p => p !== process.platform)
  const keymapsPath = path.join(CONFIG.repositoryRootPath, 'keymaps')
  const keymaps = {}
  for (let keymapName of fs.readdirSync(keymapsPath)) {
    const keymapPath = path.join(keymapsPath, keymapName)
    if (keymapPath.endsWith('.cson') || keymapPath.endsWith('.json')) {
      const keymapPlatform = path.basename(keymapPath, path.extname(keymapPath))
      if (invalidPlatforms.indexOf(keymapPlatform) === -1) {
        keymaps[path.basename(keymapPath)] = CSON.readFileSync(keymapPath)
      }
    }
  }
  return keymaps
}
Пример #5
0
function getConfig () {
  const config = new Config()

  let configFilePath
  if (fs.existsSync(path.join(process.env.ATOM_HOME, 'config.json'))) {
    configFilePath = path.join(process.env.ATOM_HOME, 'config.json')
  } else if (fs.existsSync(path.join(process.env.ATOM_HOME, 'config.cson'))) {
    configFilePath = path.join(process.env.ATOM_HOME, 'config.cson')
  }

  if (configFilePath) {
    const configFileData = CSON.readFileSync(configFilePath)
    config.resetUserSettings(configFileData)
  }

  return config
}
Пример #6
0
 readFile(callback) {
   const exists = fs.existsSync(this.file());
   if (exists) {
     try {
       let projects = CSON.readFileSync(this.file()) || {};
       callback(projects);
       return projects;
     } catch (error) {
       const message = `Failed to load ${path.basename(this.file())}`;
       const detail = error.location != null ? error.stack : error.message;
       this.notifyFailure(message, detail);
     }
   } else {
     fs.writeFileSync(this.file(), '{}');
     callback({});
     return {};
   }
 }
Пример #7
0
    it('does not reopen any previously opened windows when launched with no path and `core.restorePreviousWindowsOnStart` is no', async () => {
      const atomApplication1 = buildAtomApplication()
      const [app1Window1] = await atomApplication1.launch(parseCommandLine([makeTempDir()]))
      await focusWindow(app1Window1)
      const [app1Window2] = await atomApplication1.launch(parseCommandLine([makeTempDir()]))
      await focusWindow(app1Window2)

      const configPath = path.join(process.env.ATOM_HOME, 'config.cson')
      const config = season.readFileSync(configPath)
      if (!config['*'].core) config['*'].core = {}
      config['*'].core.restorePreviousWindowsOnStart = 'no'
      season.writeFileSync(configPath, config)

      const atomApplication2 = buildAtomApplication()
      const [app2Window] = await atomApplication2.launch(parseCommandLine([]))
      await focusWindow(app2Window)
      assert.deepEqual(app2Window.representedDirectoryPaths, [])
    })
Пример #8
0
    it('does not reopen any previously opened windows when launched with no path and `core.restorePreviousWindowsOnStart` is false', async function () {
      const atomApplication1 = buildAtomApplication()
      const app1Window1 = atomApplication1.launch(parseCommandLine([makeTempDir()]))
      await focusWindow(app1Window1)
      const app1Window2 = atomApplication1.launch(parseCommandLine([makeTempDir()]))
      await focusWindow(app1Window2)

      const configPath = path.join(process.env.ATOM_HOME, 'config.cson')
      const config = season.readFileSync(configPath)
      if (!config['*'].core) config['*'].core = {}
      config['*'].core.restorePreviousWindowsOnStart = false
      season.writeFileSync(configPath, config)

      const atomApplication2 = buildAtomApplication()
      const app2Window = atomApplication2.launch(parseCommandLine([]))
      await focusWindow(app2Window)
      assert.deepEqual(await getTreeViewRootDirectories(app2Window), [])
    })
Пример #9
0
    it('does not open an empty editor when opened with no path if the core.openEmptyEditorOnStart config setting is false', async () => {
      const configPath = path.join(process.env.ATOM_HOME, 'config.cson')
      const config = season.readFileSync(configPath)
      if (!config['*'].core) config['*'].core = {}
      config['*'].core.openEmptyEditorOnStart = false
      season.writeFileSync(configPath, config)

      const atomApplication = buildAtomApplication()
      const [window1] = await atomApplication.launch(parseCommandLine([]))
      await focusWindow(window1)

     // wait a bit just to make sure we don't pass due to querying the render process before it loads
      await timeoutPromise(1000)

      const itemCount = await evalInWebContents(window1.browserWindow.webContents, sendBackToMainProcess => {
        sendBackToMainProcess(atom.workspace.getActivePane().getItems().length)
      })
      assert.equal(itemCount, 0)
    })
Пример #10
0
function buildBundledPackagesMetadata () {
  const packages = {}
  for (let packageName of Object.keys(CONFIG.appMetadata.packageDependencies)) {
    const packagePath = path.join(CONFIG.intermediateAppPath, 'node_modules', packageName)
    const packageMetadataPath = path.join(packagePath, 'package.json')
    const packageMetadata = JSON.parse(fs.readFileSync(packageMetadataPath, 'utf8'))
    normalizePackageData(packageMetadata, (msg) => {
      console.warn(`Invalid package metadata. ${packageMetadata.name}: ${msg}`)
    }, true)
    if (packageMetadata.repository && packageMetadata.repository.url && packageMetadata.repository.type === 'git') {
      packageMetadata.repository.url = packageMetadata.repository.url.replace(/^git\+/, '')
    }

    delete packageMetadata['_from']
    delete packageMetadata['_id']
    delete packageMetadata['dist']
    delete packageMetadata['readme']
    delete packageMetadata['readmeFilename']

    const packageModuleCache = packageMetadata._atomModuleCache || {}
    if (packageModuleCache.extensions && packageModuleCache.extensions['.json']) {
      const index = packageModuleCache.extensions['.json'].indexOf('package.json')
      if (index !== -1) {
        packageModuleCache.extensions['.json'].splice(index, 1)
      }
    }

    const packageNewMetadata = {metadata: packageMetadata, keymaps: {}, menus: {}, grammarPaths: [], settings: {}}

    packageNewMetadata.rootDirPath = path.relative(CONFIG.intermediateAppPath, packagePath)

    if (packageMetadata.main) {
      const mainPath = require.resolve(path.resolve(packagePath, packageMetadata.main))
      packageNewMetadata.main = path.relative(path.join(CONFIG.intermediateAppPath, 'static'), mainPath)
      // Convert backward slashes to forward slashes in order to allow package
      // main modules to be required from the snapshot. This is because we use
      // forward slashes to cache the sources in the snapshot, so we need to use
      // them here as well.
      packageNewMetadata.main = packageNewMetadata.main.replace(/\\/g, '/')
    }

    const packageKeymapsPath = path.join(packagePath, 'keymaps')
    if (fs.existsSync(packageKeymapsPath)) {
      for (let packageKeymapName of fs.readdirSync(packageKeymapsPath)) {
        const packageKeymapPath = path.join(packageKeymapsPath, packageKeymapName)
        if (packageKeymapPath.endsWith('.cson') || packageKeymapPath.endsWith('.json')) {
          const relativePath = path.relative(CONFIG.intermediateAppPath, packageKeymapPath)
          packageNewMetadata.keymaps[relativePath] = CSON.readFileSync(packageKeymapPath)
        }
      }
    }

    const packageMenusPath = path.join(packagePath, 'menus')
    if (fs.existsSync(packageMenusPath)) {
      for (let packageMenuName of fs.readdirSync(packageMenusPath)) {
        const packageMenuPath = path.join(packageMenusPath, packageMenuName)
        if (packageMenuPath.endsWith('.cson') || packageMenuPath.endsWith('.json')) {
          const relativePath = path.relative(CONFIG.intermediateAppPath, packageMenuPath)
          packageNewMetadata.menus[relativePath] = CSON.readFileSync(packageMenuPath)
        }
      }
    }

    const packageGrammarsPath = path.join(packagePath, 'grammars')
    for (let packageGrammarPath of fs.listSync(packageGrammarsPath, ['json', 'cson'])) {
      const relativePath = path.relative(CONFIG.intermediateAppPath, packageGrammarPath)
      packageNewMetadata.grammarPaths.push(relativePath)
    }

    const packageSettingsPath = path.join(packagePath, 'settings')
    for (let packageSettingPath of fs.listSync(packageSettingsPath, ['json', 'cson'])) {
      const relativePath = path.relative(CONFIG.intermediateAppPath, packageSettingPath)
      packageNewMetadata.settings[relativePath] = CSON.readFileSync(packageSettingPath)
    }

    const packageStyleSheetsPath = path.join(packagePath, 'styles')
    let styleSheets = null
    if (packageMetadata.mainStyleSheet) {
      styleSheets = [fs.resolve(packagePath, packageMetadata.mainStyleSheet)]
    } else if (packageMetadata.styleSheets) {
      styleSheets = packageMetadata.styleSheets.map((name) => (
        fs.resolve(packageStyleSheetsPath, name, ['css', 'less', ''])
      ))
    } else {
      const indexStylesheet = fs.resolve(packagePath, 'index', ['css', 'less'])
      if (indexStylesheet) {
        styleSheets = [indexStylesheet]
      } else {
        styleSheets = fs.listSync(packageStyleSheetsPath, ['css', 'less'])
      }
    }

    packageNewMetadata.styleSheetPaths =
      styleSheets.map(styleSheetPath => path.relative(packagePath, styleSheetPath))

    packages[packageMetadata.name] = packageNewMetadata
    if (packageModuleCache.extensions) {
      for (let extension of Object.keys(packageModuleCache.extensions)) {
        const paths = packageModuleCache.extensions[extension]
        if (paths.length === 0) {
          delete packageModuleCache.extensions[extension]
        }
      }
    }
  }
  return packages
}
Пример #11
0
function readFileSync(file) {
   return CSON.readFileSync(file);
}
Пример #12
0
 // Extended: Read a grammar synchronously but don't add it to the registry.
 //
 // * `grammarPath` A {String} absolute file path to a grammar file.
 //
 // Returns a {Grammar}.
 readGrammarSync (grammarPath) {
   return this.createGrammar(grammarPath, CSON.readFileSync(grammarPath) || {})
 }
Пример #13
0
function buildBundledPackagesMetadata () {
  const packages = {}
  for (let packageName of Object.keys(CONFIG.appMetadata.packageDependencies)) {
    const packagePath = path.join(CONFIG.intermediateAppPath, 'node_modules', packageName)
    const packageMetadataPath = path.join(packagePath, 'package.json')
    const packageMetadata = JSON.parse(fs.readFileSync(packageMetadataPath, 'utf8'))
    normalizePackageData(packageMetadata, () => {
      throw new Error(`Invalid package metadata. ${metadata.name}: ${msg}`)
    }, true)
    if (packageMetadata.repository && packageMetadata.repository.url && packageMetadata.repository.type === 'git') {
      packageMetadata.repository.url = packageMetadata.repository.url.replace(/^git\+/, '')
    }

    delete packageMetadata['_from']
    delete packageMetadata['_id']
    delete packageMetadata['dist']
    delete packageMetadata['readme']
    delete packageMetadata['readmeFilename']

    const packageModuleCache = packageMetadata._atomModuleCache || {}
    if (packageModuleCache.extensions && packageModuleCache.extensions['.json']) {
      const index = packageModuleCache.extensions['.json'].indexOf('package.json')
      if (index !== -1) {
        packageModuleCache.extensions['.json'].splice(index, 1)
      }
    }

    const packageNewMetadata = {metadata: packageMetadata, keymaps: {}, menus: {}}
    if (packageMetadata.main) {
      const mainPath = require.resolve(path.resolve(packagePath, packageMetadata.main))
      packageNewMetadata.main = path.relative(CONFIG.intermediateAppPath, mainPath)
    }

    const packageKeymapsPath = path.join(packagePath, 'keymaps')
    if (fs.existsSync(packageKeymapsPath)) {
      for (let packageKeymapName of fs.readdirSync(packageKeymapsPath)) {
        const packageKeymapPath = path.join(packageKeymapsPath, packageKeymapName)
        if (packageKeymapPath.endsWith('.cson') || packageKeymapPath.endsWith('.json')) {
          const relativePath = path.relative(CONFIG.intermediateAppPath, packageKeymapPath)
          packageNewMetadata.keymaps[relativePath] = CSON.readFileSync(packageKeymapPath)
        }
      }
    }

    const packageMenusPath = path.join(packagePath, 'menus')
    if (fs.existsSync(packageMenusPath)) {
      for (let packageMenuName of fs.readdirSync(packageMenusPath)) {
        const packageMenuPath = path.join(packageMenusPath, packageMenuName)
        if (packageMenuPath.endsWith('.cson') || packageMenuPath.endsWith('.json')) {
          const relativePath = path.relative(CONFIG.intermediateAppPath, packageMenuPath)
          packageNewMetadata.menus[relativePath] = CSON.readFileSync(packageMenuPath)
        }
      }
    }

    packages[packageMetadata.name] = packageNewMetadata
    if (packageModuleCache.extensions) {
      for (let extension of Object.keys(packageModuleCache.extensions)) {
        const paths = packageModuleCache.extensions[extension]
        if (paths.length === 0) {
          delete packageModuleCache.extensions[extension]
        }
      }
    }
  }
  return packages
}