mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
🔨 Apply filter to dirs as well as files
This commit is contained in:
parent
4a5ccf1c4d
commit
886faf237d
@ -4,7 +4,7 @@
|
||||
'use strict'
|
||||
|
||||
const path = require('path')
|
||||
const fs = require('fs-extra')
|
||||
const copySync = require('./copy-sync')
|
||||
const CONFIG = require('../config')
|
||||
const glob = require('glob')
|
||||
const includePathInPackagedApp = require('./include-path-in-packaged-app')
|
||||
@ -22,10 +22,10 @@ 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: includePathInPackagedApp})
|
||||
copySync(srcPath, computeDestinationPath(srcPath), {filter: includePathInPackagedApp})
|
||||
}
|
||||
|
||||
fs.copySync(
|
||||
copySync(
|
||||
path.join(CONFIG.repositoryRootPath, 'resources', 'app-icons', CONFIG.channel, 'png', '1024.png'),
|
||||
path.join(CONFIG.intermediateAppPath, 'resources', 'atom.png')
|
||||
)
|
||||
|
50
script/lib/copy-sync.js
Normal file
50
script/lib/copy-sync.js
Normal file
@ -0,0 +1,50 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
|
||||
module.exports = copySync
|
||||
|
||||
function copySync(src, dest, options) {
|
||||
options = options || {}
|
||||
options.filter = options.filter || () => true
|
||||
|
||||
const destFolder = path.dirname(dest)
|
||||
const stat = fs.statSync(src)
|
||||
|
||||
if (options.filter(src)) {
|
||||
if (stat.isFile()) {
|
||||
if (!fs.existsSync(destFolder)) fs.mkdirsSync(destFolder)
|
||||
copyFileSync(src, dest, options)
|
||||
} else if (stat.isDirectory()) {
|
||||
fs.readdirSync(src).forEach(content => {
|
||||
copySync(path.join(src, content), path.join(dest, content), options)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const BUF_LENGTH = 4096
|
||||
const _buff = new Buffer(BUF_LENGTH)
|
||||
|
||||
function copyFileSync(srcFile, destFile) {
|
||||
if (fs.existsSync(destFile)) {
|
||||
fs.chmodSync(destFile, parseInt('777', 8))
|
||||
fs.unlinkSync(destFile)
|
||||
}
|
||||
|
||||
const fileRead = fs.openSync(srcFile, 'r')
|
||||
const stat = fs.fstatSync(fileRead)
|
||||
const fileWrite = fs.openSync(destFile, 'w', stat.mode)
|
||||
let bytesRead = 1
|
||||
let pos = 0
|
||||
|
||||
while (bytesRead > 0) {
|
||||
bytesRead = fs.readSync(fileRead, _buff, 0, BUF_LENGTH, pos)
|
||||
fs.writeSync(fileWrite, _buff, 0, bytesRead)
|
||||
pos += bytesRead
|
||||
}
|
||||
|
||||
fs.closeSync(fileRead)
|
||||
fs.closeSync(fileWrite)
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const copySync = require('./copy-sync')
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
|
||||
@ -12,7 +13,7 @@ module.exports = function (packagedAppPath) {
|
||||
fs.removeSync(installationDirPath)
|
||||
}
|
||||
console.log(`Installing ${packagedAppPath} at ${installationDirPath}`)
|
||||
fs.copySync(packagedAppPath, installationDirPath)
|
||||
copySync(packagedAppPath, installationDirPath)
|
||||
} else {
|
||||
throw new Error("Not implemented yet.")
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('assert')
|
||||
const copySync = require('./copy-sync')
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
const childProcess = require('child_process')
|
||||
@ -52,7 +53,7 @@ module.exports = function () {
|
||||
|
||||
function copyNonASARResources (packagedAppPath, bundledResourcesPath) {
|
||||
console.log(`Copying non-ASAR resources to ${bundledResourcesPath}`)
|
||||
fs.copySync(
|
||||
copySync(
|
||||
path.join(CONFIG.repositoryRootPath, 'apm', 'node_modules', 'atom-package-manager'),
|
||||
path.join(bundledResourcesPath, 'app', 'apm'),
|
||||
{filter: includePathInPackagedApp}
|
||||
@ -61,18 +62,18 @@ function copyNonASARResources (packagedAppPath, bundledResourcesPath) {
|
||||
// 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(bundledResourcesPath, 'app', 'apm', 'node_modules', '.bin', 'apm'))
|
||||
fs.copySync(path.join(CONFIG.repositoryRootPath, 'atom.sh'), path.join(bundledResourcesPath, 'app', 'atom.sh'))
|
||||
copySync(path.join(CONFIG.repositoryRootPath, 'atom.sh'), path.join(bundledResourcesPath, 'app', 'atom.sh'))
|
||||
}
|
||||
if (process.platform === 'darwin') {
|
||||
fs.copySync(path.join(CONFIG.repositoryRootPath, 'resources', 'mac', 'file.icns'), path.join(bundledResourcesPath, 'file.icns'))
|
||||
copySync(path.join(CONFIG.repositoryRootPath, 'resources', 'mac', 'file.icns'), path.join(bundledResourcesPath, 'file.icns'))
|
||||
} else if (process.platform === 'linux') {
|
||||
fs.copySync(path.join(CONFIG.repositoryRootPath, 'resources', 'app-icons', CONFIG.channel, 'png', '1024.png'), path.join(packagedAppPath, 'atom.png'))
|
||||
copySync(path.join(CONFIG.repositoryRootPath, 'resources', 'app-icons', CONFIG.channel, 'png', '1024.png'), path.join(packagedAppPath, 'atom.png'))
|
||||
} else if (process.platform === 'win32') {
|
||||
fs.copySync(path.join('resources', 'win', 'atom.cmd'), path.join(bundledResourcesPath, 'cli', 'atom.cmd'))
|
||||
fs.copySync(path.join('resources', 'win', 'atom.sh'), path.join(bundledResourcesPath, 'cli', 'atom.sh'))
|
||||
fs.copySync(path.join('resources', 'win', 'atom.js'), path.join(bundledResourcesPath, 'cli', 'atom.js'))
|
||||
fs.copySync(path.join('resources', 'win', 'apm.cmd'), path.join(bundledResourcesPath, 'cli', 'apm.cmd'))
|
||||
fs.copySync(path.join('resources', 'win', 'apm.sh'), path.join(bundledResourcesPath, 'cli', 'apm.sh'))
|
||||
copySync(path.join('resources', 'win', 'atom.cmd'), path.join(bundledResourcesPath, 'cli', 'atom.cmd'))
|
||||
copySync(path.join('resources', 'win', 'atom.sh'), path.join(bundledResourcesPath, 'cli', 'atom.sh'))
|
||||
copySync(path.join('resources', 'win', 'atom.js'), path.join(bundledResourcesPath, 'cli', 'atom.js'))
|
||||
copySync(path.join('resources', 'win', 'apm.cmd'), path.join(bundledResourcesPath, 'cli', 'apm.cmd'))
|
||||
copySync(path.join('resources', 'win', 'apm.sh'), path.join(bundledResourcesPath, 'cli', 'apm.sh'))
|
||||
}
|
||||
|
||||
console.log(`Writing LICENSE.md to ${bundledResourcesPath}`)
|
||||
|
Loading…
Reference in New Issue
Block a user