Skip to content

Commit 26ce7bd

Browse files
Merge pull request #1239 from opencomponents/cli-facade-ts
move to TS most of the cli/facade files
2 parents 7632f0c + bf06d5b commit 26ce7bd

20 files changed

+535
-390
lines changed
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
'use strict';
1+
import path from 'path';
2+
import chokidar from 'chokidar';
23

3-
const path = require('path');
4-
const chokidar = require('chokidar');
4+
import settings from '../../resources/settings';
55

6-
const settings = require('../../resources/settings').default;
7-
8-
module.exports = function(dirs, baseDir, changed) {
6+
export default function watch(
7+
dirs: string[],
8+
baseDir: string,
9+
changed: (err: Error | null, fileName: string, componentDir?: string) => void
10+
): void {
911
const watcher = chokidar.watch(path.resolve(baseDir), {
1012
ignored: settings.filesToIgnoreOnDevWatch,
1113
persistent: true,
1214
ignoreInitial: true,
1315
usePolling: false
1416
});
15-
const onChange = fileName => {
17+
const onChange = (fileName: string) => {
1618
const componentDir = dirs.find(dir =>
1719
Boolean(fileName.match(escapeRegularExpression(dir + path.sep)))
1820
);
@@ -24,8 +26,8 @@ module.exports = function(dirs, baseDir, changed) {
2426
.on('change', onChange)
2527
.on('unlink', onChange)
2628
.on('error', changed);
27-
};
29+
}
2830

29-
function escapeRegularExpression(text) {
31+
function escapeRegularExpression(text: string) {
3032
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
3133
}

src/cli/facade/clean.js renamed to src/cli/facade/clean.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
'use strict';
1+
import read from 'read';
2+
import strings from '../../resources/index';
3+
import { Local } from '../../types';
4+
import { Logger } from '../logger';
25

3-
const read = require('read');
4-
5-
const strings = require('../../resources/index').default;
6-
7-
module.exports = function(dependencies) {
8-
const { local, logger } = dependencies;
9-
const { fetchList, remove } = local.clean;
6+
const clean = ({
7+
local: {
8+
clean: { fetchList, remove }
9+
},
10+
logger
11+
}: {
12+
local: Local;
13+
logger: Logger;
14+
}) => {
1015
const {
1116
cleanAlreadyClean,
1217
cleanList,
@@ -15,7 +20,7 @@ module.exports = function(dependencies) {
1520
cleanSuccess
1621
} = strings.messages.cli;
1722

18-
const prompt = cb =>
23+
const prompt = (cb: (proceed: boolean) => void) =>
1924
read(
2025
{ prompt: cleanPrompt, default: cleanPromptDefault },
2126
(err, result) => {
@@ -26,21 +31,24 @@ module.exports = function(dependencies) {
2631
}
2732
);
2833

29-
const removeFolders = (list, cb) =>
34+
const removeFolders = (list: string[], cb: (err?: unknown) => void) =>
3035
remove(list, err => {
3136
if (err) {
32-
logger.err(strings.errors.cli.cleanRemoveError(err));
37+
logger.err(strings.errors.cli.cleanRemoveError(String(err)));
3338
return cb(err);
3439
}
3540

3641
logger.ok(cleanSuccess);
3742
cb();
3843
});
3944

40-
return function(opts, callback) {
45+
return (
46+
opts: { dirPath: string; yes: boolean },
47+
callback: (err?: unknown) => void
48+
) => {
4149
fetchList(opts.dirPath, (err, list) => {
4250
if (err) {
43-
logger.err(strings.errors.generic(err));
51+
logger.err(strings.errors.generic(String(err)));
4452
return callback(err);
4553
}
4654

@@ -63,3 +71,7 @@ module.exports = function(dependencies) {
6371
});
6472
};
6573
};
74+
75+
export default clean;
76+
77+
module.exports = clean;

src/cli/facade/dev.js

Lines changed: 0 additions & 205 deletions
This file was deleted.

0 commit comments

Comments
 (0)