diff --git a/e2e/__tests__/__snapshots__/legacyInit.test.js.snap b/e2e/__tests__/__snapshots__/legacyInit.test.js.snap index f78d5e2b4..2f5b89897 100644 --- a/e2e/__tests__/__snapshots__/legacyInit.test.js.snap +++ b/e2e/__tests__/__snapshots__/legacyInit.test.js.snap @@ -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", }, diff --git a/packages/cli/src/commands/init/__tests__/editTemplate.test.js b/packages/cli/src/commands/init/__tests__/editTemplate.test.js index 8917c54d4..f664d2557 100644 --- a/packages/cli/src/commands/init/__tests__/editTemplate.test.js +++ b/packages/cli/src/commands/init/__tests__/editTemplate.test.js @@ -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( @@ -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; } diff --git a/packages/cli/src/commands/init/__tests__/template.test.js b/packages/cli/src/commands/init/__tests__/template.test.js index 73590ce17..657a2ca1f 100644 --- a/packages/cli/src/commands/init/__tests__/template.test.js +++ b/packages/cli/src/commands/init/__tests__/template.test.js @@ -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'; @@ -9,6 +8,7 @@ import { copyTemplate, executePostInitScript, } from '../template'; +import * as copyFiles from '../../../tools/copyFiles'; const TEMPLATE_NAME = 'templateName'; @@ -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); @@ -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', () => { diff --git a/packages/cli/src/commands/init/template.js b/packages/cli/src/commands/init/template.js index 40c670487..dd7180ece 100644 --- a/packages/cli/src/commands/init/template.js +++ b/packages/cli/src/commands/init/template.js @@ -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, @@ -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( diff --git a/packages/cli/src/tools/copyFiles.js b/packages/cli/src/tools/copyFiles.js new file mode 100644 index 000000000..c94581f78 --- /dev/null +++ b/packages/cli/src/tools/copyFiles.js @@ -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) { + walk(srcPath).forEach(absoluteSrcFilePath => { + const relativeFilePath = path.relative(srcPath, absoluteSrcFilePath); + copyAndReplace( + absoluteSrcFilePath, + path.resolve(destPath, relativeFilePath), + {}, // no replacements + ); + }); +} + +export default copyFiles;