Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const path = require('path')
const webpack = require('webpack')
const AssetsPlugin = require('assets-webpack-plugin')
const nodeExternals = require('webpack-node-externals')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const dotenv = require('dotenv')
const appRoot = require('app-root-path')
const WebpackMd5Hash = require('webpack-md5-hash')
const { removeEmpty, ifElse, merge } = require('../utils')
const appRootPath = appRoot.toString()
// @see https://github.com/motdotla/dotenv
dotenv.config(process.env.NOW
// This is to support deployment to the "now" host. See the README for more info.
? { path: '../../.envnow', silent: true }
// Standard .env loading.
: { silent: true }
)
function webpackConfigFactory ({ target, mode }, { json }) {
if (!target || !~['client', 'server'].findIndex(valid => target === valid)) {
throw new Error(
'You must provide a "target" (client|server) to the webpackConfigFactory.'
)
}
var commandLineArgs = require('command-line-args');
var camelize = require('camelize');
var fs = require('fs');
var path = require('path');
var appRoot = require('app-root-path');
var currentValue, environmentProperty, environmentBase, tsString, booleanValue;
var optionDefinitions = [
{ name: 'out', alias: 'o', type: String },
{ name: 'in', alias: 'i', type: String },
];
var options = commandLineArgs(optionDefinitions);
var environmentPath = options['in'] || path.join(appRoot.toString(), 'environment.json');;
var tsEnvironmentPath = options['out'] || path.join(appRoot.toString(), 'src', 'environments', 'base.ts')
if (fs.existsSync(environmentPath)) {
console.log('Reading base environment: ' + environmentPath);
environmentBase = JSON.parse(fs.readFileSync(environmentPath, 'utf-8').toString());
} else {
environmentBase = {};
}
require('dotenv').config();
Object.keys(process.env).forEach(function (key) {
if (key.startsWith('NG_')) {
currentValue = process.env[key];
booleanValue = currentValue.toLowerCase();
environmentProperty = camelize(key.substr(3).toLowerCase());
if (booleanValue === 'true' || booleanValue === 'false') {
export default (configPath?: string): ConfigFile => {
if (configPath) {
return {
filePath: configPath,
config: require(configPath),
};
}
const rootDir = appRoot.toString();
const defaultConfigPath = path.join(rootDir, 'stricter.config.js');
return {
filePath: defaultConfigPath,
config: require(defaultConfigPath),
};
};
function createFolderForNode(dirPath: string): void {
createFolder(dirPath);
let indexPath: string = path.join(
appRoot.toString(),
FUNCTION_TEMPLATES_RELATIVE_PATH,
BASE_NODE_FUNCTION_PATH
);
let funcJsonPath: string = path.join(
appRoot.toString(),
FUNCTION_TEMPLATES_RELATIVE_PATH,
BASE_NODE_FUNCTION_CONFIG_PATH
);
fs.copyFileSync(indexPath, path.join(dirPath, "index.js"));
fs.copyFileSync(funcJsonPath, path.join(dirPath, "function.json"));
}
private getFunctionsARMParameters(selections: FunctionSelections): any {
let parametersPath = path.join(
appRoot.toString(),
"src",
"azure",
"azure-functions",
"arm-templates",
"parameters.json"
);
let parameters = JSON.parse(fs.readFileSync(parametersPath, "utf8"));
parameters.parameters = {
name: {
value: selections.functionAppName
},
location: {
value: selections.location
},
function projectDir() {
return require('app-root-path').toString();
}
exports.projectDir = projectDir;
return fallback ? path.resolve(__dirname, fallback) : null;
}
}
function getSourceDir() {
try { return path.dirname(require.resolve(appRoot)); }
catch (e) { return appRoot.resolve('src'); }
}
function overrideConfig(config) {
try { return Object.assign(config, appRoot.require('.hopsrc')); }
catch (e) { return config; }
}
module.exports = overrideConfig({
appRoot: appRoot.toString(),
distDir: appRoot.resolve('dist'),
eslint: getFilePath('.eslintrc.js', '../etc/eslint.js'),
srcDir: getSourceDir(),
stylelint: getFilePath('.stylelintrc.js', '../etc/stylelint.js'),
testGlob: appRoot.resolve('!(node_modules)/**/*.test.js'),
webpack: getFilePath('webpack.js', '../etc/webpack.js'),
webpackBase: getFilePath('webpack.base.js', '../etc/webpack.base.js'),
webpackDev: getFilePath('webpack.dev.js', '../etc/webpack.dev.js'),
webpackBuild: getFilePath('webpack.build.js', '../etc/webpack.build.js')
});
constructor(userPath?: string) {
if (!!userPath) {
this.path = userPath;
} else {
const defaultPath = path.join(appRoot.toString(), "spidered");
this.path = defaultPath;
}
if (!fs.existsSync(this.path)) {
logger.info("Creating directory '%s' to store analyses...", path);
fs.mkdirSync(this.path);
}
}
private getFunctionsARMTemplate(): any {
let templatePath = path.join(
appRoot.toString(),
"src",
"azure",
"azure-functions",
"arm-templates",
"template.json"
);
return JSON.parse(fs.readFileSync(templatePath, "utf8"));
}