Skip to content

Commit d776ec9

Browse files
committed
feat: setup the template
1 parent 0ef3354 commit d776ec9

File tree

15 files changed

+3953
-1
lines changed

15 files changed

+3953
-1
lines changed

.eslintrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "@antfu",
3+
"rules": {
4+
"@typescript-eslint/no-var-requires": "off"
5+
}
6+
}

.github/workflows/release.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
- 'test*'
8+
9+
jobs:
10+
release:
11+
runs-on: macos-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- uses: actions/setup-node@v3
18+
with:
19+
node-version: 16.x
20+
21+
- name: Build
22+
run: |
23+
npm install
24+
npm run build
25+
- name: Setup release files
26+
run: ./build.sh
27+
28+
- name: Release
29+
uses: ncipollo/release-action@v1
30+
with:
31+
artifacts: ./dist/your-workflow-name.alfredworkflow
32+
token: ${{ secrets.G_TOKEN }}
33+
34+
- run: npx changelogithub # or changelogithub@0.12 if ensure the stable result
35+
env:
36+
GITHUB_TOKEN: ${{secrets.G_TOKEN}}

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"prettier.enable": false,
3+
"editor.formatOnSave": false,
4+
"editor.codeActionsOnSave": {
5+
"source.fixAll.eslint": true
6+
}
7+
}

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
11
# alfred-workflow-ts-template
2-
template for building a alfred workflow in TypeScript.
2+
a Template for building a alfred workflow in TypeScript.
3+
4+
## Features
5+
6+
- 🦾 TypeScript, of course
7+
- ⚙️ Unit Testing with [Vitest](https://github.com/vitest-dev/vitest)
8+
- [Unbuild](https://github.com/unjs/unbuild), a unified javascript build system
9+
- JXA Types, supported by [@jxa/global-type](https://github.com/JXA-userland/JXA/tree/master/packages/@jxa/global-type)
10+
- Eslint
11+
- pnpm
12+
13+
## Usage
14+
15+
- modify the `package.json`
16+
- modify the `artifacts` value in `.github/workflows/release.yml`
17+
- filled in the workflow info in `src/update.sh`
18+
- generate your `info.plist` & `icon.png`
19+
20+
## Preview
21+
22+
# License
23+
24+
[MIT](./LICENSE) License © 2022 [Nauxscript](https://github.com/Nauxscript)

build.config.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { defineBuildConfig } from 'unbuild'
2+
3+
export default defineBuildConfig({
4+
entries: [
5+
'./src/index',
6+
],
7+
hooks: {
8+
'rollup:options': (ctx, option) => {
9+
(Array.isArray(option.output)) && option.output.push(
10+
{
11+
name: 'run',
12+
dir: ctx.options.outDir,
13+
format: 'iife',
14+
exports: 'auto',
15+
generatedCode: {
16+
constBindings: true,
17+
},
18+
externalLiveBindings: false,
19+
freeze: false,
20+
},
21+
)
22+
},
23+
},
24+
})

build.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
3+
# /bin/bash
4+
5+
# if any return not equal to true, process will quit.
6+
# refer to https://www.zhizhesoft.com/unix-linux-jiao-ben-zhong-set-e-de-zuo-yong/
7+
set -e
8+
9+
# refer to https://blog.csdn.net/qq_20417499/article/details/103308076
10+
# this script's parent directory
11+
cd $(dirname $0)
12+
parentDir=$(pwd)
13+
14+
cd dist
15+
echo "setup files ..."
16+
cp ${parentDir}/src/info.plist ./
17+
cp ${parentDir}/src/icon.png ./
18+
cp ${parentDir}/README.md ./
19+
cp ${parentDir}/LICENSE ./
20+
21+
rm ./index.mjs
22+
23+
# insert the vesion to .plist file, if you need
24+
echo "Updating version ..."
25+
curVersion=$(node -e "console.log(require('${parentDir}/package.json').version)")
26+
sed -i '' 's/{{version}}/'${curVersion}'/' ./info.plist
27+
28+
# insert the readme content in src dir to .plist file, if you need
29+
echo "Injecting readme ..."
30+
readme="${parentDir}/src/README.md"
31+
sed -i '' -e "/{{readme}}/{r ${readme}" -e 'd' -e '}' ./info.plist
32+
33+
# insert the auto-update to .plist file, if you need, and you need to fill in the workflow info in that file
34+
echo "Injecting auto-update script ..."
35+
update="$(mktemp)"
36+
# s/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g this pattern is use for repalcing '&' '<' '>'
37+
cat ${parentDir}/src/update.sh | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' > ${update}
38+
sed -i '' -e "/{{update_script}}/{r ${update}" -e 'd' -e '}' ./info.plist
39+
40+
echo "Bundling workflow ..."
41+
name=$(node -e "console.log(require('${parentDir}/package.json').name)")
42+
zip -Z deflate -rq9 ${parentDir}/dist/${name}.alfredworkflow * -x etc

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "your-workflow-name",
3+
"version": "1.0.0",
4+
"description": "",
5+
"scripts": {
6+
"lint:fix": "eslint . --fix",
7+
"test": "vitest",
8+
"build": "unbuild",
9+
"release": "bumpp package.json --commit --push --tag ",
10+
"release:test": "pnpm build && ./build.sh"
11+
},
12+
"keywords": [],
13+
"author": "",
14+
"license": "ISC",
15+
"devDependencies": {
16+
"@antfu/eslint-config": "^0.33.1",
17+
"@jxa/global-type": "^1.3.6",
18+
"@types/node": "^18.11.10",
19+
"bumpp": "^8.2.1",
20+
"eslint": "^8.29.0",
21+
"ts-node": "^10.9.1",
22+
"typescript": "^4.9.3",
23+
"unbuild": "^1.0.1",
24+
"vitest": "^0.25.3"
25+
},
26+
"peerDependencies": {
27+
"@jxa/global-type": "^1.3.6"
28+
}
29+
}

0 commit comments

Comments
 (0)