From b57d00109e1489e5f090b9f2bde9e0b7fc14c0fe Mon Sep 17 00:00:00 2001 From: Lakr Aream Date: Tue, 23 Aug 2022 20:20:49 +0800 Subject: [PATCH] Sync Update - d8d1058 [feat: ts template] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: 寻 --- App/Action/Action.xcodeproj/project.pbxproj | 8 +- App/Action/Action/Application/License.txt | 2 +- .../zh-Hans.lproj/Localizable.strings | 1 + .../Backend/Action/ActionManager+Module.swift | 4 +- .../ActionManager+Template.swift | 2 + .../ActionModuleTemplates/Template+Node.swift | 152 ++++++++++++++++++ .../Template+Swift.swift | 22 +-- .../Action/Backend/Executor/Executor.swift | 22 +++ .../ActionModule/ModuleEditView.swift | 58 +++++-- .../ModuleTemplate/SourceNode/.eslintrc.js | 1 + .../ModuleTemplate/SourceNode/.gitignore | 6 + .../SourceNode/.supplement/compile.sh | 28 ++++ .../ModuleTemplate/SourceNode/package.json | 17 ++ .../ModuleTemplate/SourceNode/src/global.d.ts | 10 ++ .../ModuleTemplate/SourceNode/src/index.ts | 38 +++++ .../ModuleTemplate/SourceNode/tsconfig.json | 13 ++ .../SourceSwift/.supplement/compile.sh | 9 +- 17 files changed, 353 insertions(+), 40 deletions(-) create mode 100644 App/Action/Action/Backend/Action/ActionModuleTemplates/Template+Node.swift create mode 100644 Resources/ModuleTemplate/SourceNode/.eslintrc.js create mode 100644 Resources/ModuleTemplate/SourceNode/.gitignore create mode 100755 Resources/ModuleTemplate/SourceNode/.supplement/compile.sh create mode 100644 Resources/ModuleTemplate/SourceNode/package.json create mode 100644 Resources/ModuleTemplate/SourceNode/src/global.d.ts create mode 100644 Resources/ModuleTemplate/SourceNode/src/index.ts create mode 100644 Resources/ModuleTemplate/SourceNode/tsconfig.json diff --git a/App/Action/Action.xcodeproj/project.pbxproj b/App/Action/Action.xcodeproj/project.pbxproj index 03ff9c7..c875d32 100644 --- a/App/Action/Action.xcodeproj/project.pbxproj +++ b/App/Action/Action.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 13C6C62128AF1BF0008ADA60 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 13C6C62328AF1BF0008ADA60 /* Localizable.strings */; }; + 1F6BCF0628B219B400C2B417 /* Template+Node.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F6BCF0528B219B400C2B417 /* Template+Node.swift */; }; 5001740128AA557100FF9B99 /* UserDefault.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5001740028AA557100FF9B99 /* UserDefault.swift */; }; 5001740528AA818500FF9B99 /* DiagnosticLogView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5001740428AA818500FF9B99 /* DiagnosticLogView.swift */; }; 5006F55E28A9663100C8ADBE /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5006F55D28A9663100C8ADBE /* Notification.swift */; }; @@ -61,6 +62,7 @@ /* Begin PBXFileReference section */ 13C6C62228AF1BF0008ADA60 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; 13C6C62428AF1DEB008ADA60 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; + 1F6BCF0528B219B400C2B417 /* Template+Node.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Template+Node.swift"; sourceTree = ""; }; 5001740028AA557100FF9B99 /* UserDefault.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefault.swift; sourceTree = ""; }; 5001740428AA818500FF9B99 /* DiagnosticLogView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiagnosticLogView.swift; sourceTree = ""; }; 5006F55D28A9663100C8ADBE /* Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = ""; }; @@ -204,6 +206,7 @@ 505A10A728A95EC200D46DB3 /* ActionManager+Template.swift */, 50A7D80228ACD14B004F0B34 /* Template+Executable.swift */, 5067392528AB786A003A6A9C /* Template+Swift.swift */, + 1F6BCF0528B219B400C2B417 /* Template+Node.swift */, ); path = ActionModuleTemplates; sourceTree = ""; @@ -504,6 +507,7 @@ 502E87A528AA95BF00CAB5E1 /* ModuleElementView.swift in Sources */, 5053CF9A288F9A5E00A92822 /* ModuleCreateView.swift in Sources */, 505A10A828A95EC200D46DB3 /* ActionManager+Template.swift in Sources */, + 1F6BCF0628B219B400C2B417 /* Template+Node.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -664,7 +668,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.0; - MARKETING_VERSION = 1.1; + MARKETING_VERSION = 1.4; PRODUCT_BUNDLE_IDENTIFIER = wiki.qaq.Action; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; @@ -697,7 +701,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.0; - MARKETING_VERSION = 1.1; + MARKETING_VERSION = 1.4; PRODUCT_BUNDLE_IDENTIFIER = wiki.qaq.Action; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; diff --git a/App/Action/Action/Application/License.txt b/App/Action/Action/Application/License.txt index 5b5fe2b..9b3cba2 100644 --- a/App/Action/Action/Application/License.txt +++ b/App/Action/Action/Application/License.txt @@ -122,4 +122,4 @@ SOFTWARE. ========== -Updated: 2022-08-19 +Updated: 2022-08-23 diff --git a/App/Action/Action/Application/zh-Hans.lproj/Localizable.strings b/App/Action/Action/Application/zh-Hans.lproj/Localizable.strings index ba11616..0df3ccf 100644 --- a/App/Action/Action/Application/zh-Hans.lproj/Localizable.strings +++ b/App/Action/Action/Application/zh-Hans.lproj/Localizable.strings @@ -44,6 +44,7 @@ "Edit Action" = "编辑自动化模块"; "Save" = "保存"; "Compiling Source" = "正在编译模块..."; +"Compile Finished" = "编译完成"; "Broken Module" = "损坏的模块"; "Delete" = "删除"; "Close" = "关闭"; diff --git a/App/Action/Action/Backend/Action/ActionManager+Module.swift b/App/Action/Action/Backend/Action/ActionManager+Module.swift index dd2b0c8..d51ed94 100644 --- a/App/Action/Action/Backend/Action/ActionManager+Module.swift +++ b/App/Action/Action/Backend/Action/ActionManager+Module.swift @@ -105,14 +105,14 @@ extension ActionManager { invalidateBinaryCache(forAction: id) } - func issueCompile(forAction actionId: Action.ID) -> Result { + func issueCompile(forAction actionId: Action.ID, output: @escaping (String) -> Void) -> Result { assert(!Thread.isMainThread) guard let action = self[actionId] else { return .failure(.brokenResources) } let result = action.template .obtainTemplateDetails() - .compileModule(id: actionId) { print($0) } + .compileModule(id: actionId, output: output) return result } diff --git a/App/Action/Action/Backend/Action/ActionModuleTemplates/ActionManager+Template.swift b/App/Action/Action/Backend/Action/ActionModuleTemplates/ActionManager+Template.swift index 0aab235..c099d6e 100644 --- a/App/Action/Action/Backend/Action/ActionModuleTemplates/ActionManager+Template.swift +++ b/App/Action/Action/Backend/Action/ActionModuleTemplates/ActionManager+Template.swift @@ -65,12 +65,14 @@ extension ActionManager { case executableSwift case swift + case node func obtainTemplateDetails() -> ModuleTemplate { switch self { case .executable: return ModuleTemplateExecutable() case .executableSwift: return ModuleTemplateExecutableSwift() case .swift: return ModuleTemplateSwift() + case .node: return ModuleTemplateExecutableNode() } } } diff --git a/App/Action/Action/Backend/Action/ActionModuleTemplates/Template+Node.swift b/App/Action/Action/Backend/Action/ActionModuleTemplates/Template+Node.swift new file mode 100644 index 0000000..f70aa5d --- /dev/null +++ b/App/Action/Action/Backend/Action/ActionModuleTemplates/Template+Node.swift @@ -0,0 +1,152 @@ +// +// Template+Node.swift +// Action +// +// Created by Innei on 2022/8/21. +// + +import AuxiliaryExecute +import Foundation + +extension ActionManager { + class ModuleTemplateExecutableNode: ModuleTemplateExecutable { + override func getLanguage() -> String { "Source - Node" } + override func getTemplateBundleName() -> String { "SourceNode" } + override func getBuildHint() -> String { "To build Node Module, node and it's tool is required. Install them yourself." } + + override func openDesignatedEditor(id: ActionManager.Action.ID) -> Result { + let url = ActionManager.shared + .actionModuleBaseUrl + .appendingPathComponent(id.uuidString) + + let recipe = AuxiliaryExecute.spawn( + command: "/bin/zsh", + args: ["-c", "code \(url.path)"] + ) + + guard recipe.exitCode == 0 else { + return .failure(.designatedEditorMissing) + } + + return .success + } + + override func compileModule(id: ActionManager.Action.ID, output: @escaping (String) -> Void) -> Result { + guard let action = ActionManager.shared[id] else { + return .failure(.brokenResources) + } + + let temporaryDir = URL(fileURLWithPath: NSTemporaryDirectory()) + .appendingPathComponent(UUID().uuidString) + try? FileManager.default.removeItem(at: temporaryDir) + defer { + try? FileManager.default.removeItem(at: temporaryDir) + } + + do { + output("[*] starting compiler at \(temporaryDir.path)\n") + try FileManager.default.createDirectory(at: temporaryDir, withIntermediateDirectories: true) + try Executor.shared.unarchiveTar(at: getTemplateBundleURL(), toDest: temporaryDir) + let validatedSourcePathComponents = "src" + let userSrc = ActionManager.shared + .actionModuleBaseUrl + .appendingPathComponent(action.id.uuidString) + .appendingPathComponent(validatedSourcePathComponents) + let targetSrc = temporaryDir + .appendingPathComponent(validatedSourcePathComponents) + output("[*] copying user source from \(userSrc.path) to \(targetSrc.path)\n") + try FileManager.default.removeItem(at: targetSrc) + try FileManager.default.copyItem(at: userSrc, to: targetSrc) + FileManager.default.createFile( + atPath: temporaryDir.appendingPathComponent(".action").path, + contents: nil + ) + } catch { + output("[E] \(error.localizedDescription)") + return .failure(.permissionDenied) + } + + output("[*] calling compiler script\n") + let compileScript = temporaryDir + .appendingPathComponent(".supplement") + .appendingPathComponent("compile.sh") + let recipe = executeZshScript(atLocation: compileScript, output: output) + guard recipe.exitCode == 0 else { + return .failure(.compilerError) + } + + let binaryLocation = temporaryDir + .appendingPathComponent("dist") + .appendingPathComponent("index.js") + guard FileManager.default.fileExists(atPath: binaryLocation.path) else { + return .failure(.permissionDenied) + } + + output("[*] compiled binary at \(binaryLocation.path)\n") + ActionManager.shared.registerBianry(forAction: action.id, binary: binaryLocation) + return .success + } + + override func executeModule(id: ActionManager.Action.ID, withPasteboardEvent event: PasteboardManager.PEvent, output: @escaping (String) -> Void) -> Result { + assert(!Thread.isMainThread) + + guard let action = ActionManager.shared[id] else { + return .failure(.brokenResources) + } + + let script = ActionManager.shared + .actionBinaryBaseUrl + .appendingPathComponent(action.id.uuidString) + + guard let argument = ArgumentData( + focusAppID: event.app?.bundleIdentifier, + focusAppName: event.app?.name, + pasteboardContent: event.content + ) + .compileBase64() + else { + return .failure(.brokenResources) + } + + print("[*] executing action \(id.uuidString)") + + var resultData: ActionRecipeData? + + let recipe = AuxiliaryExecute.spawn( + command: "/bin/zsh", + args: ["-c", "node \(script.path)"], + environment: ["Communicator_Message": argument], + timeout: Double(action.timeout), + output: output + ) + + var lastLine = recipe.stderr + .trimmingCharacters(in: .whitespacesAndNewlines) + .components(separatedBy: "\n") + .last? + .trimmingCharacters(in: .whitespaces) + ?? "" + let prefix = "ActionBee-Result-Recipe://" + if lastLine.hasPrefix(prefix) { + lastLine.removeFirst(prefix.count) + } + if let base64 = Data(base64Encoded: lastLine) { + resultData = ActionRecipeData.retrieve(withData: base64) + } + + guard let result = resultData else { + return .failure(.invalidResponse) + } + + return .success(result) + } + + func executeZshScript(atLocation: URL, output: @escaping (String) -> Void = { _ in }) -> AuxiliaryExecute.ExecuteRecipe { + AuxiliaryExecute.spawn( + command: "/bin/zsh", + args: ["-c", atLocation.path], + output: output + ) + } + } +} diff --git a/App/Action/Action/Backend/Action/ActionModuleTemplates/Template+Swift.swift b/App/Action/Action/Backend/Action/ActionModuleTemplates/Template+Swift.swift index 534df75..c43c953 100644 --- a/App/Action/Action/Backend/Action/ActionModuleTemplates/Template+Swift.swift +++ b/App/Action/Action/Backend/Action/ActionModuleTemplates/Template+Swift.swift @@ -45,7 +45,7 @@ extension ActionManager { } do { - output("[*] starting compiler at \(temporaryDir.path)") + output("[*] starting compiler at \(temporaryDir.path)\n") try FileManager.default.createDirectory(at: temporaryDir, withIntermediateDirectories: true) try Executor.shared.unarchiveTar(at: getTemplateBundleURL(), toDest: temporaryDir) let validatedSourcePathComponents = "Source" @@ -55,13 +55,7 @@ extension ActionManager { .appendingPathComponent(validatedSourcePathComponents) let targetSrc = temporaryDir .appendingPathComponent(validatedSourcePathComponents) - output( - """ - [*] copying user source - from \(userSrc.path) - to \(targetSrc.path) - """ - ) + output("[*] copying user source from \(userSrc.path) to \(targetSrc.path)\n") try FileManager.default.removeItem(at: targetSrc) try FileManager.default.copyItem(at: userSrc, to: targetSrc) FileManager.default.createFile( @@ -69,15 +63,15 @@ extension ActionManager { contents: nil ) } catch { - print("[E] \(error.localizedDescription)") + output("[E] \(error.localizedDescription)") return .failure(.permissionDenied) } - output("[*] calling compiler script") + output("[*] calling compiler script\n") let compileScript = temporaryDir .appendingPathComponent(".supplement") .appendingPathComponent("compile.sh") - let recipe = executeBashScript(atLocation: compileScript, output: output) + let recipe = executeZshScript(atLocation: compileScript, output: output) guard recipe.exitCode == 0 else { return .failure(.compilerError) } @@ -89,14 +83,14 @@ extension ActionManager { return .failure(.permissionDenied) } - output("[*] compiled binary at \(binaryLocation.path)") + output("[*] compiled binary at \(binaryLocation.path)\n") ActionManager.shared.registerBianry(forAction: action.id, binary: binaryLocation) return .success } - func executeBashScript(atLocation: URL, output: @escaping (String) -> Void = { _ in }) -> AuxiliaryExecute.ExecuteRecipe { + func executeZshScript(atLocation: URL, output: @escaping (String) -> Void = { _ in }) -> AuxiliaryExecute.ExecuteRecipe { AuxiliaryExecute.spawn( - command: "/bin/bash", + command: "/bin/zsh", args: ["-c", atLocation.path], output: output ) diff --git a/App/Action/Action/Backend/Executor/Executor.swift b/App/Action/Action/Backend/Executor/Executor.swift index c07ce70..bcee64e 100644 --- a/App/Action/Action/Backend/Executor/Executor.swift +++ b/App/Action/Action/Backend/Executor/Executor.swift @@ -24,6 +24,28 @@ final class Executor { } print("[*] whoami \(username)") + do { + let findEnv = AuxiliaryExecute.spawn( + command: "/bin/zsh", + args: ["-c", "source ~/.zshrc 1>/dev/null 2>/dev/null && echo $PATH"] + ) + let env = findEnv.stdout.trimmingCharacters(in: .whitespacesAndNewlines) + print("[*] setting up env PATH value \(findEnv.stdout)") + let envPathBuilder = env.components(separatedBy: ":") + .filter { FileManager.default.fileExists(atPath: $0) } + let origPathBuilder = ( + ProcessInfo + .processInfo + .environment["PATH"] ?? "" + ) + .components(separatedBy: ":") + .filter { FileManager.default.fileExists(atPath: $0) } + let newPath = Array(Set(envPathBuilder + origPathBuilder)) + .joined(separator: ":") + + setenv("PATH", newPath, 1) + } + try? FileManager.default.createDirectory(at: executorDir, withIntermediateDirectories: true) } diff --git a/App/Action/Action/Interface/ActionModule/ModuleEditView.swift b/App/Action/Action/Interface/ActionModule/ModuleEditView.swift index c2183c3..a0eee43 100644 --- a/App/Action/Action/Interface/ActionModule/ModuleEditView.swift +++ b/App/Action/Action/Interface/ActionModule/ModuleEditView.swift @@ -20,6 +20,9 @@ struct ModuleEditView: View { @State var openCompileView: Bool = false @State var hoverApplication: String? = nil + @State var compileLog: String = "" + @State var compilerFinished: Bool = false + var body: some View { VStack(alignment: .leading, spacing: 8) { if editingAction == nil { @@ -62,24 +65,43 @@ struct ModuleEditView: View { actionEnabled = ActionManager.shared.enabledActions.contains(id) } .opacity(openCompileView ? 0 : 1) - .overlay( - VStack(alignment: .leading) { - ProgressView() - Divider().hidden() - Spacer().frame(height: 20) - Text("Compiling Source") - .font(.headline) - Spacer().frame(height: 6) - RandomCodeTextView() - } - .opacity(openCompileView ? 1 : 0) - .padding() - ) + .overlay(compileOverlay) .padding() - .animation(.interactiveSpring(), value: openCompileView) .frame(width: 500, alignment: .center) } + var compileOverlay: some View { + VStack(alignment: .leading) { + if !compilerFinished { ProgressView().padding(.top, 20) } + Spacer().frame(height: 20) + Text(compilerFinished ? "Compile Finished" : "Compiling Source") + .font(.headline) + Spacer().frame(height: 6) + if !compilerFinished { RandomCodeTextView() } + Divider() + ScrollView(.vertical, showsIndicators: true) { + VStack(alignment: .leading, spacing: 4) { + ForEach(Array( + compileLog + .components(separatedBy: "\n") + .reversed() + .enumerated() + ), id: \.offset) { _, log in + Text(log).textSelection(.enabled) + } + .font(.system(.footnote, design: .monospaced)) + .opacity(0.5) + } + } + Button("Cancel") { + compileLog = "" + openCompileView = false + } + .opacity(compilerFinished ? 1 : 0) + } + .opacity(openCompileView ? 1 : 0) + } + var brokenModule: some View { VStack { Image(systemName: "xmark.seal.fill") @@ -280,6 +302,7 @@ struct ModuleEditView: View { ActionManager.shared[id] = action presentationMode.wrappedValue.dismiss() case let .failure(failure): + compilerFinished = true let alert = NSAlert() alert.alertStyle = .critical alert.messageText = "Unable to compile this action: \(failure.message)" @@ -401,9 +424,12 @@ struct ModuleEditView: View { return } DispatchQueue.global().async { - let result = ActionManager.shared.issueCompile(forAction: action.id) + let result = ActionManager.shared.issueCompile(forAction: action.id) { str in + DispatchQueue.withMainAndWait { + compileLog.append(str) + } + } DispatchQueue.main.async { - openCompileView = false completion(result) } } diff --git a/Resources/ModuleTemplate/SourceNode/.eslintrc.js b/Resources/ModuleTemplate/SourceNode/.eslintrc.js new file mode 100644 index 0000000..cbf1554 --- /dev/null +++ b/Resources/ModuleTemplate/SourceNode/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('@innei/eslint-config-ts') diff --git a/Resources/ModuleTemplate/SourceNode/.gitignore b/Resources/ModuleTemplate/SourceNode/.gitignore new file mode 100644 index 0000000..03fbe73 --- /dev/null +++ b/Resources/ModuleTemplate/SourceNode/.gitignore @@ -0,0 +1,6 @@ +node_modules +pnpm-lock.yaml +dist +yarn.lock +package-lock.json +.DS_Store diff --git a/Resources/ModuleTemplate/SourceNode/.supplement/compile.sh b/Resources/ModuleTemplate/SourceNode/.supplement/compile.sh new file mode 100755 index 0000000..cb0d309 --- /dev/null +++ b/Resources/ModuleTemplate/SourceNode/.supplement/compile.sh @@ -0,0 +1,28 @@ +#!/bin/zsh + +# this compiler script is designed to issue result to ./dist/index.js + +set -e + +cd "$(dirname "$0")"/../ + +echo "[*] starting build at $(pwd)..." + +if [ ! -f .action ]; then + echo "[E] malformed project architecture" + exit 1 +fi + +echo "[*] cleaning build..." + +rm -rf dist || true + +echo "[*] install dependencies..." + +npm i + +echo "[*] compile..." + +npm run build + +echo "[+] completed compile" diff --git a/Resources/ModuleTemplate/SourceNode/package.json b/Resources/ModuleTemplate/SourceNode/package.json new file mode 100644 index 0000000..2ce37b3 --- /dev/null +++ b/Resources/ModuleTemplate/SourceNode/package.json @@ -0,0 +1,17 @@ +{ + "name": "action.bee.source.module.src", + "version": "0.0.0", + "description": "ActionBee Module Source Using Node", + "main": "./dist/index.js", + "scripts": { + "build": "ncc build src/index.ts -o dist" + }, + "keywords": [], + "author": "Innei", + "license": "MIT", + "devDependencies": { + "@types/node": "18.7.8", + "@vercel/ncc": "0.34.0", + "typescript": "4.7.4" + } +} \ No newline at end of file diff --git a/Resources/ModuleTemplate/SourceNode/src/global.d.ts b/Resources/ModuleTemplate/SourceNode/src/global.d.ts new file mode 100644 index 0000000..1f709ae --- /dev/null +++ b/Resources/ModuleTemplate/SourceNode/src/global.d.ts @@ -0,0 +1,10 @@ +declare global { + export interface ActionBeeMessageEvent { + focusAppID?: string + focusAppName?: string + pasteboardContent: string + } + + export type ActionBeeAction = 'none' | 'overwrite' | 'speak' +} +export {} diff --git a/Resources/ModuleTemplate/SourceNode/src/index.ts b/Resources/ModuleTemplate/SourceNode/src/index.ts new file mode 100644 index 0000000..565bd5b --- /dev/null +++ b/Resources/ModuleTemplate/SourceNode/src/index.ts @@ -0,0 +1,38 @@ +// ActionBee - Node Module Template + +// ⚠️ please put compiled your src into ./dist/index.js + +function finalizeResult( + action: ActionBeeAction, + content: string, + continueQueue: boolean, +) { + const result = { + postAction: action, // none, overwrite, speak + postContent: content, // your content to post + continueQueue, + } + const base64 = Buffer.from(JSON.stringify(result)).toString('base64') + process.stderr.write(`\nActionBee-Result-Recipe://${base64}`) + process.exit(0) +} + +function moduleMain() { + const messageFromEnv = process.env['Communicator_Message'] + + if (!messageFromEnv) { + process.stderr.write('ActionBee-Error: No message found') + return + } + + const toString = Buffer.from(messageFromEnv, 'base64').toString() + const event: ActionBeeMessageEvent = JSON.parse(toString) + + console.log(event.focusAppID) // optional + console.log(event.focusAppName) // optional + console.log(event.pasteboardContent) // string + + finalizeResult('overwrite', 'Hello World', false) +} + +moduleMain() diff --git a/Resources/ModuleTemplate/SourceNode/tsconfig.json b/Resources/ModuleTemplate/SourceNode/tsconfig.json new file mode 100644 index 0000000..7bebf49 --- /dev/null +++ b/Resources/ModuleTemplate/SourceNode/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "ES2017", + "module": "CommonJS", + "declaration": false, + "allowJs": true, + "allowSyntheticDefaultImports": true, + "baseUrl": "./src", + "resolveJsonModule": true, + "strict": true, + "esModuleInterop": true + } +} \ No newline at end of file diff --git a/Resources/ModuleTemplate/SourceSwift/.supplement/compile.sh b/Resources/ModuleTemplate/SourceSwift/.supplement/compile.sh index 0d1f9a7..a9ef3eb 100755 --- a/Resources/ModuleTemplate/SourceSwift/.supplement/compile.sh +++ b/Resources/ModuleTemplate/SourceSwift/.supplement/compile.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/zsh # this compiler script is designed to issue binary to ./.build/cli @@ -9,6 +9,7 @@ cd "$(dirname "$0")"/../ echo "[*] starting build at $(pwd)..." if [ ! -f .action ]; then + echo "[E] malformed project architecture" exit 1 fi @@ -26,8 +27,7 @@ BUILT_PRODUCTS_DIR=$( -workspace ./App.xcworkspace \ -scheme CommandLineBridge \ -showBuildSettings \ - CODE_SIGNING_ALLOWED="NO" \ - 2>/dev/null | grep -m 1 "BUILT_PRODUCTS_DIR" | grep -oEi "\/.*" + CODE_SIGNING_ALLOWED="NO" | grep -m 1 "BUILT_PRODUCTS_DIR" | grep -oEi "\/.*" ) BINARY_LOCATION="$BUILT_PRODUCTS_DIR/CommandLineBridge" @@ -42,8 +42,7 @@ xcodebuild \ -configuration Release \ -workspace ./App.xcworkspace \ -scheme CommandLineBridge \ - CODE_SIGNING_ALLOWED="NO" \ - 1>/dev/null 2>/dev/null + CODE_SIGNING_ALLOWED="NO" # check if the binary exists if [ ! -f "$BINARY_LOCATION" ]; then