Skip to content

Commit

Permalink
[#683] convert copyFiles from flow to typescript (#690)
Browse files Browse the repository at this point in the history
* convert copyFiles from flow to typescript

* add ts-ignore for FIXME comment

* fix flow-check
  • Loading branch information
sasurau4 authored and Esemesek committed Sep 10, 2019
1 parent ed6205b commit cc2697a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fs from 'fs-extra';
import snapshotDiff from 'snapshot-diff';
import slash from 'slash';
import walk from '../../../tools/walk';
// $FlowFixMe - converted to TS
import copyFiles from '../../../tools/copyFiles';
import {changePlaceholderInTemplate} from '../editTemplate';

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/init/__tests__/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
copyTemplate,
executePostInitScript,
} from '../template';
// $FlowFixMe - converted to TS
import * as copyFiles from '../../../tools/copyFiles';

const TEMPLATE_NAME = 'templateName';
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/init/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import execa from 'execa';
import path from 'path';
import * as PackageManager from '../../tools/packageManager';
import {logger} from '@react-native-community/cli-tools';
// $FlowFixMe - converted to TS
import copyFiles from '../../tools/copyFiles';
import replacePathSepForRegex from '../../tools/replacePathSepForRegex';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import fs from 'fs';
import path from 'path';
// @ts-ignore FIXME after converting walk to typescript
import walk from './walk';

type Options = {
exclude?: Array<RegExp>,
exclude?: Array<RegExp>;
};

/**
Expand All @@ -21,10 +20,10 @@ type Options = {
async function copyFiles(
srcPath: string,
destPath: string,
options?: Options = {},
options: Options = {},
) {
return Promise.all(
walk(srcPath).map(async absoluteSrcFilePath => {
walk(srcPath).map(async (absoluteSrcFilePath: string) => {
const exclude = options.exclude;
if (exclude && exclude.some(p => p.test(absoluteSrcFilePath))) {
return;
Expand Down Expand Up @@ -63,7 +62,11 @@ function copyFile(srcPath: string, destPath: string) {
/**
* Same as 'cp' on Unix. Don't do any replacements.
*/
function copyBinaryFile(srcPath, destPath, cb) {
function copyBinaryFile(
srcPath: string,
destPath: string,
cb: (err?: Error) => void,
) {
let cbCalled = false;
const {mode} = fs.statSync(srcPath);
const readStream = fs.createReadStream(srcPath);
Expand All @@ -79,7 +82,7 @@ function copyBinaryFile(srcPath, destPath, cb) {
fs.chmodSync(destPath, mode);
});
readStream.pipe(writeStream);
function done(err) {
function done(err?: Error) {
if (!cbCalled) {
cb(err);
cbCalled = true;
Expand Down

0 comments on commit cc2697a

Please sign in to comment.