Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions e2e/__tests__/__snapshots__/legacyInit.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Object {
"react-native": "0.59.3",
},
"devDependencies": Object {
"@babel/core": "^7.4.0",
"@babel/runtime": "^7.4.2",
"babel-jest": "^24.6.0",
"jest": "^24.6.0",
"@babel/core": "^7.4.3",
"@babel/runtime": "^7.4.3",
"babel-jest": "^24.7.0",
"jest": "^24.7.0",
"metro-react-native-babel-preset": "^0.53.1",
"react-test-renderer": "16.8.3",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from 'path';
import fs from 'fs-extra';
import snapshotDiff from 'snapshot-diff';
import walk from '../../../tools/walk';
import copyFiles from '../../../tools/copyFiles';
import {changePlaceholderInTemplate} from '../editTemplate';

const FIXTURE_DIR = path.resolve(
Expand All @@ -21,7 +22,7 @@ function createTestEnv() {
const testPath = path.resolve(tmpDir, TEST_DIR);

fs.mkdirSync(testPath);
fs.copySync(FIXTURE_DIR, testPath);
copyFiles(FIXTURE_DIR, testPath);

return testPath;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/commands/init/__tests__/template.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @flow
import fs from 'fs-extra';
import path from 'path';
import ChildProcess from 'child_process';
import * as PackageManger from '../../../tools/PackageManager';
Expand All @@ -9,6 +8,7 @@ import {
copyTemplate,
executePostInitScript,
} from '../template';
import * as copyFiles from '../../../tools/copyFiles';

const TEMPLATE_NAME = 'templateName';

Expand Down Expand Up @@ -55,7 +55,7 @@ test('copyTemplate', () => {
const CWD = '.';

jest.spyOn(path, 'resolve').mockImplementationOnce((...e) => e.join('/'));
jest.spyOn(fs, 'copySync').mockImplementationOnce(() => {});
jest.spyOn(copyFiles, 'default').mockImplementationOnce(() => {});
jest.spyOn(process, 'cwd').mockImplementationOnce(() => CWD);

copyTemplate(TEMPLATE_NAME, TEMPLATE_DIR);
Expand All @@ -65,7 +65,7 @@ test('copyTemplate', () => {
TEMPLATE_NAME,
TEMPLATE_DIR,
);
expect(fs.copySync).toHaveBeenCalledWith(expect.any(String), CWD);
expect(copyFiles.default).toHaveBeenCalledWith(expect.any(String), CWD);
});

test('executePostInitScript', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/init/template.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @flow
import {execFileSync} from 'child_process';
import fs from 'fs-extra';
import path from 'path';
import * as PackageManager from '../../tools/PackageManager';
import logger from '../../tools/logger';
import copyFiles from '../../tools/copyFiles';

export type TemplateConfig = {
placeholderName: string,
Expand Down Expand Up @@ -33,7 +33,7 @@ export function copyTemplate(templateName: string, templateDir: string) {

logger.debug(`Copying template from ${templatePath}`);

fs.copySync(templatePath, process.cwd());
copyFiles(templatePath, process.cwd());
}

export function executePostInitScript(
Expand Down
28 changes: 28 additions & 0 deletions packages/cli/src/tools/copyFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import path from 'path';
import copyAndReplace from './copyAndReplace';
import walk from './walk';

/**
* Copy files (binary included) recursively.
*/
function copyFiles(srcPath: string, destPath: string) {
Copy link
Member

Choose a reason for hiding this comment

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

Created a new utility to just copy files recursively, without replacing stuff around (which could theoretically break some 3rd templates in the future). It's based on copyAndReplace but with empty replacements, so binaries are still copied and I verified that it works with run-android (previously was breaking)

walk(srcPath).forEach(absoluteSrcFilePath => {
const relativeFilePath = path.relative(srcPath, absoluteSrcFilePath);
copyAndReplace(
absoluteSrcFilePath,
path.resolve(destPath, relativeFilePath),
{}, // no replacements
);
});
}

export default copyFiles;