Skip to content

Commit

Permalink
address feedback; remove version handling from createFromTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
thymikee committed May 17, 2019
1 parent dc3aefb commit 3e17adc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
31 changes: 14 additions & 17 deletions packages/cli/src/commands/init/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,11 @@ function adjustNameIfUrl(name, cwd) {
async function createFromTemplate({
projectName,
templateName,
version,
npm,
directory,
}: {
projectName: string,
templateName: string,
version?: string,
npm?: boolean,
directory: string,
}) {
Expand All @@ -108,17 +106,9 @@ async function createFromTemplate({
path.join(os.tmpdir(), 'rncli-init-template-'),
);

if (version && semver.valid(version) && !semver.gte(version, '0.60.0-rc.0')) {
throw new Error(
'Cannot use React Native CLI to initialize project with version lower than 0.60.0.',
);
}

try {
loader.start();
let {uri, name} = await processTemplateName(
version ? `${templateName}@${version}` : templateName,
);
let {uri, name} = await processTemplateName(templateName);

await installTemplatePackage(uri, templateSourceDir, npm);

Expand Down Expand Up @@ -181,25 +171,32 @@ async function createProject(
version: string,
options: Options,
) {
const templateName = options.template || 'react-native';
const templateName = options.template || `react-native@${version}`;

if (
version !== 'latest' &&
semver.valid(version) &&
!semver.gte(version, '0.60.0-rc.0')
) {
throw new Error(
'Cannot use React Native CLI to initialize project with version lower than 0.60.0.',
);
}

return createFromTemplate({
projectName,
templateName,
// version is "latest" by default, but it's easier for us to treat it as
// undefined when the "template" param is passed. Might refactor later
version: options.template ? undefined : version,
npm: options.npm,
directory,
});
}

export default (async function initialize(
[projectName]: Array<string>,
_context: ConfigT,
context: ConfigT,
options: Options,
) {
const rootFolder = process.cwd();
const rootFolder = context.root;

validateProjectName(projectName);

Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/tools/installPods.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import fs from 'fs-extra';
import fs from 'fs';
import execa from 'execa';
import chalk from 'chalk';
import Ora from 'ora';
Expand All @@ -17,13 +17,13 @@ async function installPods({
loader?: typeof Ora,
}) {
try {
if (!(await fs.pathExists('ios'))) {
if (!fs.existsSync('ios')) {
return;
}

process.chdir('ios');

const hasPods = await fs.pathExists('Podfile');
const hasPods = fs.existsSync('Podfile');

if (!hasPods) {
return;
Expand Down

0 comments on commit 3e17adc

Please sign in to comment.