this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

move actions to their own files

+84 -64
+9
actions/disable.js
··· 1 + #! /usr/bin/env node 2 + 3 + import {disableAutomaticSwitching} from '../functions/index.js'; 4 + 5 + export async function disable() { 6 + await disableAutomaticSwitching(); 7 + 8 + console.log('Automatic switching disabled'); 9 + }
+24
actions/enable.js
··· 1 + import {config} from "../config.js"; 2 + import {packageJson} from "../constants/index.js"; 3 + import {enableAutomaticSwitching} from "../functions/index.js"; 4 + 5 + export async function enable({darkProfile, lightProfile}) { 6 + if (!darkProfile && !config.darkProfile) { 7 + throw new Error( 8 + `Dark profile must be specified with --dark-profile or previously set with \`${packageJson.name} set-dark-mode\``, 9 + ); 10 + } 11 + 12 + if (!lightProfile && !config.lightProfile) { 13 + throw new Error( 14 + `Light profile must be specified with --light-profile or previously set with \`${packageJson.name} set-light-mode\``, 15 + ); 16 + } 17 + 18 + if (darkProfile) config.darkProfile = darkProfile; 19 + if (lightProfile) config.lightProfile = lightProfile; 20 + 21 + await enableAutomaticSwitching(); 22 + 23 + console.log('Automatic switching enabled'); 24 + }
+5
actions/index.js
··· 1 + export {disable} from './disable.js' 2 + export {enable} from './enable.js' 3 + export {setModeProfile} from './set-mode-profile.js' 4 + export {status} from './status.js' 5 + export {updateProfile} from './update-profile.js'
+7
actions/set-mode-profile.js
··· 1 + import {config} from "../config.js"; 2 + 3 + export function setModeProfile({mode, profile}) { 4 + config[`${mode}Profile`] = profile; 5 + 6 + console.log(`${mode} mode profile set to '${profile}'`); 7 + }
+12
actions/status.js
··· 1 + import {isAutomaticSwitchingEnabled} from "../functions/index.js"; 2 + import {config} from "../config.js"; 3 + 4 + export async function status () { 5 + console.log( 6 + `automatic switching : ${ 7 + (await isAutomaticSwitchingEnabled()) ? 'enabled' : 'disabled' 8 + }`, 9 + ); 10 + console.log(`dark profile : ${config.darkProfile}`); 11 + console.log(`light profile : ${config.lightProfile}`); 12 + }
+17
actions/update-profile.js
··· 1 + import {config} from "../config.js"; 2 + import darkMode from "dark-mode"; 3 + import {setTerminalProfile} from "terminal-profile"; 4 + 5 + export async function updateProfile () { 6 + if (!config.darkProfile) { 7 + throw new Error('Dark profile not set'); 8 + } 9 + 10 + if (!config.lightProfile) { 11 + throw new Error('Light profile not set'); 12 + } 13 + 14 + const mode = (await darkMode.isEnabled()) ? 'dark' : 'light'; 15 + 16 + await setTerminalProfile(config[`${mode}Profile`]); 17 + }
+10 -64
cli.js
··· 1 1 #! /usr/bin/env node 2 2 3 + import {fileURLToPath} from 'node:url'; 3 4 import {program} from 'commander'; 4 - import darkMode from 'dark-mode'; 5 - import {setTerminalProfile} from 'terminal-profile'; 6 - import {config} from './config.js'; 7 - import { 8 - disableAutomaticSwitching, 9 - enableAutomaticSwitching, 10 - isAutomaticSwitchingEnabled, 11 - } from './functions/index.js'; 12 5 import {packageJson} from './constants/index.js'; 6 + import {disable, enable, setModeProfile, status, updateProfile} from "./actions/index.js"; 13 7 14 8 program 15 9 .name(packageJson.name) 16 10 .description(packageJson.description) 17 - .version(packageJson.version); 11 + .version(packageJson.version) 12 + .executableDir(fileURLToPath(new URL('commands', import.meta.url))); 18 13 19 14 program 20 15 .command('disable') 21 16 .description( 22 17 'Disable automatic macOS Terminal profile switching based on system dark / light mode', 23 18 ) 24 - .action(async () => { 25 - await disableAutomaticSwitching(); 26 - 27 - console.log('Automatic switching disabled'); 28 - }); 19 + .action(disable); 29 20 30 21 program 31 22 .command('enable') 32 - .description( 33 - 'Enable automatic macOS Terminal profile switching based on system dark / light mode', 34 - ) 23 + .description( 'Enable automatic macOS Terminal profile switching based on system dark / light mode') 35 24 .option( 36 25 '--dark-profile <profile>', 37 26 'dark profile name, for example "One Dark"', ··· 40 29 '--light-profile <profile>', 41 30 'light profile name, for example "One Light"', 42 31 ) 43 - .action(async ({darkProfile, lightProfile}) => { 44 - if (!darkProfile && !config.darkProfile) { 45 - throw new Error( 46 - `Dark profile must be specified with --dark-profile or previously set with \`${packageJson.name} set-dark-mode\``, 47 - ); 48 - } 49 - 50 - if (!lightProfile && !config.lightProfile) { 51 - throw new Error( 52 - `Light profile must be specified with --light-profile or previously set with \`${packageJson.name} set-light-mode\``, 53 - ); 54 - } 55 - 56 - if (darkProfile) config.darkProfile = darkProfile; 57 - if (lightProfile) config.lightProfile = lightProfile; 58 - 59 - await enableAutomaticSwitching(); 60 - 61 - console.log('Automatic switching enabled'); 62 - }); 32 + .action(enable); 63 33 64 34 for (const mode of ['dark', 'light']) { 65 35 program 66 36 .command(`set-${mode}-profile`) 67 37 .description(`Set the Terminal profile to use in ${mode} mode`) 68 38 .argument('<profile>') 69 - .action((profile) => { 70 - config[`${mode}Profile`] = profile; 71 - 72 - console.log(`${mode} mode profile set to '${profile}'`); 73 - }); 39 + .action((profile) => setModeProfile({mode, profile})); 74 40 } 75 41 76 42 program 77 43 .command('status') 78 44 .description('Show status and configuration') 79 - .action(async () => { 80 - console.log( 81 - `automatic switching : ${ 82 - (await isAutomaticSwitchingEnabled()) ? 'enabled' : 'disabled' 83 - }`, 84 - ); 85 - console.log(`dark profile : ${config.darkProfile}`); 86 - console.log(`light profile : ${config.lightProfile}`); 87 - }); 45 + .action(status); 88 46 89 47 program 90 48 .command('update-profile') 91 49 .description( 92 50 'Update the profile of currently running Terminal windows / tabs', 93 51 ) 94 - .action(async () => { 95 - if (!config.darkProfile) { 96 - throw new Error('Dark profile not set'); 97 - } 98 - 99 - if (!config.lightProfile) { 100 - throw new Error('Light profile not set'); 101 - } 102 - 103 - const mode = (await darkMode.isEnabled()) ? 'dark' : 'light'; 104 - 105 - await setTerminalProfile(config[`${mode}Profile`]); 106 - }); 52 + .action(updateProfile); 107 53 108 54 program.parse();