Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: use template from react-native #84

Merged
merged 5 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/local-cli/generator/copyProjectTemplateAndReplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ function copyProjectTemplateAndReplace(
}
}

const relativeFilePath = path.relative(srcPath, absoluteSrcFilePath);
const relativeRenamedPath = translateFilePath(relativeFilePath)
.replace(/HelloWorld/g, newProjectName)
.replace(/helloworld/g, newProjectName.toLowerCase());
const relativeFilePath = translateFilePath(
path.relative(srcPath, absoluteSrcFilePath)
);

// Templates may contain files that we don't want to copy.
// Examples:
Expand All @@ -89,13 +88,13 @@ function copyProjectTemplateAndReplace(
contentChangedCallback = (_, contentChanged) =>
upgradeFileContentChangedCallback(
absoluteSrcFilePath,
relativeRenamedPath,
relativeFilePath,
contentChanged
);
}
copyAndReplace(
absoluteSrcFilePath,
path.resolve(destPath, relativeRenamedPath),
path.resolve(destPath, relativeFilePath),
{
'Hello App Display Name': options.displayName || newProjectName,
HelloWorld: newProjectName,
Expand Down
15 changes: 7 additions & 8 deletions packages/local-cli/generator/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,20 @@ function createProjectFromTemplate(
template,
yarnVersion
) {
// Expand the basic 'HelloWorld' template
copyProjectTemplateAndReplace(
path.resolve(__dirname, '../templates/HelloWorld'),
destPath,
newProjectName
const templatePath = path.resolve(
process.cwd(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be destPath (the project directory, passed from init()) instead of the current working directory (which could be any dir where the command to create a project was run).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually we could just use require.resolve('react-native/template') instead, since we are in context of node_modules, right?

Note that destPath is still passed on line 32. The diff might be confusing, but we are only changing the "path.resolve(__dirname, '../templates/HelloWorld')," part.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, require.resolve should work I think.

'./node_modules/react-native/template'
);
copyProjectTemplateAndReplace(templatePath, destPath, newProjectName);

if (template === undefined) {
// No specific template, use just the HelloWorld template above
// No specific template, use just the react-native template above
return;
}

// Keep the files from the 'HelloWorld' template, and overwrite some of them
// Keep the files from the react-native template, and overwrite some of them
// with the specified project template.
// The 'HelloWorld' template contains the native files (these are used by
// The react-native template contains the native files (these are used by
// all templates) and every other template only contains additional JS code.
// Reason:
// This way we don't have to duplicate the native files in every template.
Expand Down
2 changes: 1 addition & 1 deletion packages/local-cli/init/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function init(projectDir, argsOrName) {
* @param options Command line arguments parsed by minimist.
*/
function generateProject(destinationRoot, newProjectName, options) {
const reactNativePackageJson = require.resolve('react-native/package.json');
const reactNativePackageJson = require('react-native/package.json');
const { peerDependencies } = reactNativePackageJson;
if (!peerDependencies) {
console.error(
Expand Down
50 changes: 0 additions & 50 deletions packages/local-cli/templates/HelloWorld/App.js

This file was deleted.

15 changes: 0 additions & 15 deletions packages/local-cli/templates/HelloWorld/__tests__/App-test.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/local-cli/templates/HelloWorld/_babelrc

This file was deleted.

6 changes: 0 additions & 6 deletions packages/local-cli/templates/HelloWorld/_buckconfig

This file was deleted.

70 changes: 0 additions & 70 deletions packages/local-cli/templates/HelloWorld/_flowconfig

This file was deleted.

1 change: 0 additions & 1 deletion packages/local-cli/templates/HelloWorld/_gitattributes

This file was deleted.

56 changes: 0 additions & 56 deletions packages/local-cli/templates/HelloWorld/_gitignore

This file was deleted.

1 change: 0 additions & 1 deletion packages/local-cli/templates/HelloWorld/_watchmanconfig

This file was deleted.

55 changes: 0 additions & 55 deletions packages/local-cli/templates/HelloWorld/android/app/_BUCK

This file was deleted.

Loading