-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin.js
executable file
·54 lines (43 loc) · 1.41 KB
/
bin.js
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
51
52
53
54
#!/usr/bin/env node
'use strict';
process.title = 'swiftlint';
if (process.platform !== 'darwin') {
console.log('!!! WARN: Not running SwiftLint for non-macOS platform: ' + process.platform + '\n');
process.exit();
}
const { Subprocess } = require('@ionic/utils-subprocess');
const { writeJson } = require('@ionic/utils-fs');
const { cosmiconfig } = require('cosmiconfig');
const os = require('os');
const path = require('path');
const { isInstalled } = require('./utils');
const getConfigPath = async () => {
try {
const explorer = cosmiconfig('swiftlint');
const result = await explorer.search();
const tmppath = path.resolve(os.tmpdir(), 'swiftlint-config');
const config = typeof result.config === 'string' ? require(result.config) : result.config;
await writeJson(tmppath, config, { spaces: 2 });
console.log('node-swiftlint: using config from', result.filepath);
return tmppath;
} catch (e) {
// ignore
}
};
const run = async () => {
if (await isInstalled()) {
const p = await getConfigPath();
const proc = new Subprocess(
'swiftlint',
[...process.argv.slice(2), ...p ? ['--config', p] : []],
{ stdio: 'inherit' },
);
await proc.run();
} else {
console.log(
`!!! WARN: SwiftLint not found in PATH. You can install it with Homebrew:\n\n` +
` > brew install swiftlint\n`
);
}
};
run().catch(() => { process.exit(1); });