Skip to content
This repository has been archived by the owner on Oct 30, 2020. It is now read-only.

Commit

Permalink
feat: add listCommands function printing out a Markdown tables of all (
Browse files Browse the repository at this point in the history
  • Loading branch information
phuctm97 committed Apr 25, 2020
1 parent dec43a1 commit d7c07b4
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ LICENSE
package-lock.json
yarn.lock

## Auto-generated documents.
docs/COMMANDS.md

### .gitignore.

## macOS template.
Expand Down
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ jobs:
showClock: true
```
A workflow has `jobs`, each job `uses` a command with a set of `args` to construct an automation.
Check out [Features] to see full list of supported commands.

#### Run your workflow

Simply run the `jxax` CLI with your configured workflow YAML file, either absolute or relative or
Expand All @@ -121,21 +124,18 @@ $ jxax your-workflow.yml

## Features

Currently, JXAX supports:

- `sysprefs.configureGeneral`: configure _System Preferences/General_.

- `sysprefs.configureDock`: configure _System Preferences/Dock_.

- `sysprefs.configureMissionControl`: configure _System Preferences/Mission Control_.

- `sysprefs.configureSpotlight`: configure _System Preferences/Spotlight_.
Currently, JXAX supports following commands:

- `desktops.changePicture`: change desktop picture, either picture names in
_Apple Desktop Pictures_ or absolute paths or relative paths are applicable.
| Command | Description |
| ---------------------------------- | -------------------------------------------- |
| `desktops.changePicture` | Change current Desktop picture |
| `desktops.configureScreenSaver` | Configure screen saver preferences |
| `sysprefs.configureGeneral` | Configure System Preferences/General |
| `sysprefs.configureDock` | Configure System Preferences/Dock |
| `sysprefs.configureMissionControl` | Configure System Preferences/Mission Control |
| `sysprefs.configureSpotlight` | Configure System Preferences/Spotlight |

- `sysprefs.configureScreenSaver`: change screen saver, configure screen saver options. Screen
savers have to be added before being able to be configured.
See [Commands][commands-file] for the commands' details (arguments and types).

😬We're adding more features constantly. However, the features to be added are dependent on our
maintainers' interests. If you'd love to add a feature, feel free to create an issue and submit
Expand Down Expand Up @@ -167,5 +167,7 @@ Copyright © 2020 - present, Phuc (Minh) Tran. All rights reserved.

<!-- Links -->

[features]: #features
[commands-file]: /docs/COMMANDS.md
[license-file]: /LICENSE
[contributing-file]: /CONTRIBUTING.md
97 changes: 97 additions & 0 deletions docs/COMMANDS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<!-- This is an auto-generated document, using `jxax --ls-cmds --format long > docs/COMMANDS.md` -->

# Commands

Currently, JXAX supports following commands:

| Command | Description |
| -------------------------------------------------------------------- | -------------------------------------------- |
| [desktops.changePicture](#desktopschangepicture) | Change current Desktop picture |
| [desktops.configureScreenSaver](#desktopsconfigurescreensaver) | Configure screen saver preferences |
| [sysprefs.configureGeneral](#sysprefsconfiguregeneral) | Configure System Preferences/General |
| [sysprefs.configureDock](#sysprefsconfiguredock) | Configure System Preferences/Dock |
| [sysprefs.configureMissionControl](#sysprefsconfiguremissioncontrol) | Configure System Preferences/Mission Control |
| [sysprefs.configureSpotlight](#sysprefsconfigurespotlight) | Configure System Preferences/Spotlight |

## desktops.changePicture

Change current Desktop picture.

| Argument | Type | Description |
| --------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `picture` | `string` | Path to the new Desktop picture, e.g. ~/Pictures/Wallpaper.jpg, ./images/wallpaper.png, Catalina Rock (default to Apple Desktop pictures) |

## desktops.configureScreenSaver

Configure screen saver preferences.

| Argument | Type | Description |
| ---------------- | --------- | ---------------------------------------------------------------------------------------------------------------------- |
| `screenSaver` | `string` | Name of the new screen saver, which has to added in advance |
| `delayInterval` | `enum` | The time in seconds of inactivity before the screen saver is shown (`0` / `1` / `2` / `5` / `10` / `20` / `30` / `60`) |
| `mainScreenOnly` | `boolean` | Show screen saver in main display only |
| `showClock` | `boolean` | Show a clock along with the screen saver when it' being shown |

## sysprefs.configureGeneral

Configure System Preferences/General.

| Argument | Type | Description |
| ----------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------- |
| `appearance` | `enum` | Appearance (`"light"` / `"dark"` / `"auto"`) |
| `accentColor` | `enum` | Accent color (`"blue"` / `"purple"` / `"pink"` / `"red"` / `"orange"` / `"yellow"` / `"green"` / `"graphite"`) |
| `highlightColor` | `enum` | Highlight color (`"blue"` / `"purple"` / `"pink"` / `"red"` / `"orange"` / `"yellow"` / `"green"` / `"graphite"`) |
| `sidebarIconSize` | `enum` | Sidebar icon size (`"small"` / `"medium"` / `"large"`) |
| `autoHideMenuBar` | `boolean` | Automatically hide and show menu bar |
| `showScrollBars` | `enum` | Show scroll bars trigger (`"auto"` / `"whenScrolling"` / `"always"`) |
| `clickScrollBar` | `enum` | Click scroll bar to (`"jumpToNextPage"` / `"jumpToSpotClicked"`) |
| `defaultWebBrowser` | `string` | Default web browser |
| `askWhenClosingDocuments` | `boolean` | Ask to keep changes when closing documents |
| `closeWindowsWhenQuittingApp` | `boolean` | Close windows when quitting an app |
| `recentItems` | `enum` | Number of items to show in Recent items (`0` / `5` / `10` / `15` / `20` / `30` / `50`) |
| `allowHandoff` | `boolean` | Allow Handoff between this Mac and your iCloud devices |
| `useFontSmoothing` | `boolean` | Use font smoothing when available |

## sysprefs.configureDock

Configure System Preferences/Dock.

| Argument | Type | Description |
| -------------------------------- | --------- | --------------------------------------------------------------------------------------------- |
| `size` | `string` | Size/height of the items (between 0.0 (minimum) and 1.0 (maximum)) |
| `magnification` | `boolean` | Is magnification on or off? |
| `magnificationSize` | `string` | Maximum magnification size when magnification is on (between 0.0 (minimum) and 1.0 (maximum)) |
| `location` | `enum` | Location on screen (`"bottom"` / `"left"` / `"right"`) |
| `minimizeEffect` | `enum` | Minimization effect (`"genie"` / `"scale"`) |
| `preferTabsWhenOpeningDocuments` | `enum` | Prefer tabs when opening documents (`"always"` / `"inFullScreenOnly"` / `"manually"`) |
| `doubleClickTitleBar` | `enum` | Double-click window's title bar to (`"none"` / `"zoom"` / `"minimize"`) |
| `minimizeToAppIcon` | `boolean` | Minimize windows to application icon |
| `animate` | `boolean` | Is the animation of opening applications on or off? |
| `autohide` | `boolean` | Is autohiding the dock on or off? |
| `showOpenIndicators` | `boolean` | Show indicators for opening applications |
| `showRecentApps` | `boolean` | Show recent applications in Dock |

## sysprefs.configureMissionControl

Configure System Preferences/Mission Control.

| Argument | Type | Description |
| ---------------------------- | --------- | --------------------------------------------------------------------------------------- |
| `autoRearrangeSpaces` | `boolean` | Automatically rearrange Spaces based on mist recent use |
| `switchSpaceWhenSwithToApp` | `boolean` | When switching to an application, switch to Space with open windows for the application |
| `groupWindowsByApp` | `boolean` | Group windows by application |
| `displaysHaveSeparateSpaces` | `boolean` | Displays have separate Spaces |
| `missionControlKeyShortcut` | `string` | Mission Control keyboard shortcut |
| `appWindowsKeyShortcut` | `string` | Application Windows keyboard shortcut |
| `showDesktopKeyShortcut` | `string` | Show Desktop keyboarb shortcut |

## sysprefs.configureSpotlight

Configure System Preferences/Spotlight.

| Argument | Type | Description |
| ------------------------ | --------------- | ----------------------------------------------------------------- |
| `searchResults` | `arrayOfString` | The array of categories to be shown in Spotlight's search results |
| `allowSpotlightInLookup` | `boolean` | Allow Spotlight Suggestions in Look up |


1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"ansi-escape-sequences": "^5.1.2",
"js-yaml": "^3.13.1",
"lodash": "^4.17.15",
"markdown-table": "^2.0.0",
"validate.js": "^0.13.1"
},
"devDependencies": {
Expand Down
73 changes: 73 additions & 0 deletions src/bin/listCommands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import * as markdownTable from 'markdown-table';
import { print } from '@core/app';
import library from '@bin/library';

function addFinalDot(s) {
if (s.endsWith('.')) return s;
return `${s}.`;
}

function makeSectionLink(name) {
return `[${name}](#${name.replace('.', '').toLowerCase()})`;
}

function longFormat(commands) {
let output = '<!-- This is an auto-generated document, using `jxax --ls-cmds --format long > docs/COMMANDS.md` --> \n\n';
output += '# Commands\n\n';
output += 'Currently, JXAX supports following commands:\n\n';
output += markdownTable([
['Command', 'Description'],
...commands.map((cmd) => [makeSectionLink(cmd.name), cmd.description]),
]);
output += '\n\n';

commands.forEach((cmd) => {
output += `## ${cmd.name}\n\n`;
output += `${addFinalDot(cmd.description)}\n\n`;
output += markdownTable([
['Argument', 'Type', 'Description'],
...Object.entries(cmd.args)
.map(([key, val]) => {
let { type, description } = val;
if (val.inclusion) {
type = 'enum';
description += ` (${val.inclusion.within
.map((it) => `\`${JSON.stringify(it)}\``)
.join(' / ')})`;
}
return [`\`${key}\``, `\`${type ?? 'string'}\``, description];
}),
]);
output += '\n\n';
});
return output;
}

