Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const root = path.resolve(name);
const appName = path.basename(root);
const packageToInstall = getInstallPackage(version);
const packageName = getPackageName(packageToInstall);
if (packageToInstall === 'react-native-scripts') {
// The latest version of react-native-scripts is just a wrapper for expo-cli,
// so we can skip installing it and just run expo-cli directly.
runExpoCli('init', name);
return;
}
checkAppName(appName, packageName);
if (!await pathExists(name)) {
await fse.mkdir(root);
} else if (!await isSafeToCreateProjectIn(root)) {
console.log(`The directory \`${name}\` contains file(s) that could conflict. Aborting.`);
process.exit(1);
}
console.log(`Creating a new React Native app in ${root}.`);
console.log();
const packageJson = {
name: appName,
version: '0.1.0',
private: true,
};
await fse.writeFile(path.join(root, 'package.json'), JSON.stringify(packageJson, null, 2));
process.chdir(root);
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var historyApiFallback = require('connect-history-api-fallback');
var httpProxyMiddleware = require('http-proxy-middleware');
var detect = require('detect-port');
var clearConsole = require('react-dev-utils/clearConsole');
var checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
var formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
var getProcessForPort = require('react-dev-utils/getProcessForPort');
var openBrowser = require('react-dev-utils/openBrowser');
var prompt = require('react-dev-utils/prompt');
var pathExists = require('path-exists');
var config = require('../config/webpack.config.dev');
var paths = require('../config/paths');
var useYarn = pathExists.sync(paths.yarnLockFile);
var cli = useYarn ? 'yarn' : 'npm';
var isInteractive = process.stdout.isTTY;
// Warn and crash if required files are missing
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
process.exit(1);
}
// Tools like Cloud9 rely on this.
var DEFAULT_PORT = process.env.PORT || 3000;
var compiler;
var handleCompile;
// You can safely remove this after ejecting.
// We only use this block for testing of Create React App itself:
var isSmokeTest = process.argv.some(arg => arg.indexOf('--smoke-test') > -1);
require('dotenv').config({silent: true});
var chalk = require('chalk');
var fs = require('fs-extra');
var path = require('path');
var pathExists = require('path-exists');
var filesize = require('filesize');
var gzipSize = require('gzip-size').sync;
var webpack = require('webpack');
var config = require('../config/webpack.config.prod');
var paths = require('../config/paths');
var checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
var recursive = require('recursive-readdir');
var stripAnsi = require('strip-ansi');
var useYarn = pathExists.sync(paths.yarnLockFile);
// Warn and crash if required files are missing
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
process.exit(1);
}
// Input: /User/dan/app/build/static/js/main.82be8.js
// Output: /static/js/main.js
function removeFileNameHash(fileName) {
return fileName
.replace(paths.appBuild, '')
.replace(/\/?(.*)(\.\w+)(\.js|\.css|\.jsx|\.scss)/, (match, p1, p2, p3) => p1 + p3);
}
// Input: 1024, 2048
// Output: "(+1 KB)"
LAST_OPENED_LOG_FOLDER_KEY
);
if (lastOpenedLogFolder && pathExists.sync(lastOpenedLogFolder)) {
return vscode.Uri.file(lastOpenedLogFolder);
}
// If lastOpenedLogFolder isn't defined or doesn't exist then use the
// same directory that the SFDX download logs command would download to
// if it exists.
const sfdxCommandLogDir = path.join(
vscode.workspace.workspaceFolders![0].uri.fsPath,
'.sfdx',
'tools',
'debug',
'logs'
);
if (pathExists.sync(sfdxCommandLogDir)) {
return vscode.Uri.file(sfdxCommandLogDir);
}
// If all else fails, fallback to the .sfdx directory in the workspace
return vscode.Uri.file(
path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, '.sfdx')
);
}
}
id,
base,
config,
factory,
transforms,
filters,
log,
isEnvironment
} = settings;
const path = resolve(base, id);
const staticCacheRoot = resolve(process.cwd(), ".cache");
config.log = log;
// No patterns to find here
if (!await exists(path)) {
debug(`Expected path ${path} for pattern ${id} does not exist.`);
return [];
}
const search = (await exists(resolve(path, "pattern.json")))
? resolve(path, "pattern.json")
: path;
// Get all pattern ids
const paths = await readTree(search, options.cache);
const patternIDs = paths
.filter(item => basename(item) === "pattern.json")
.filter(item => (isEnvironment ? true : !item.includes("@environments")))
.map(item => dirname(item))
.map(item => relative(options.base, item));
filters,
log,
isEnvironment
} = settings;
const path = resolve(base, id);
const staticCacheRoot = resolve(process.cwd(), ".cache");
config.log = log;
// No patterns to find here
if (!await exists(path)) {
debug(`Expected path ${path} for pattern ${id} does not exist.`);
return [];
}
const search = (await exists(resolve(path, "pattern.json")))
? resolve(path, "pattern.json")
: path;
// Get all pattern ids
const paths = await readTree(search, options.cache);
const patternIDs = paths
.filter(item => basename(item) === "pattern.json")
.filter(item => (isEnvironment ? true : !item.includes("@environments")))
.map(item => dirname(item))
.map(item => relative(options.base, item));
// Read and transform patterns at a concurrency of 5
return await Promise.all(
patternIDs.map(
throat(5, async patternID => {
// Set application runtime cwds
application.runtime.cwds = [
...new Set([
application.runtime.cwd,
...existingModulePaths,
process.cwd()
])
];
// Check which user config paths exist
let existingConfigPaths = [];
for (const configPath of core.paths.configuration) {
for (const cwd of application.runtime.cwds) {
for (const suffix of ["", userPkg.name]) {
const userPath = resolve(cwd, configPath, suffix);
if (await exists(userPath)) {
// eslint-disable-line babel/no-await-in-loop
existingConfigPaths.push(userPath);
}
}
}
}
// Load most specific paths only
// Check if paths have siblings that contain them completely, thus are sub directories / more specific configuration folders
existingConfigPaths = existingConfigPaths.filter(configPath => {
const match = existingConfigPaths.filter(
subConfigPath =>
subConfigPath.includes(configPath) && subConfigPath !== configPath
);
return match.length === 0;
});
it('should create all bundles and chunks', () => {
expect(pathExists(mainBundlePathFR)).to.be.true
expect(pathExists(mainBundlePathEN)).to.be.true
expect(pathExists(secondBundlePathFR)).to.be.true
expect(pathExists(secondBundlePathEN)).to.be.true
})
test('WAIL created the managed directories', async t => {
let crawlPath = settings.get('heritrix.jobsDir')
t.true(await pathExists(crawlPath), 'the directory WAIL_Managed_Crawls must exist')
let warcsPath = settings.get('warcs')
t.true(await pathExists(warcsPath), 'the directory WAIL_ManagedCollections must exist')
let colPath = settings.get('collections.dir')
t.true(await pathExists(colPath), 'the directory WAIL_ManagedCollections/collections must exist')
let templateDir = settings.get('collections.templateDir')
t.true(await pathExists(templateDir), 'the template directory required by pywb must exist')
let staticDir = settings.get('collections.staticsDir')
t.true(await pathExists(staticDir), 'the static directory required by pywb must exist')
})
test('WAIL created the managed directories', async t => {
let crawlPath = settings.get('heritrix.jobsDir')
t.true(await pathExists(crawlPath), 'the directory WAIL_Managed_Crawls must exist')
let warcsPath = settings.get('warcs')
t.true(await pathExists(warcsPath), 'the directory WAIL_ManagedCollections must exist')
let colPath = settings.get('collections.dir')
t.true(await pathExists(colPath), 'the directory WAIL_ManagedCollections/collections must exist')
let templateDir = settings.get('collections.templateDir')
t.true(await pathExists(templateDir), 'the template directory required by pywb must exist')
let staticDir = settings.get('collections.staticsDir')
t.true(await pathExists(staticDir), 'the static directory required by pywb must exist')
})