Move shell scripts copying into package-application step

Signed-off-by: Nathan Sobo <nathan@github.com>
This commit is contained in:
Antonio Scandurra
2016-07-28 20:05:49 +02:00
committed by Nathan Sobo
parent 6804156266
commit 510ef53398
4 changed files with 99 additions and 100 deletions

View File

@@ -10,13 +10,12 @@ const appMetadata = require('../package.json')
const repositoryRootPath = path.resolve(__dirname, '..')
const buildOutputPath = path.join(repositoryRootPath, 'out')
const intermediateAppPath = path.join(buildOutputPath, 'app')
const intermediateShellCommandsPath = path.join(buildOutputPath, 'shell')
const cachePath = path.join(repositoryRootPath, 'cache')
const channel = getChannel()
module.exports = {
appMetadata, channel,
repositoryRootPath, buildOutputPath, intermediateAppPath, intermediateShellCommandsPath,
repositoryRootPath, buildOutputPath, intermediateAppPath,
cachePath
}

View File

@@ -7,11 +7,10 @@ const path = require('path')
const fs = require('fs-extra')
const CONFIG = require('../config')
const glob = require('glob')
const includePathInPackagedApp = require('./include-path-in-packaged-app')
module.exports = function () {
console.log(`Copying assets to ${CONFIG.intermediateAppPath}...`);
const ignoredPathsRegExp = buildIgnoredPathsRegExp()
const skipIgnoredPaths = (path) => !ignoredPathsRegExp.test(path)
let srcPaths = [
path.join(CONFIG.repositoryRootPath, 'dot-atom'),
path.join(CONFIG.repositoryRootPath, 'exports'),
@@ -25,17 +24,7 @@ module.exports = function () {
]
srcPaths = srcPaths.concat(glob.sync(path.join(CONFIG.repositoryRootPath, 'spec', '*.*'), {ignore: path.join('**', '*-spec.*')}))
for (let srcPath of srcPaths) {
fs.copySync(srcPath, computeDestinationPath(srcPath), {filter: skipIgnoredPaths})
}
console.log(`Copying shell commands to ${CONFIG.intermediateShellCommandsPath}...`);
fs.copySync(
path.join(CONFIG.repositoryRootPath, 'apm', 'node_modules', 'atom-package-manager'),
path.join(CONFIG.intermediateShellCommandsPath, 'apm'),
{filter: skipIgnoredPaths}
)
if (process.platform !== 'windows') {
fs.copySync(path.join(CONFIG.repositoryRootPath, 'atom.sh'), path.join(CONFIG.intermediateShellCommandsPath, 'atom.sh'))
fs.copySync(srcPath, computeDestinationPath(srcPath), {filter: includePathInPackagedApp})
}
}
@@ -43,73 +32,3 @@ function computeDestinationPath (srcPath) {
const relativePath = path.relative(CONFIG.repositoryRootPath, srcPath)
return path.join(CONFIG.intermediateAppPath, relativePath)
}
function buildIgnoredPathsRegExp () {
const ignoreRegExps = [
escapeRegExp(path.join('git-utils', 'deps')),
escapeRegExp(path.join('oniguruma', 'deps')),
escapeRegExp(path.join('less', 'dist')),
escapeRegExp(path.join('npm', 'doc')),
escapeRegExp(path.join('npm', 'html')),
escapeRegExp(path.join('npm', 'man')),
escapeRegExp(path.join('npm', 'node_modules', '.bin', 'beep')),
escapeRegExp(path.join('npm', 'node_modules', '.bin', 'clear')),
escapeRegExp(path.join('npm', 'node_modules', '.bin', 'starwars')),
escapeRegExp(path.join('pegjs', 'examples')),
escapeRegExp(path.join('get-parameter-names', 'node_modules', 'testla')),
escapeRegExp(path.join('get-parameter-names', 'node_modules', '.bin', 'testla')),
escapeRegExp(path.join('jasmine-reporters', 'ext')),
escapeRegExp(path.join('node_modules', 'nan')),
escapeRegExp(path.join('node_modules', 'native-mate')),
escapeRegExp(path.join('build', 'binding.Makefile')),
escapeRegExp(path.join('build', 'config.gypi')),
escapeRegExp(path.join('build', 'gyp-mac-tool')),
escapeRegExp(path.join('build', 'Makefile')),
escapeRegExp(path.join('build', 'Release', 'obj.target')),
escapeRegExp(path.join('build', 'Release', 'obj')),
escapeRegExp(path.join('build', 'Release', '.deps')),
escapeRegExp(path.join('vendor', 'apm')),
// These are only required in dev-mode, when pegjs grammars aren't precompiled
escapeRegExp(path.join('node_modules', 'loophole')),
escapeRegExp(path.join('node_modules', 'pegjs')),
escapeRegExp(path.join('node_modules', '.bin', 'pegjs')),
escapeRegExp(path.join('node_modules', 'spellchecker', 'vendor', 'hunspell') + path.sep) + '.*',
escapeRegExp(path.join('build', 'Release') + path.sep) + '.*\\.pdb',
// Ignore *.cc and *.h files from native modules
escapeRegExp(path.join('ctags', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('git-utils', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('keytar', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('nslog', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('oniguruma', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('pathwatcher', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('runas', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('scrollbar-style', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('spellchecker', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('cached-run-in-this-context', 'src') + path.sep) + '.*\\.(cc|h)?',
escapeRegExp(path.join('keyboard-layout', 'src') + path.sep) + '.*\\.(cc|h|mm)*',
// Ignore build files
escapeRegExp(path.sep) + 'binding\\.gyp$',
escapeRegExp(path.sep) + '.+\\.target.mk$',
escapeRegExp(path.sep) + 'linker\\.lock$',
escapeRegExp(path.join('build', 'Release') + path.sep) + '.+\\.node\\.dSYM',
// Ignore test, spec and example folders for packages
'node_modules' + escapeRegExp(path.sep) + '.*' + escapeRegExp(path.sep) + '_*te?sts?_*' + escapeRegExp(path.sep),
'node_modules' + escapeRegExp(path.sep) + '.*' + escapeRegExp(path.sep) + 'spec' + escapeRegExp(path.sep),
'node_modules' + escapeRegExp(path.sep) + '.*' + escapeRegExp(path.sep) + 'examples?' + escapeRegExp(path.sep),
]
// Ignore Hunspell dictionaries only on macOS.
if (process.platform === 'darwin') {
ignoreRegExps.push(escapeRegExp(path.join('spellchecker', 'vendor', 'hunspell_dictionaries')))
}
const regExpSource = ignoreRegExps.map(path => `(${path})`).join('|')
return new RegExp(regExpSource)
}
function escapeRegExp (string) {
return string.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&")
}

View File

@@ -0,0 +1,76 @@
'use strict'
const path = require('path')
module.exports = function (path) {
return !EXCLUDED_PATHS_REGEXP.test(path)
}
const EXCLUDE_REGEXPS_SOURCES = [
escapeRegExp(path.join('git-utils', 'deps')),
escapeRegExp(path.join('oniguruma', 'deps')),
escapeRegExp(path.join('less', 'dist')),
escapeRegExp(path.join('npm', 'doc')),
escapeRegExp(path.join('npm', 'html')),
escapeRegExp(path.join('npm', 'man')),
escapeRegExp(path.join('npm', 'node_modules', '.bin', 'beep')),
escapeRegExp(path.join('npm', 'node_modules', '.bin', 'clear')),
escapeRegExp(path.join('npm', 'node_modules', '.bin', 'starwars')),
escapeRegExp(path.join('pegjs', 'examples')),
escapeRegExp(path.join('get-parameter-names', 'node_modules', 'testla')),
escapeRegExp(path.join('get-parameter-names', 'node_modules', '.bin', 'testla')),
escapeRegExp(path.join('jasmine-reporters', 'ext')),
escapeRegExp(path.join('node_modules', 'nan')),
escapeRegExp(path.join('node_modules', 'native-mate')),
escapeRegExp(path.join('build', 'binding.Makefile')),
escapeRegExp(path.join('build', 'config.gypi')),
escapeRegExp(path.join('build', 'gyp-mac-tool')),
escapeRegExp(path.join('build', 'Makefile')),
escapeRegExp(path.join('build', 'Release', 'obj.target')),
escapeRegExp(path.join('build', 'Release', 'obj')),
escapeRegExp(path.join('build', 'Release', '.deps')),
escapeRegExp(path.join('vendor', 'apm')),
// These are only required in dev-mode, when pegjs grammars aren't precompiled
escapeRegExp(path.join('node_modules', 'loophole')),
escapeRegExp(path.join('node_modules', 'pegjs')),
escapeRegExp(path.join('node_modules', '.bin', 'pegjs')),
escapeRegExp(path.join('node_modules', 'spellchecker', 'vendor', 'hunspell') + path.sep) + '.*',
escapeRegExp(path.join('build', 'Release') + path.sep) + '.*\\.pdb',
// Ignore *.cc and *.h files from native modules
escapeRegExp(path.join('ctags', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('git-utils', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('keytar', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('nslog', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('oniguruma', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('pathwatcher', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('runas', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('scrollbar-style', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('spellchecker', 'src') + path.sep) + '.*\\.(cc|h)*',
escapeRegExp(path.join('cached-run-in-this-context', 'src') + path.sep) + '.*\\.(cc|h)?',
escapeRegExp(path.join('keyboard-layout', 'src') + path.sep) + '.*\\.(cc|h|mm)*',
// Ignore build files
escapeRegExp(path.sep) + 'binding\\.gyp$',
escapeRegExp(path.sep) + '.+\\.target.mk$',
escapeRegExp(path.sep) + 'linker\\.lock$',
escapeRegExp(path.join('build', 'Release') + path.sep) + '.+\\.node\\.dSYM',
// Ignore test, spec and example folders for packages
'node_modules' + escapeRegExp(path.sep) + '.*' + escapeRegExp(path.sep) + '_*te?sts?_*' + escapeRegExp(path.sep),
'node_modules' + escapeRegExp(path.sep) + '.*' + escapeRegExp(path.sep) + 'spec' + escapeRegExp(path.sep),
'node_modules' + escapeRegExp(path.sep) + '.*' + escapeRegExp(path.sep) + 'examples?' + escapeRegExp(path.sep),
]
// Ignore Hunspell dictionaries only on macOS.
if (process.platform === 'darwin') {
EXCLUDE_REGEXPS_SOURCES.push(escapeRegExp(path.join('spellchecker', 'vendor', 'hunspell_dictionaries')))
}
const EXCLUDED_PATHS_REGEXP = new RegExp(
EXCLUDE_REGEXPS_SOURCES.map(path => `(${path})`).join('|')
)
function escapeRegExp (string) {
return string.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&")
}

View File

@@ -1,15 +1,10 @@
'use strict'
// This is where we'll run electron-packager on our intermediate app dir.
// It takes an ignore regex for paths to exclude, and I've started on a function
// to build up this regexp based on existing work in build-task.coffee. We should
// try to lean on electron-packager to do as much of the work for us as possible
// other than transpilation. It looks like it has a programmatic API. We'll need to
// copy more stuff such as the package.json for the packager to work correctly.
const assert = require('assert')
const fs = require('fs-extra')
const path = require('path')
const electronPackager = require('electron-packager')
const includePathInPackagedApp = require('./include-path-in-packaged-app')
const CONFIG = require('../config')
@@ -26,22 +21,32 @@ module.exports = function () {
'overwrite': true,
'platform': process.platform,
'version': CONFIG.appMetadata.electronVersion
}, (err, appPaths) => {
}, (err, packagedAppPaths) => {
if (err) {
console.error(err)
} else {
if (appPaths.length > 1) {
throw new Error('TODO: handle this case!')
}
assert(packagedAppPaths.length === 1, 'Generated more than one electron application!')
const packagedAppPath = packagedAppPaths[0]
if (process.platform === 'darwin') {
const bundleResourcesPath = path.join(appPaths[0], 'Atom.app', 'Contents', 'Resources')
fs.copySync(CONFIG.intermediateShellCommandsPath, path.join(bundleResourcesPath, 'app'))
const bundledResourcesPath = path.join(packagedAppPath, 'Atom.app', 'Contents', 'Resources')
const bundledShellCommandsPath = path.join(bundledResourcesPath, 'app')
console.log(`Copying shell commands to ${bundledShellCommandsPath}...`);
fs.copySync(
path.join(CONFIG.repositoryRootPath, 'apm', 'node_modules', 'atom-package-manager'),
path.join(bundledShellCommandsPath, 'apm'),
{filter: includePathInPackagedApp}
)
if (process.platform !== 'windows') {
// Existing symlinks on user systems point to an outdated path, so just symlink it to the real location of the apm binary.
// TODO: Change command installer to point to appropriate path and remove this fallback after a few releases.
fs.symlinkSync(path.join('..', '..', 'bin', 'apm'), path.join(bundledShellCommandsPath, 'apm', 'node_modules', '.bin', 'apm'))
fs.copySync(path.join(CONFIG.repositoryRootPath, 'atom.sh'), path.join(bundledShellCommandsPath, 'atom.sh'))
}
} else {
throw new Error('TODO: handle this case!')
}
console.log(`Application bundle(s) created on ${appPaths}`)
console.log(`Application bundle(s) created on ${packagedAppPath}`)
}
})
}