forked from alrra/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add Raycast scripts for Trello integration and dotenv support
- Loading branch information
Showing
8 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Raycast Script Commands | ||
|
||
## Overview | ||
This repository contains a collection of scripts for the Raycast app. Visit the [Raycast website](https://raycast.com) to learn more about the app and [Raycast Script Commands](https://github.com/raycast/script-commands) to learn more about Script Commands. | ||
|
||
## References | ||
|
||
Raycast | ||
- https://developers.raycast.com/ | ||
- https://github.com/raycast/script-commands/tree/master | ||
- https://github.com/faisal3389/raycast-script-commands/blob/main/world-time.sh | ||
- https://www.raycast.com/blog/getting-started-with-script-commands | ||
- https://github.com/raycast/extensions/tree/main/extensions/ai-git-assistant | ||
|
||
Trello | ||
- https://developer.atlassian.com/cloud/trello/rest/api-group-actions/#api-group-actions | ||
- https://github.com/raycast/extensions/tree/main/extensions/trello | ||
- https://trello.com/power-ups/admin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
# https://github.com/raycast/script-commands/issues/165 | ||
|
||
# Required parameters: | ||
# @raycast.schemaVersion 1 | ||
# @raycast.title Create Trello Highlight Card | ||
# @raycast.packageName Trello | ||
# @raycast.mode compact | ||
|
||
# Optional parameters: | ||
# @raycast.icon ./icons/trello-64x64.png | ||
# @raycast.argument1 { "type": "text", "placeholder": "Card title" } | ||
# @raycast.argument2 { "type": "text", "placeholder": "Due date (e.g. today)", "optional": true } | ||
|
||
# Documentation: | ||
# @raycast.description Create a new Trello Highlight card | ||
# @raycast.author Cheong Yip | ||
# @raycast.authorURL https://github.com/wingy3181 | ||
|
||
source libs/load-node.sh | ||
|
||
node scripts/create-trello-card.mjs "$1" "$2" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
// https://flaviocopes.com/fix-dirname-not-defined-es-module-scope/ | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
const envFilePath = path.resolve(__dirname, '../.env'); | ||
const envFileContent = fs.readFileSync(envFilePath, 'utf-8'); | ||
|
||
envFileContent.split('\n').forEach(line => { | ||
if (line.startsWith('#') || !line.includes('=')) { | ||
return; | ||
} | ||
const [key, value] = line.split('='); | ||
if (key && value) { | ||
process.env[key.trim()] = value.trim(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export NVM_DIR="${HOME}/.nvm" | ||
[ -f "$NVM_DIR/nvm.sh" ] \ | ||
&& . "$NVM_DIR/nvm.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
# https://github.com/raycast/script-commands/issues/165 | ||
|
||
# Required parameters: | ||
# @raycast.schemaVersion 1 | ||
# @raycast.title Open Trello Personal Board | ||
# @raycast.packageName Trello | ||
# @raycast.mode silent | ||
|
||
# Optional parameters: | ||
# @raycast.icon ./icons/trello-64x64.png | ||
|
||
# Documentation: | ||
# @raycast.description Open Trello Personal Board | ||
# @raycast.author Cheong Yip | ||
# @raycast.authorURL https://github.com/wingy3181 | ||
|
||
source .env | ||
|
||
open $TRELLO_PERSONAL_BOARD_URL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#!/usr/bin/env node | ||
|
||
import * as https from 'https'; | ||
import * as process from 'process'; | ||
import '../libs/dotenv.mjs'; | ||
|
||
// To generate an API key/token, head to https://trello.com/app-key | ||
// https://trello.com/power-ups/admin/ | ||
const TRELLO_KEY = process.env.TRELLO_KEY | ||
const TRELLO_SECRET = process.env.TRELLO_SECRET | ||
const TRELLO_TOKEN = process.env.TRELLO_TOKEN | ||
// To find the Board ID, head to https://api.trello.com/1/members/me/boards?key={TRELLO_KEY}&token={TRELLO_TOKEN} | ||
// To find the List ID, head to https://api.trello.com/1/boards/{BOARD_ID}/lists?key={TRELLO_KEY}&token={TRELLO_TOKEN} | ||
|
||
const TRELLO_LIST_ID = process.env.TRELLO_LIST_ID | ||
|
||
// To find the List ID, head to https://api.trello.com/1/me?key={TRELLO_KEY}&token={TRELLO_TOKEN} | ||
const TRELLO_MEMBER_ID = process.env.TRELLO_MEMBER_ID | ||
|
||
if (!TRELLO_KEY) { | ||
console.error('💥 Command not configured correctly. Missing variable: TRELLO_KEY'); | ||
process.exit(1); | ||
} | ||
|
||
if (!TRELLO_TOKEN) { | ||
console.error('💥 Command not configured correctly. Missing variable: TRELLO_TOKEN'); | ||
process.exit(1); | ||
} | ||
|
||
if (!TRELLO_LIST_ID) { | ||
console.error('💥 Command not configured correctly. Missing variable: TRELLO_LIST_ID'); | ||
process.exit(1); | ||
} | ||
|
||
if (!TRELLO_MEMBER_ID) { | ||
console.error('💥 Command not configured correctly. Missing variable: TRELLO_MEMBER_ID'); | ||
process.exit(1); | ||
} | ||
|
||
// https://nodejs.org/docs/latest/api/process.html#processargv | ||
const name = process.argv[2]; | ||
const dueDate = process.argv[3]; | ||
|
||
if (!name) { | ||
console.error('💥 Please provide a card title'); | ||
process.exit(1); | ||
} | ||
|
||
const payload = { | ||
key: TRELLO_KEY, | ||
token: TRELLO_TOKEN, | ||
idList: TRELLO_LIST_ID, | ||
idMembers: [TRELLO_MEMBER_ID], | ||
name: name, | ||
pos: 'top' | ||
}; | ||
|
||
if (dueDate) { | ||
try { | ||
const datetime = new Date(dueDate); | ||
if (!(datetime instanceof Date)) { | ||
throw new Error('Invalid date'); | ||
} | ||
payload['due'] = datetime.toISOString().split('T')[0]; | ||
} catch (error) { | ||
console.error('💥 Error parsing due date:', error); | ||
} | ||
} | ||
|
||
const postData = new URLSearchParams(payload).toString(); | ||
|
||
const options = { | ||
hostname: 'api.trello.com', | ||
path: '/1/cards', | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
'Content-Length': postData.length | ||
} | ||
}; | ||
|
||
const req = https.request(options, res => { | ||
let data = ''; | ||
|
||
res.on('data', chunk => { | ||
data += chunk; | ||
}); | ||
|
||
res.on('end', () => { | ||
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) { | ||
console.log('✅ Trello card created successfully'); | ||
} else { | ||
console.error('💥 Error creating Trello card:', res.statusCode, data); | ||
process.exit(1); | ||
} | ||
}); | ||
}); | ||
|
||
req.on('error', error => { | ||
console.error('💥 Error creating Trello card:', error); | ||
process.exit(1); | ||
}); | ||
|
||
req.write(postData); | ||
req.end(); |