From c92239f6076d8e0dbd23d0c66be781614f992d00 Mon Sep 17 00:00:00 2001 From: cpojer Date: Tue, 2 Apr 2019 16:58:21 -0700 Subject: [PATCH 1/3] Properly copy template files. --- packages/cli/src/commands/init/template.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/init/template.js b/packages/cli/src/commands/init/template.js index 40c670487..24ad6b686 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 copyProjectTemplateAndReplace from '../../tools/generator/copyProjectTemplateAndReplace'; 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()); + copyProjectTemplateAndReplace(templatePath, process.cwd(), templateName); } export function executePostInitScript( From 3ae68f5a426f3da488e135b95a14fdd5a1d395bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Wed, 3 Apr 2019 09:58:53 +0200 Subject: [PATCH 2/3] use copyFiles with binary support --- .../init/__tests__/editTemplate.test.js | 3 +- .../commands/init/__tests__/template.test.js | 6 ++-- packages/cli/src/commands/init/template.js | 4 +-- packages/cli/src/tools/copyFiles.js | 28 +++++++++++++++++++ 4 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 packages/cli/src/tools/copyFiles.js 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 24ad6b686..dd7180ece 100644 --- a/packages/cli/src/commands/init/template.js +++ b/packages/cli/src/commands/init/template.js @@ -3,7 +3,7 @@ import {execFileSync} from 'child_process'; import path from 'path'; import * as PackageManager from '../../tools/PackageManager'; import logger from '../../tools/logger'; -import copyProjectTemplateAndReplace from '../../tools/generator/copyProjectTemplateAndReplace'; +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}`); - copyProjectTemplateAndReplace(templatePath, process.cwd(), templateName); + 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; From c2828e54a9b74b0548557e4d79862a0681dd3a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Wed, 3 Apr 2019 10:02:41 +0200 Subject: [PATCH 3/3] update snapshot --- e2e/__tests__/__snapshots__/legacyInit.test.js.snap | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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", },