copy-assets.js
1 // This module exports a function that copies all the static assets into the 2 // appropriate location in the build output directory. 3 4 'use strict'; 5 6 const path = require('path'); 7 const fs = require('fs-extra'); 8 const CONFIG = require('../config'); 9 const glob = require('glob'); 10 const includePathInPackagedApp = require('./include-path-in-packaged-app'); 11 12 module.exports = function() { 13 console.log(`Copying assets to ${CONFIG.intermediateAppPath}`); 14 let srcPaths = [ 15 path.join(CONFIG.repositoryRootPath, 'benchmarks', 'benchmark-runner.js'), 16 path.join(CONFIG.repositoryRootPath, 'dot-atom'), 17 path.join(CONFIG.repositoryRootPath, 'exports'), 18 path.join(CONFIG.repositoryRootPath, 'package.json'), 19 path.join(CONFIG.repositoryRootPath, 'static'), 20 path.join(CONFIG.repositoryRootPath, 'src'), 21 path.join(CONFIG.repositoryRootPath, 'vendor') 22 ]; 23 srcPaths = srcPaths.concat( 24 glob.sync(path.join(CONFIG.repositoryRootPath, 'spec', '*.*'), { 25 ignore: path.join('**', '*-spec.*') 26 }) 27 ); 28 for (let srcPath of srcPaths) { 29 fs.copySync(srcPath, computeDestinationPath(srcPath), { 30 filter: includePathInPackagedApp 31 }); 32 } 33 34 // Run a copy pass to dereference symlinked directories under node_modules. 35 // We do this to ensure that symlinked repo-local bundled packages get 36 // copied to the output folder correctly. We dereference only the top-level 37 // symlinks and not nested symlinks to avoid issues where symlinked binaries 38 // are duplicated in Atom's installation packages (see atom/atom#18490). 39 const nodeModulesPath = path.join(CONFIG.repositoryRootPath, 'node_modules'); 40 glob 41 .sync(path.join(nodeModulesPath, '*')) 42 .map(p => 43 fs.lstatSync(p).isSymbolicLink() 44 ? path.resolve(nodeModulesPath, fs.readlinkSync(p)) 45 : p 46 ) 47 .forEach(modulePath => { 48 const destPath = path.join( 49 CONFIG.intermediateAppPath, 50 'node_modules', 51 path.basename(modulePath) 52 ); 53 fs.copySync(modulePath, destPath, { filter: includePathInPackagedApp }); 54 }); 55 56 fs.copySync( 57 path.join( 58 CONFIG.repositoryRootPath, 59 'resources', 60 'app-icons', 61 CONFIG.channel, 62 'png', 63 '1024.png' 64 ), 65 path.join(CONFIG.intermediateAppPath, 'resources', 'atom.png') 66 ); 67 }; 68 69 function computeDestinationPath(srcPath) { 70 const relativePath = path.relative(CONFIG.repositoryRootPath, srcPath); 71 return path.join(CONFIG.intermediateAppPath, relativePath); 72 }