-
Notifications
You must be signed in to change notification settings - Fork 3
/
select.mjs
50 lines (40 loc) · 1.52 KB
/
select.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env node
import * as shellParams from './helpers/shellParams.mjs';
import { updateBundle } from './select/update-bundle.mjs';
import * as path from 'path';
(function() {
'use strict';
const directoryOrFilePath = shellParams.get().path;
let fileName,
folderFilePath;
if (isDirectory(directoryOrFilePath)) {
fileName = '.spec.ts';
folderFilePath = directoryOrFilePath;
console.info(`Directory selected.\n\n${logFiles('all files in folder', folderFilePath)}`);
} else if (isSpecFile(directoryOrFilePath)) {
fileName = getFileName(directoryOrFilePath);
folderFilePath = getDirectoryPath(directoryOrFilePath);
console.info(`Spec file selected.\n\n${logFiles(fileName, folderFilePath)}`);
} else {
const specFilePath = directoryOrFilePath.replace('.ts', '.spec.ts');
fileName = getFileName(specFilePath);
folderFilePath = getDirectoryPath(specFilePath);
console.info(`Non-directory and non-spec file selected, assuming this is the file to test.\n\n${logFiles(fileName, folderFilePath)}`);
}
updateBundle(folderFilePath, fileName);
function logFiles(file, folder) {
return `File watched: ${file}\nFolder: ${folder}`;
}
function isSpecFile(filePath) {
return path.basename(filePath).indexOf('.spec.ts') > 0;
}
function isDirectory(filePath) {
return path.basename(filePath).indexOf('.ts') < 0;
}
function getDirectoryPath(filePath) {
return path.dirname(filePath);
}
function getFileName(filePath) {
return path.basename(filePath);
}
})();