function shortFormat(commands) {
return markdownTable([
['Command', 'Description'],
...commands.map((cmd) => [`\`${cmd.name}\``, cmd.description]),
]);
}

/**
* List all available `Command`(s).
*
* @param {string} format Output format (`short`/`long`).
*/
export default function listCommands(format = 'short') {
const commands = Object.entries(library).map(([name, cmd]) => ({
name,
description: cmd.description,
args: cmd.args,
}));

switch (format) {
case 'long': print(longFormat(commands));
break;
case 'short': print(shortFormat(commands));
break;
default:
throw new Error(`unknown format ${format}`);
}
}
17 changes: 17 additions & 0 deletions src/core/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,20 @@ retry.defaultOpts = {
maxAttempts: 3,
delayInterval: 0.5,
};

// Import 'Foundation' in advance for `print` to access 'Foundation' APIs.
ObjC.import('Foundation');

/**
* Print to standard output.
*
* @param {...any} args Arguments.
*/
export function print(...args) {
args.forEach((a) => {
$.NSFileHandle.fileHandleWithStandardOutput.writeData(
$.NSString.alloc.initWithString(`${String(a)}\n`)
.dataUsingEncoding($.NSNEXTSTEPStringEncoding),
);
});
}
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4791,6 +4791,13 @@ map-visit@^1.0.0:
dependencies:
object-visit "^1.0.0"

