UNPKG

ecology9-src4js-tools

Version:

src4js-tools

91 lines (76 loc) 3.16 kB
var path = require('path'); var fs = require('fs'); //try to detect if user is using a custom scripts version var custom_scripts = false; const cs_index = process.argv.indexOf('--scripts-version'); if (cs_index > -1 && cs_index + 1 <= process.argv.length) { custom_scripts = process.argv[cs_index + 1]; } //Allow custom overrides package location const projectDir = path.resolve(fs.realpathSync(process.cwd())); var config_overrides = projectDir + '/config-overrides'; const co_index = process.argv.indexOf('--config-overrides'); if (co_index > -1 && co_index + 1 <= process.argv.length) { config_overrides = path.resolve(process.argv[co_index + 1]); process.argv.splice(co_index, 2); } const scriptVersion = custom_scripts || 'react-scripts'; const modulePath = path.join( require.resolve(`${scriptVersion}/package.json`), '..' ); let paths = require(modulePath + '/config/paths'); // const path = require('path'); // const fs = require('fs'); // const url = require('url'); const appDirectory = fs.realpathSync(process.cwd()); const resolveApp = relativePath => path.resolve(appDirectory, relativePath); const weaverConfig = require('../../../../webpack-config'); // console.log("paths old:",paths); paths.appIndexJs = resolveApp(weaverConfig.appIndexJs); //resolveApp('../test/src/index.js'); paths.appSrc = resolveApp(weaverConfig.appSrc); //resolveApp('../test'); paths.appPath = resolveApp(weaverConfig.appSrc); //resolveApp('../test'); paths.appHtml = resolveApp(weaverConfig.appHtml); paths.appBuild = resolveApp(weaverConfig.appBuild); paths.appWealink = weaverConfig.appWealink ? resolveApp(weaverConfig.appWealink) : weaverConfig.appWealink; paths.servedPath = weaverConfig.servedPath; paths.appThemePath = resolveApp(weaverConfig.appThemePath); paths.skeletonLoadingType = weaverConfig.skeletonLoadingType; let copyFilesPath = []; if (Array.isArray(weaverConfig.copyFiles) && weaverConfig.copyFiles.length > 0) { copyFilesPath = weaverConfig.copyFiles.map(copyFile => ({ from: resolveApp(copyFile.from), to: resolveApp(copyFile.to), })); } const fse = require('fs-extra'); const chalk = require('chalk'); const argv = require('yargs').argv; if (process.env.NODE_ENV === 'production') { if (argv.local) { fse.emptyDirSync(paths.appWealink); fse.copySync(resolveApp('public4local'), paths.appWealink, { dereference: true }); } paths.appPublic = resolveApp('public4build'); if (Array.isArray(copyFilesPath)) { setTimeout(() => { // const reg = /[^\/]+\/[^\/]+$/; copyFilesPath.forEach(copyFile => { fse.copy(copyFile.from, copyFile.to, err => { if (err) { console.log(chalk.red('Failed to copy files.\n')); } else { console.log('The ' + chalk.green(copyFile.from)); console.log('has copied to ' + chalk.green(copyFile.to) + '\n'); } }) }); }, 5000); // Failed to copy files without timeout } } // console.log("paths:",paths); module.exports = Object.assign({ scriptVersion: modulePath, configOverrides: config_overrides, customScriptsIndex: (custom_scripts ? cs_index : -1) }, paths);