Skip to content

Commit

Permalink
paths refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pavjacko committed Aug 18, 2019
1 parent aeeda44 commit 9c65e7f
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 64 deletions.
4 changes: 2 additions & 2 deletions buildHooks/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const hooks = {
}),
convertPlugins: c => new Promise((resolve, reject) => {
for (const k in c.files.pluginTemplatesConfig.plugins) {
const pf = path.join(c.paths.rnvPluginTemplatesFolder, k);
const pf = path.join(c.paths.rnv.pluginTemplates.dir, k);
const fp = path.join(pf, 'renative-plugin.json');

if (fs.existsSync(pf)) {
Expand All @@ -36,7 +36,7 @@ const hooks = {
_updatePackageJson(c, path.join(pkgFolder, 'renative-template-blank/package.json'), v);
_updatePackageJson(c, path.join(pkgFolder, 'renative/package.json'), v);
FileUtils.copyFileSync(path.join(c.paths.project.dir, 'README.md'), path.join(pkgFolder, 'renative/README.md'));
FileUtils.updateObjectSync(c.paths.rnvPluginTemplatesConfigPath, {
FileUtils.updateObjectSync(c.paths.rnv.pluginTemplates.config, {
plugins: {
renative: {
version: c.files.project.package.version
Expand Down
14 changes: 7 additions & 7 deletions packages/renative/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -916,19 +916,19 @@ c.program;
c.process;
c.command;
c.subCommand;
c.appId;
c.runtime.appId;
c.platform;
//FILES
c.files.projectConfig;
c.files.rnvPackage;
c.files.rnv.package;
//PATHS
c.paths.rnv.dir;
c.paths.rnv.dir;
c.paths.rnvPlatformTemplatesFolder;
c.paths.rnvPluginTemplatesFolder;
c.paths.rnvPluginTemplatesConfigPath;
c.paths.rnvPackagePath;
c.paths.rnvPluginsFolder;
c.paths.rnv.platformTemplates.dir;
c.paths.rnv.pluginTemplates.dir;
c.paths.rnv.pluginTemplates.config;
c.paths.rnv.package;
c.paths.rnv.plugins.dir;
c.paths.project.dir;
c.paths.buildHooks.dir;
c.paths.buildHooks.dist.dir;
Expand Down
6 changes: 3 additions & 3 deletions packages/rnv/src/cli/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const _runConfigure = c => new Promise((resolve, reject) => {
.then(() => _checkAndCreatePlatforms(c, c.program.platform))
.then(() => copyRuntimeAssets(c))
.then(() => _copySharedPlatforms(c))
.then(() => _runPlugins(c, c.paths.rnvPluginsFolder))
.then(() => _runPlugins(c, c.paths.rnv.plugins.dir))
.then(() => _runPlugins(c, c.paths.project.projectConfig.pluginsDir))
.then(() => (_isOK(c, p, [ANDROID]) ? configureGradleProject(c, ANDROID) : Promise.resolve()))
.then(() => (_isOK(c, p, [ANDROID_TV]) ? configureGradleProject(c, ANDROID_TV) : Promise.resolve()))
Expand Down Expand Up @@ -279,7 +279,7 @@ const checkAndCreateProjectPackage = (c, data) => {
renative: 'latest',
};
pkgJson.devDependencies = {
rnv: c.files.rnvPackage.version,
rnv: c.files.rnv.package.version,
};
pkgJson.devDependencies[data.optionTemplates.selectedOption] = 'latest';

Expand Down Expand Up @@ -314,7 +314,7 @@ const checkAndCreateProjectConfig = (c, data) => {
defaultAppId: appID.toLowerCase()
};

const obj = JSON.parse(fs.readFileSync(path.join(c.paths.rnvProjectTemplateFolder, 'rnv-config.json')));
const obj = JSON.parse(fs.readFileSync(path.join(c.paths.rnv.projectTemplate.dir, 'rnv-config.json')));

obj.defaultProjectConfigs = defaultProjectConfigs;

Expand Down
16 changes: 8 additions & 8 deletions packages/rnv/src/cli/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const _runEjectPlatforms = c => new Promise((resolve) => {


const ptfn = 'platformTemplates';
const rptf = c.paths.rnvPlatformTemplatesFolder;
const rptf = c.paths.rnv.platformTemplates.dir;
const prf = c.paths.project.dir;

const WEB_BASED_PLATFORMS = [];
Expand Down Expand Up @@ -143,7 +143,7 @@ const _runEjectPlatforms = c => new Promise((resolve) => {

const _genPlatOptions = (c) => {
const opts = generateOptions(c.files.projectConfig.defaultProjectConfigs.supportedPlatforms, true, null, (i, obj, mapping, defaultVal) => {
const isEjected = c.paths.platformTemplatesFolders[obj].includes(c.paths.rnvPlatformTemplatesFolder) ? chalk.green('(connected)') : chalk.yellow('(ejected)');
const isEjected = c.paths.platformTemplatesFolders[obj].includes(c.paths.rnv.platformTemplates.dir) ? chalk.green('(connected)') : chalk.yellow('(ejected)');
return `-[${chalk.white(i + 1)}] ${chalk.white(defaultVal)} - ${isEjected} \n`;
});
return opts;
Expand All @@ -168,7 +168,7 @@ const _runConnectPlatforms = c => new Promise((resolve) => {
writeObjectSync(c.paths.project.config, c.files.projectConfig);
});
logSuccess(
`${chalk.white(opts.selectedOptions.join(','))} now using ReNative platformTemplates located in ${chalk.white(c.paths.rnvPlatformTemplatesFolder)} now!`
`${chalk.white(opts.selectedOptions.join(','))} now using ReNative platformTemplates located in ${chalk.white(c.paths.rnv.platformTemplates.dir)} now!`
);
resolve();
});
Expand Down Expand Up @@ -205,13 +205,13 @@ const _runCopyPlatforms = (c, platform) => new Promise((resolve, reject) => {
for (const k in c.files.appConfigFile.platforms) {
if (isPlatformSupportedSync(k)) {
const ptPath = path.join(c.paths.platformTemplatesFolders[k], `${k}`);
const pPath = path.join(c.paths.platformBuildsFolder, `${c.appId}_${k}`);
const pPath = path.join(c.paths.platformBuildsFolder, `${c.runtime.appId}_${k}`);
copyPlatformTasks.push(copyFolderContentsRecursiveSync(ptPath, pPath));
}
}
} else if (isPlatformSupportedSync(platform)) {
const ptPath = path.join(c.paths.platformTemplatesFolders[platform], `${platform}`);
const pPath = path.join(c.paths.platformBuildsFolder, `${c.appId}_${platform}`);
const pPath = path.join(c.paths.platformBuildsFolder, `${c.runtime.appId}_${platform}`);
copyPlatformTasks.push(copyFolderContentsRecursiveSync(ptPath, pPath));
} else {
logWarning(`Your platform ${chalk.white(platform)} config is not present. Check ${chalk.white(c.paths.appConfigPath)}`);
Expand All @@ -230,12 +230,12 @@ const cleanPlatformBuild = (c, platform) => new Promise((resolve, reject) => {
if (platform === 'all') {
for (const k in c.files.appConfigFile.platforms) {
if (isPlatformSupportedSync(k)) {
const pPath = path.join(c.paths.platformBuildsFolder, `${c.appId}_${k}`);
const pPath = path.join(c.paths.platformBuildsFolder, `${c.runtime.appId}_${k}`);
cleanTasks.push(cleanFolder(pPath));
}
}
} else if (isPlatformSupportedSync(platform)) {
const pPath = path.join(c.paths.platformBuildsFolder, `${c.appId}_${platform}`);
const pPath = path.join(c.paths.platformBuildsFolder, `${c.runtime.appId}_${platform}`);
cleanTasks.push(cleanFolder(pPath));
}

Expand All @@ -254,7 +254,7 @@ const createPlatformBuild = (c, platform) => new Promise((resolve, reject) => {

if (!isPlatformSupportedSync(platform, null, reject)) return;

const pPath = path.join(c.paths.platformBuildsFolder, `${c.appId}_${platform}`);
const pPath = path.join(c.paths.platformBuildsFolder, `${c.runtime.appId}_${platform}`);
const ptPath = path.join(c.paths.platformTemplatesFolders[platform], `${platform}`);
copyFolderContentsRecursiveSync(ptPath, pPath, false, [path.join(ptPath, '_privateConfig')]);

Expand Down
4 changes: 2 additions & 2 deletions packages/rnv/src/cli/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ const configureHostedIfRequired = async (c, platform) => {
if (_isWebHostEnabled(c, platform)) {
logDebug('Running hosted build');
const { platformBuildsFolder, rnvRootFolder } = c.paths;
copyFolderContentsRecursiveSync(path.join(rnvRootFolder, 'supportFiles', 'appShell'), path.join(platformBuildsFolder, `${c.appId}_${platform}`, 'public'));
writeCleanFile(path.join(rnvRootFolder, 'supportFiles', 'appShell', 'index.html'), path.join(platformBuildsFolder, `${c.appId}_${platform}`, 'public', 'index.html'), [
copyFolderContentsRecursiveSync(path.join(rnvRootFolder, 'supportFiles', 'appShell'), path.join(platformBuildsFolder, `${c.runtime.appId}_${platform}`, 'public'));
writeCleanFile(path.join(rnvRootFolder, 'supportFiles', 'appShell', 'index.html'), path.join(platformBuildsFolder, `${c.runtime.appId}_${platform}`, 'public', 'index.html'), [
{ pattern: '{{DEV_SERVER}}', override: `http://${ip.address()}:${c.platformDefaults[platform].defaultPort}` },
]);
}
Expand Down
31 changes: 12 additions & 19 deletions packages/rnv/src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import {
PLATFORMS
} from './constants';
import { executeAsync } from './systemTools/exec';
import { parseRenativeConfigsSync, createRnvConfig } from './configTools/configParser';
import { parseRenativeConfigsSync, createRnvConfig, setAppConfig } from './configTools/configParser';

const SUPPORTED_PLATFORMS = [
IOS,
Expand Down Expand Up @@ -234,7 +234,7 @@ const initializeBuilder = (cmd, subCmd, process, program) => new Promise((resolv
const startBuilder = c => new Promise((resolve, reject) => {
logTask('initializeBuilder');

c.files.pluginTemplatesConfig = JSON.parse(fs.readFileSync(path.join(c.paths.rnvPluginTemplatesConfigPath)).toString());
c.files.pluginTemplatesConfig = JSON.parse(fs.readFileSync(path.join(c.paths.rnv.pluginTemplates.config)).toString());

if ((c.command === 'app' && c.subCommand === 'create') || c.command === 'new') {
resolve(c);
Expand Down Expand Up @@ -297,7 +297,7 @@ const gatherInfo = c => new Promise((resolve, reject) => {
}
if (fs.existsSync(c.paths.runtimeConfigPath)) {
c.files.appConfigFile = JSON.parse(fs.readFileSync(c.paths.runtimeConfigPath).toString());
c.appId = c.files.appConfigFile.id;
c.runtime.appId = c.files.appConfigFile.id;
} else {
console.log('Missing runtimeConfigPath', c.paths.runtimeConfigPath);
}
Expand Down Expand Up @@ -330,7 +330,7 @@ const configureProject = c => new Promise((resolve, reject) => {
logWarning(
`Looks like your rn-cli config file ${chalk.white(c.paths.project.rnCliConfig)} is missing! Let's create one for you.`,
);
copyFileSync(path.join(c.paths.rnvProjectTemplateFolder, RN_CLI_CONFIG_NAME), c.paths.project.rnCliConfig);
copyFileSync(path.join(c.paths.rnv.projectTemplate.dir, RN_CLI_CONFIG_NAME), c.paths.project.rnCliConfig);
}

// Check babel-config
Expand Down Expand Up @@ -540,7 +540,7 @@ const configureEntryPoints = (c) => {
for (const k in p) {
plat = p[k];
const source = path.join(c.paths.projectTemplateFolder, `${plat.entryFile}.js`);
const backupSource = path.join(c.paths.rnvProjectTemplateFolder, 'entry', `${plat.entryFile}.js`);
const backupSource = path.join(c.paths.rnv.projectTemplate.dir, 'entry', `${plat.entryFile}.js`);
const dest = path.join(c.paths.project.dir, `${plat.entryFile}.js`);
if (!fs.existsSync(dest)) {
if (!plat.entryFile) {
Expand Down Expand Up @@ -657,9 +657,9 @@ const configurePlugins = c => new Promise((resolve, reject) => {
const configureApp = c => new Promise((resolve, reject) => {
logTask('configureApp');

if (c.appId) {
if (c.runtime.appId) {
// App ID specified
_getConfig(c, c.appId)
_getConfig(c, c.runtime.appId)
.then(() => {
configureEntryPoints(c);
resolve(c);
Expand Down Expand Up @@ -768,7 +768,7 @@ const _getConfig = (c, appConfigId) => new Promise((resolve, reject) => {
logTask(`_getConfig:${appConfigId}`);

setAppConfig(c, appConfigId);
c.appId = appConfigId;
c.runtime.appId = appConfigId;

if (!fs.existsSync(c.paths.appConfigFolder)) {
const readline = require('readline').createInterface({
Expand Down Expand Up @@ -798,7 +798,7 @@ const _getConfig = (c, appConfigId) => new Promise((resolve, reject) => {
(v) => {
if (configDirs[v]) {
c.defaultAppConfigId = configDirs[v];
c.appId = c.defaultAppConfigId;
c.runtime.appId = c.defaultAppConfigId;
setAppConfig(c, c.defaultAppConfigId);
_configureConfig(c)
.then(() => resolve())
Expand Down Expand Up @@ -838,7 +838,7 @@ const _getConfig = (c, appConfigId) => new Promise((resolve, reject) => {
const _arrayMergeOverride = (destinationArray, sourceArray, mergeOptions) => sourceArray;

const _configureConfig = c => new Promise((resolve, reject) => {
logTask(`_configureConfig:${c.appId}`);
logTask(`_configureConfig:${c.runtime.appId}`);
c.files.appConfigFile = JSON.parse(fs.readFileSync(c.paths.appConfigPath).toString());

// EXTEND CONFIG
Expand All @@ -860,7 +860,7 @@ const _configureConfig = c => new Promise((resolve, reject) => {
}
});

const getAppFolder = (c, platform) => path.join(c.paths.platformBuildsFolder, `${c.appId}_${platform}`);
const getAppFolder = (c, platform) => path.join(c.paths.platformBuildsFolder, `${c.runtime.appId}_${platform}`);

const getAppTemplateFolder = (c, platform) => path.join(c.paths.platformTemplatesFolders[platform], `${platform}`);

Expand Down Expand Up @@ -969,7 +969,7 @@ const isPlatformActive = (c, platform, resolve) => {
return false;
}
if (!c.files.appConfigFile.platforms[platform]) {
console.log(`Platform ${platform} not configured for ${c.appId}. skipping.`);
console.log(`Platform ${platform} not configured for ${c.runtime.appId}. skipping.`);
if (resolve) resolve();
return false;
}
Expand Down Expand Up @@ -1093,13 +1093,6 @@ const getIP = () => {
return ip.address();
};

const setAppConfig = (c, p) => {
c.paths.appConfigFolder = path.join(c.paths.project.appConfigsDir, p);
c.paths.appConfigPath = path.join(c.paths.appConfigFolder, RNV_APP_CONFIG_NAME);
c.paths.privateAppConfigFolder = path.join(c.paths.privateAppConfigsFolder, p);
c.paths.privateAppConfigPath = path.join(c.paths.privateAppConfigFolder, RNV_PRIVATE_APP_CONFIG_NAME);
};

const cleanPlatformIfRequired = (c, platform) => new Promise((resolve, reject) => {
if (c.program.reset) {
logInfo(`You passed ${chalk.white('-r')} argument. paltform ${chalk.white(platform)} will be cleaned up first!`);
Expand Down
39 changes: 25 additions & 14 deletions packages/rnv/src/configTools/configParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ export const createRnvConfig = (program, process, cmd, subCmd) => {

},
paths: {
rnv: {},
rnv: {
pluginTemplates: {},
platformTemplates: {}
},
project: {},
app: {},
private: {}
Expand All @@ -84,15 +87,16 @@ export const createRnvConfig = (program, process, cmd, subCmd) => {
c.command = cmd;
c.subCommand = subCmd;
c.platformDefaults = PLATFORMS;
c.appId = program.appConfigID;
c.runtime.appId = program.appConfigID;

c.paths.rnv.dir = path.join(__dirname, '../..');
c.paths.rnvPlatformTemplatesFolder = path.join(c.paths.rnv.dir, 'platformTemplates');
c.paths.rnvPluginTemplatesFolder = path.join(c.paths.rnv.dir, 'pluginTemplates');
c.paths.rnvPluginTemplatesConfigPath = path.join(c.paths.rnvPluginTemplatesFolder, 'plugins.json');
c.paths.rnvPackagePath = path.join(c.paths.rnv.dir, 'package.json');
c.paths.rnvPluginsFolder = path.join(c.paths.rnv.dir, 'plugins');
c.paths.rnvProjectTemplateFolder = path.join(c.paths.rnv.dir, 'projectTemplate');
c.files.rnvPackage = JSON.parse(fs.readFileSync(c.paths.rnvPackagePath).toString());
c.paths.rnv.platformTemplates.dir = path.join(c.paths.rnv.dir, 'platformTemplates');
c.paths.rnv.pluginTemplates.dir = path.join(c.paths.rnv.dir, 'pluginTemplates');
c.paths.rnv.pluginTemplates.config = path.join(c.paths.rnv.pluginTemplates.dir, 'plugins.json');
c.paths.rnv.package = path.join(c.paths.rnv.dir, 'package.json');
c.paths.rnv.plugins.dir = path.join(c.paths.rnv.dir, 'plugins');
c.paths.rnv.projectTemplate.dir = path.join(c.paths.rnv.dir, 'projectTemplate');
c.files.rnv.package = JSON.parse(fs.readFileSync(c.paths.rnv.package).toString());

return c;
};
Expand Down Expand Up @@ -127,13 +131,13 @@ export const parseRenativeConfigsSync = (c) => {
try {
c.files.project.package = JSON.parse(fs.readFileSync(c.paths.project.package).toString());

const rnvVersionRunner = c.files.rnvPackage.version;
const rnvVersionProject = c.files.project.package.devDependencies?.rnv;
c.runtime.rnvVersionRunner = c.files.rnv.package.version;
c.runtime.rnvVersionProject = c.files.project.package.devDependencies?.rnv;

if (rnvVersionRunner && rnvVersionProject) {
if (rnvVersionRunner !== rnvVersionProject) {
if (c.runtime.rnvVersionRunner && c.runtime.rnvVersionProject) {
if (c.runtime.rnvVersionRunner !== c.runtime.rnvVersionProject) {
const recCmd = chalk.white(`$ npx ${getCurrentCommand(true)}`);
logWarning(`You are running $rnv v${chalk.red(rnvVersionRunner)} against project built with $rnv v${chalk.red(rnvVersionProject)}.
logWarning(`You are running $rnv v${chalk.red(c.runtime.rnvVersionRunner)} against project built with $rnv v${chalk.red(c.runtime.rnvVersionProject)}.
This might result in unexpected behaviour! It is recommended that you run your rnv command with npx prefix: ${recCmd} .`);
}
}
Expand Down Expand Up @@ -202,6 +206,13 @@ This might result in unexpected behaviour! It is recommended that you run your r
}
};

export const setAppConfig = (c, p) => {
c.paths.appConfigFolder = path.join(c.paths.project.appConfigsDir, p);
c.paths.appConfigPath = path.join(c.paths.appConfigFolder, RNV_APP_CONFIG_NAME);
c.paths.privateAppConfigFolder = path.join(c.paths.privateAppConfigsFolder, p);
c.paths.privateAppConfigPath = path.join(c.paths.privateAppConfigFolder, RNV_PRIVATE_APP_CONFIG_NAME);
};

const _generatePlatformTemplatePaths = (c) => {
const pt = c.files.projectConfig.platformTemplatesFolders || {};
const originalPath = c.files.projectConfig.platformTemplatesFolder || 'RNV_HOME/platformTemplates';
Expand Down
2 changes: 1 addition & 1 deletion packages/rnv/src/deployTools/ftp.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const _createDeployConfig = (c, platform) => new Promise((resolve, reject) => {
c.files.appConfigFile.platforms[platform].deploy[DEPLOY_TARGET_FTP].type = DEPLOY_TARGET_FTP;

const targetConfigPromise = new Promise((resolve, reject) => {
c.files.appConfigFile.platforms[platform].deploy[DEPLOY_TARGET_FTP].localRoot = path.resolve(c.paths.platformBuildsFolder, `${c.appId}_${platform}`);
c.files.appConfigFile.platforms[platform].deploy[DEPLOY_TARGET_FTP].localRoot = path.resolve(c.paths.platformBuildsFolder, `${c.runtime.appId}_${platform}`);
askQuestion('Folder on the ftp to upload the project (default is \'/\')')
.then((v) => {
finishQuestion();
Expand Down
2 changes: 1 addition & 1 deletion packages/rnv/src/platformTools/apple.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ const packageBundleForXcode = (c, platform, isDev = false) => {
'--dev',
isDev,
'--assets-dest',
`platformBuilds/${c.appId}_${platform}`,
`platformBuilds/${c.runtime.appId}_${platform}`,
'--entry-file',
`${c.files.appConfigFile.platforms[platform].entryFile}.js`,
'--bundle-output',
Expand Down
2 changes: 1 addition & 1 deletion packages/rnv/src/platformTools/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const buildWeb = (c, platform) => new Promise((resolve, reject) => {

const wbp = resolveNodeModulePath(c, 'webpack/bin/webpack.js');

execShellAsync(`npx cross-env NODE_ENV=production ${debugVariables} node ${wbp} -p --config ./platformBuilds/${c.appId}_${platform}/webpack.config.js`)
execShellAsync(`npx cross-env NODE_ENV=production ${debugVariables} node ${wbp} -p --config ./platformBuilds/${c.runtime.appId}_${platform}/webpack.config.js`)
.then(() => {
logSuccess(`Your Build is located in ${chalk.white(path.join(appFolder, 'public'))} .`);
resolve();
Expand Down
Loading

0 comments on commit 9c65e7f

Please sign in to comment.