markdown-table@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/markdown-table/-/markdown-table-2.0.0.tgz#194a90ced26d31fe753d8b9434430214c011865b"
integrity sha512-Ezda85ToJUBhM6WGaG6veasyym+Tbs3cMAw/ZhOPqXiYsr0jgocBV3j3nx+4lk47plLlIqjwuTm/ywVI+zjJ/A==
dependencies:
repeat-string "^1.0.0"

marked-terminal@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/marked-terminal/-/marked-terminal-4.1.0.tgz#01087372d3636dc7cb286475a1d6147187f500e0"
Expand Down Expand Up @@ -6428,7 +6435,7 @@ repeat-element@^1.1.2:
resolved "https://registry.yarnpkg.com/repeat-element/-/repeat-element-1.1.3.tgz#782e0d825c0c5a3bb39731f84efee6b742e6b1ce"
integrity sha512-ahGq0ZnV5m5XtZLMb+vP76kcAM5nkLqk0lpqAuojSKGgQtn4eRi4ZZGm2olo2zKFH+sMsWaqOCW1dqAnOru72g==

repeat-string@^1.6.1:
repeat-string@^1.0.0, repeat-string@^1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637"
integrity sha1-jcrkcOHIirwtYA//Sndihtp15jc=
Expand Down

0 comments on commit d7c07b4

Please sign in to comment.