forked from notion-enhancer/notion-enhancer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin.js
executable file
·74 lines (64 loc) · 2.19 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env node
/*
* notion-enhancer
* (c) 2020 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
* (https://dragonwocky.me/notion-enhancer) under the MIT license
*/
'use strict';
const cli = require('cac')('notion-enhancer'),
{ EnhancerError } = require('./pkg/helpers.js');
// === title ===
// ...information
// * warning
// > prompt
// -- response
// ~~ exit
// ### error ###
cli.option('-y, --yes', ': skip prompts (may overwrite data)');
cli.option('-n, --no', ': skip prompts (may cause failures)');
cli.option('-d, --dev', ': show detailed error messages (for debug purposes)');
cli
.command('apply', ': add the enhancer to the notion app')
.action(async (options) => {
console.info('=== NOTION ENHANCEMENT LOG ===');
await require('./pkg/apply.js')({
overwrite_version: options.yes ? 'y' : options.no ? 'n' : undefined,
friendly_errors: !options.dev,
});
console.info('=== END OF LOG ===');
});
cli
.command('remove', ': return notion to its pre-enhanced/pre-modded state')
.action(async (options) => {
console.info('=== NOTION RESTORATION LOG ===');
await require('./pkg/remove.js')({
delete_data: options.yes ? 'y' : options.no ? 'n' : undefined,
friendly_errors: !options.dev,
});
console.info('=== END OF LOG ===');
});
cli
.command('check', ': check the current state of the notion app')
.action(async (options) => {
try {
const status = await require('./pkg/check.js')();
console.info(options.dev ? status : status.msg);
} catch (err) {
console.error(
err instanceof EnhancerError && !options.dev ? err.message : err
);
}
});
let helpCalled = false;
cli.globalCommand.option('-h, --help', ': display usage information');
cli.globalCommand.helpCallback = (sections) => {
sections[0].body += '\nhttps://github.com/notion-enhancer/notion-enhancer';
helpCalled = true;
};
cli.showHelpOnExit = true;
cli.globalCommand.option('-v, --version', ': display version number');
cli.globalCommand.versionNumber = require('./package.json').version;
cli.showVersionOnExit = true;
cli.parse();
if (!cli.matchedCommand && !helpCalled && !cli.options.version)
cli.outputHelp();