|
1 |
| -import path from "path"; |
2 |
| -import fs from "fs"; |
3 |
| -import { fileURLToPath } from "url"; |
| 1 | +import path from 'path' |
| 2 | +import fs from 'fs' |
| 3 | +import { fileURLToPath } from 'url' |
4 | 4 |
|
5 |
| -const __filename = fileURLToPath(import.meta.url); |
6 |
| -const __dirname = path.dirname(__filename); |
7 |
| -const __onWindows = |
8 |
| - process.platform === "win32" || process.platform === "win64"; |
| 5 | +const __filename = fileURLToPath(import.meta.url) |
| 6 | +const __dirname = path.dirname(__filename) |
| 7 | +const __onWindows = process.platform === 'win32' || process.platform === 'win64' |
9 | 8 |
|
10 | 9 | if (import.meta.url === `file://${process.argv[1]}`) {
|
11 | 10 | throw new Error(
|
12 |
| - "Sorry, purescript-spec-discovery only supports NodeJS environments!", |
13 |
| - ); |
| 11 | + 'Sorry, purescript-spec-discovery only supports NodeJS environments!' |
| 12 | + ) |
14 | 13 | }
|
15 | 14 |
|
16 | 15 | export function getSpecs(pattern, mapToAff) {
|
17 | 16 | return (onError, onSuccess) => {
|
18 |
| - const regex = new RegExp(pattern); |
| 17 | + const regex = new RegExp(pattern) |
19 | 18 | const modulePromises = fs
|
20 |
| - .readdirSync(path.join(__dirname, "..")) |
21 |
| - .filter((directory) => regex.test(directory)) |
22 |
| - .map((name) => { |
| 19 | + .readdirSync(path.join(__dirname, '..')) |
| 20 | + .filter(directory => regex.test(directory)) |
| 21 | + .map(name => { |
23 | 22 | const fullPath = __onWindows
|
24 |
| - ? path.join("file://", __dirname, "..", name, "index.js") |
25 |
| - : path.join(__dirname, "..", name, "index.js"); |
26 |
| - return import(fullPath).then((module) => { |
27 |
| - let spec = |
28 |
| - module && typeof module.spec !== "undefined" ? module.spec : null; |
29 |
| - |
30 |
| - if (!spec) return spec; |
| 23 | + ? path.join('file://', __dirname, '..', name, 'index.js') |
| 24 | + : path.join(__dirname, '..', name, 'index.js') |
| 25 | + return import(fullPath).then(module => { |
| 26 | + const spec = module && module.spec; |
| 27 | + if (!spec) return null; |
31 | 28 |
|
32 | 29 | if (spec.constructor.name !== "Aff") {
|
33 | 30 | return mapToAff(spec);
|
34 | 31 | }
|
35 | 32 |
|
36 | 33 | return spec;
|
37 |
| - }); |
38 |
| - }); |
| 34 | + }) |
| 35 | + }) |
39 | 36 |
|
40 | 37 | Promise.all(modulePromises)
|
41 |
| - .then((specs) => { |
42 |
| - const s = specs.filter((x) => x); |
43 |
| - return onSuccess(s); |
44 |
| - }) |
45 |
| - .catch(onError); |
| 38 | + .then(specs => onSuccess(specs.filter(x => x))) |
| 39 | + .catch(onError) |
46 | 40 |
|
47 |
| - return () => {}; |
48 |
| - }; |
| 41 | + return () => {} |
| 42 | + } |
49 | 43 | }
|
0 commit comments