Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
version 0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Dec 14, 2022
1 parent 5a25fe8 commit 1fa905e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module and using it inside `DefineFunction` initialization code:
```typescript
import { DefineFunction, Schema, SlackFunction } from "deno-slack-sdk/mod.ts";
// ADD THIS
import { FunctionSourceFile } from "https://deno.land/x/deno_slack_source_file_resolver@0.1.2/mod.ts";
import { FunctionSourceFile } from "https://deno.land/x/deno_slack_source_file_resolver@0.1.3/mod.ts";

export const GreetingFunctionDefinition = DefineFunction({
callback_id: "greeting_function",
Expand All @@ -25,7 +25,9 @@ export const GreetingFunctionDefinition = DefineFunction({
});
```

Please note that, when you use this module, **`deno test` command needs to be `deno test --allow-read` instead**. As for running your app by `slack run` and your deployed apps, no extra configuration is requied.
Please note that, when you use this module, **`deno test` command needs to be
`deno test --allow-read` instead**. As for running your app by `slack run` and
your deployed apps, no extra configuration is requied.

### LICENSE

Expand Down
17 changes: 13 additions & 4 deletions function_source_file.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export const FunctionSourceFile = function (
// Pass the value of import.meta.url in a function code
importMetaUrl: string,
): string {
/**
* Automatically resolves the `source_file` part for `DefineFunction()` in your Slack's next-generation platform app.
*
* @param importMetaUrl the value of `import.meta.url` in a function code
* @returns the relative path from the root directory of your app project
*/
export const FunctionSourceFile = function (importMetaUrl: string): string {
let dirToFindManifestTs = toFilepath(importMetaUrl);
while (dirToFindManifestTs !== "") {
const elems = dirToFindManifestTs.split("/");
Expand All @@ -19,6 +22,12 @@ export const FunctionSourceFile = function (
throw new Error(`Failed to resolve source_file path for ${importMetaUrl}`);
};

/**
* Trims the unnecesary parts from import.meta.url to make it valid as a file path.
*
* @param url `import.meta.url` string value
* @returns valid file path
*/
function toFilepath(url: string) {
return url.replace("file://", "");
}

0 comments on commit 1fa905e

Please sign in to comment.