Skip to content

Commit cc2697a

Browse files
sasurau4Esemesek
authored andcommitted
[#683] convert copyFiles from flow to typescript (#690)
* convert copyFiles from flow to typescript * add ts-ignore for FIXME comment * fix flow-check
1 parent ed6205b commit cc2697a

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

packages/cli/src/commands/init/__tests__/editTemplate.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import fs from 'fs-extra';
55
import snapshotDiff from 'snapshot-diff';
66
import slash from 'slash';
77
import walk from '../../../tools/walk';
8+
// $FlowFixMe - converted to TS
89
import copyFiles from '../../../tools/copyFiles';
910
import {changePlaceholderInTemplate} from '../editTemplate';
1011

packages/cli/src/commands/init/__tests__/template.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
copyTemplate,
1010
executePostInitScript,
1111
} from '../template';
12+
// $FlowFixMe - converted to TS
1213
import * as copyFiles from '../../../tools/copyFiles';
1314

1415
const TEMPLATE_NAME = 'templateName';

packages/cli/src/commands/init/template.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import execa from 'execa';
33
import path from 'path';
44
import * as PackageManager from '../../tools/packageManager';
55
import {logger} from '@react-native-community/cli-tools';
6+
// $FlowFixMe - converted to TS
67
import copyFiles from '../../tools/copyFiles';
78
import replacePathSepForRegex from '../../tools/replacePathSepForRegex';
89

packages/cli/src/tools/copyFiles.js renamed to packages/cli/src/tools/copyFiles.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
6-
*
7-
* @flow
86
*/
97

108
import fs from 'fs';
119
import path from 'path';
10+
// @ts-ignore FIXME after converting walk to typescript
1211
import walk from './walk';
1312

1413
type Options = {
15-
exclude?: Array<RegExp>,
14+
exclude?: Array<RegExp>;
1615
};
1716

1817
/**
@@ -21,10 +20,10 @@ type Options = {
2120
async function copyFiles(
2221
srcPath: string,
2322
destPath: string,
24-
options?: Options = {},
23+
options: Options = {},
2524
) {
2625
return Promise.all(
27-
walk(srcPath).map(async absoluteSrcFilePath => {
26+
walk(srcPath).map(async (absoluteSrcFilePath: string) => {
2827
const exclude = options.exclude;
2928
if (exclude && exclude.some(p => p.test(absoluteSrcFilePath))) {
3029
return;
@@ -63,7 +62,11 @@ function copyFile(srcPath: string, destPath: string) {
6362
/**
6463
* Same as 'cp' on Unix. Don't do any replacements.
6564
*/
66-
function copyBinaryFile(srcPath, destPath, cb) {
65+
function copyBinaryFile(
66+
srcPath: string,
67+
destPath: string,
68+
cb: (err?: Error) => void,
69+
) {
6770
let cbCalled = false;
6871
const {mode} = fs.statSync(srcPath);
6972
const readStream = fs.createReadStream(srcPath);
@@ -79,7 +82,7 @@ function copyBinaryFile(srcPath, destPath, cb) {
7982
fs.chmodSync(destPath, mode);
8083
});
8184
readStream.pipe(writeStream);
82-
function done(err) {
85+
function done(err?: Error) {
8386
if (!cbCalled) {
8487
cb(err);
8588
cbCalled = true;

0 commit comments

Comments
 (0)