mac-helper 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.editorconfig ADDED
@@ -0,0 +1,13 @@
1
+ # EditorConfig is awesome: https://EditorConfig.org
2
+
3
+ # top-most EditorConfig file
4
+ root = true
5
+
6
+ # Unix-style newlines with a newline ending every file
7
+ [*]
8
+ end_of_line = lf
9
+ insert_final_newline = true
10
+ charset = utf-8
11
+ indent_style = space
12
+ indent_size = 2
13
+ trim_trailing_whitespace = true
package/.eslintignore ADDED
@@ -0,0 +1,4 @@
1
+ node_modules
2
+
3
+ lib
4
+ dist
package/.eslintrc.yml ADDED
@@ -0,0 +1,18 @@
1
+ # root
2
+ root: true
3
+ parser: '@typescript-eslint/parser'
4
+ plugins: ['@typescript-eslint']
5
+
6
+ env:
7
+ mocha: true
8
+ node: true
9
+
10
+ extends:
11
+ - 'eslint:recommended'
12
+ - 'plugin:@typescript-eslint/recommended'
13
+ - 'prettier'
14
+
15
+ rules:
16
+ '@typescript-eslint/ban-ts-comment': off
17
+ '@typescript-eslint/no-unused-vars': off
18
+ '@typescript-eslint/no-non-null-assertion': off
@@ -0,0 +1,27 @@
1
+ name: ci
2
+
3
+ on:
4
+ - push
5
+ - pull_request
6
+
7
+ jobs:
8
+ unit-test:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v3
12
+
13
+ - uses: pnpm/action-setup@v2
14
+ with: { version: 7 }
15
+
16
+ - uses: actions/setup-node@v3
17
+ with:
18
+ node-version: 16
19
+ cache: 'pnpm'
20
+
21
+ - run: pnpm install
22
+
23
+ # test
24
+ - run: pnpm test-cover
25
+
26
+ # test:report
27
+ - uses: codecov/codecov-action@v3
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ pnpm lint-staged
package/.mocharc.yml ADDED
@@ -0,0 +1,4 @@
1
+ require: [should]
2
+ reporter: spec
3
+ timeout: 5000
4
+ recursive: true
@@ -0,0 +1,4 @@
1
+ node_modules
2
+
3
+ lib
4
+ dist
package/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # CHANGELOG
2
+
3
+ ## v0.0.1 2023-03-01
4
+
5
+ - first release
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Magicdawn(magicdawn@qq.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # mac-helper
2
+
3
+ > useful helper for macOS
4
+
5
+ [![Build Status](https://img.shields.io/github/workflow/status/magicdawn/mac-helper/ci.yml?style=flat-square&branch=main)](https://github.com/magicdawn/mac-helper/actions/workflows/ci.yml)
6
+ [![Coverage Status](https://img.shields.io/codecov/c/github/magicdawn/mac-helper.svg?style=flat-square)](https://codecov.io/gh/magicdawn/mac-helper)
7
+ [![npm version](https://img.shields.io/npm/v/mac-helper.svg?style=flat-square)](https://www.npmjs.com/package/mac-helper)
8
+ [![npm downloads](https://img.shields.io/npm/dm/mac-helper.svg?style=flat-square)](https://www.npmjs.com/package/mac-helper)
9
+ [![npm license](https://img.shields.io/npm/l/mac-helper.svg?style=flat-square)](http://magicdawn.mit-license.org)
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ $ pnpm add mac-helper
15
+ ```
16
+
17
+ ## API
18
+
19
+ ```js
20
+ const MacHelper = require('mac-helper')
21
+ ```
22
+
23
+ ## Changelog
24
+
25
+ [CHANGELOG.md](CHANGELOG.md)
26
+
27
+ ## License
28
+
29
+ the MIT License http://magicdawn.mit-license.org
package/lib/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import '@jxa/global-type';
2
+ export declare function deprecated_getFinderSelectionViaAppleScript(): Promise<string>;
3
+ export declare function getPathFinderSelect(): Promise<string | null>;
4
+ export declare function getPathFinderSelects(): Promise<string[]>;
5
+ export declare const PathFinder: {
6
+ singleSelected(): Promise<string | null>;
7
+ allSelected(): Promise<string[]>;
8
+ };
package/lib/index.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PathFinder = exports.getPathFinderSelects = exports.getPathFinderSelect = exports.deprecated_getFinderSelectionViaAppleScript = void 0;
7
+ require("@jxa/global-type");
8
+ const run_1 = require("@jxa/run");
9
+ const applescript_1 = __importDefault(require("applescript"));
10
+ const promise_ify_1 = __importDefault(require("promise.ify"));
11
+ const SCRIPT_FI_SELECTION = `
12
+ tell application "Path Finder"
13
+ get POSIX path of (get item 1 of (get selection))
14
+ end tell
15
+ `;
16
+ async function deprecated_getFinderSelectionViaAppleScript() {
17
+ const result = (await (0, promise_ify_1.default)(applescript_1.default.execString, applescript_1.default)(SCRIPT_FI_SELECTION.trim()));
18
+ const url = result && result[0];
19
+ return url;
20
+ }
21
+ exports.deprecated_getFinderSelectionViaAppleScript = deprecated_getFinderSelectionViaAppleScript;
22
+ async function getPathFinderSelect() {
23
+ const filePath = await (0, run_1.run)(() => {
24
+ const app = Application('Path Finder');
25
+ return app.selection()?.[0]?.posixPath() ?? null;
26
+ });
27
+ return filePath;
28
+ }
29
+ exports.getPathFinderSelect = getPathFinderSelect;
30
+ async function getPathFinderSelects() {
31
+ const filePaths = await (0, run_1.run)(() => {
32
+ const app = Application('Path Finder');
33
+ return (app.selection() || []).map((x) => x?.posixPath());
34
+ });
35
+ return filePaths;
36
+ }
37
+ exports.getPathFinderSelects = getPathFinderSelects;
38
+ exports.PathFinder = {
39
+ singleSelected() {
40
+ return getPathFinderSelect();
41
+ },
42
+ allSelected() {
43
+ return getPathFinderSelects();
44
+ },
45
+ };
46
+ // ;(async () => {
47
+ // console.log(await getPathFinderSelect())
48
+ // console.log(await getPathFinderSelects())
49
+ // })()
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "mac-helper",
3
+ "version": "0.0.1",
4
+ "description": "useful helper for macOS",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "scripts": {
8
+ "test": "mocha",
9
+ "prepare": "husky install",
10
+ "test-cover": "nyc --reporter=lcov --reporter=text mocha",
11
+ "dev": "tsc -w --incremental",
12
+ "build": "rm -rf lib; rm tsconfig.tsbuildinfo; tsc",
13
+ "prepublishOnly": "pnpm build"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+ssh://git@github.com/magicdawn/mac-helper.git"
18
+ },
19
+ "keywords": [
20
+ "mac",
21
+ "helper",
22
+ "mac-helper"
23
+ ],
24
+ "author": "magicdawn",
25
+ "license": "MIT",
26
+ "bugs": {
27
+ "url": "https://github.com/magicdawn/mac-helper/issues"
28
+ },
29
+ "homepage": "https://github.com/magicdawn/mac-helper#readme",
30
+ "devDependencies": {
31
+ "@magicdawn/prettier-config": "^0.0.2",
32
+ "@swc/core": "^1.3.19",
33
+ "@types/node": "^18.11.9",
34
+ "@typescript-eslint/eslint-plugin": "^5.44.0",
35
+ "@typescript-eslint/parser": "^5.44.0",
36
+ "eslint": "^8.28.0",
37
+ "eslint-config-prettier": "^8.5.0",
38
+ "husky": "^8.0.2",
39
+ "lint-staged": "^13.0.3",
40
+ "mocha": "^10.1.0",
41
+ "nyc": "^15.1.0",
42
+ "prettier": "^2.7.1",
43
+ "should": "^13.2.3",
44
+ "typescript": "^4.9.5"
45
+ },
46
+ "packageManager": "pnpm@7.17.0",
47
+ "publishConfig": {
48
+ "registry": "https://registry.npmjs.org"
49
+ },
50
+ "lint-staged": {
51
+ "*.{js,jsx,ts,tsx,less,md}": [
52
+ "prettier --write"
53
+ ]
54
+ },
55
+ "dependencies": {
56
+ "@jxa/global-type": "^1.3.6",
57
+ "@jxa/run": "^1.3.6",
58
+ "applescript": "^1.0.0",
59
+ "promise.ify": "^0.4.0"
60
+ }
61
+ }
@@ -0,0 +1 @@
1
+ module.exports = require('@magicdawn/prettier-config')
package/src/index.ts ADDED
@@ -0,0 +1,48 @@
1
+ import '@jxa/global-type'
2
+ import { run as jxaRun } from '@jxa/run'
3
+ import AppleScript from 'applescript'
4
+ import pify from 'promise.ify'
5
+
6
+ const SCRIPT_FI_SELECTION = `
7
+ tell application "Path Finder"
8
+ get POSIX path of (get item 1 of (get selection))
9
+ end tell
10
+ `
11
+ export async function deprecated_getFinderSelectionViaAppleScript() {
12
+ const result = (await pify(
13
+ AppleScript.execString,
14
+ AppleScript
15
+ )(SCRIPT_FI_SELECTION.trim())) as string[]
16
+ const url = result && result[0]
17
+ return url
18
+ }
19
+
20
+ export async function getPathFinderSelect() {
21
+ const filePath: string | null = await jxaRun(() => {
22
+ const app = Application('Path Finder')
23
+ return app.selection()?.[0]?.posixPath() ?? null
24
+ })
25
+ return filePath
26
+ }
27
+
28
+ export async function getPathFinderSelects() {
29
+ const filePaths: string[] = await jxaRun(() => {
30
+ const app = Application('Path Finder')
31
+ return (app.selection() || []).map((x: any) => x?.posixPath())
32
+ })
33
+ return filePaths
34
+ }
35
+
36
+ export const PathFinder = {
37
+ singleSelected() {
38
+ return getPathFinderSelect()
39
+ },
40
+ allSelected() {
41
+ return getPathFinderSelects()
42
+ },
43
+ }
44
+
45
+ // ;(async () => {
46
+ // console.log(await getPathFinderSelect())
47
+ // console.log(await getPathFinderSelects())
48
+ // })()
package/test/.gitkeep ADDED
File without changes
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "include": ["src/**/*"],
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "lib",
6
+ "allowSyntheticDefaultImports": true,
7
+ "esModuleInterop": true,
8
+ "moduleResolution": "node",
9
+ "resolveJsonModule": true,
10
+ "target": "ES2020",
11
+ "module": "CommonJS",
12
+ "strictNullChecks": true,
13
+ "skipLibCheck": true,
14
+ "declaration": true
15
+ },
16
+ "ts-node": {
17
+ "swc": true
18
+ }
19
+ }