-
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.
- Loading branch information
1 parent
8828a49
commit ab24432
Showing
12 changed files
with
149 additions
and
8 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
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
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
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
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
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,9 @@ | ||
import { Command } from "commander"; | ||
import { makeSetCommand } from "./set.js"; | ||
|
||
export const installConfigCommands = (program: Command) => { | ||
const config = program.command("config"); | ||
config.description("Configure common settings"); | ||
|
||
config.addCommand(makeSetCommand()); | ||
}; |
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,26 @@ | ||
import { Command } from "commander"; | ||
import { setLiffBaseUrl, setLineBaseUrl } from "../stores/common.js"; | ||
|
||
const setAction = async (key: string, value: string) => { | ||
switch (key) { | ||
case "baseUrl.line": | ||
setLineBaseUrl(value); | ||
break; | ||
case "baseUrl.liff": | ||
setLiffBaseUrl(value); | ||
break; | ||
default: | ||
throw new Error(`Unknown key: ${key}`); | ||
} | ||
}; | ||
|
||
export const makeSetCommand = () => { | ||
const set = new Command("set"); | ||
set | ||
.description("Set configuration") | ||
.argument("<key>", "The key to set") | ||
.argument("<value>", "The value to set") | ||
.action(setAction); | ||
|
||
return set; | ||
}; |
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,17 @@ | ||
import { store } from "./index.js"; | ||
|
||
export const getLineBaseUrl = (): string => { | ||
return store.get("common.baseUrl.line") ?? "https://api.line.me"; | ||
}; | ||
|
||
export const setLineBaseUrl = (url: string) => { | ||
store.set("common.baseUrl.line", url); | ||
}; | ||
|
||
export const getLiffBaseUrl = (): string => { | ||
return store.get("common.baseUrl.liff") ?? "https://liff.line.me"; | ||
}; | ||
|
||
export const setLiffBaseUrl = (url: string) => { | ||
store.set("common.baseUrl.liff", 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,74 @@ | ||
import Conf from "conf"; | ||
import { promises as fs } from "fs"; | ||
|
||
const packageJson = JSON.parse( | ||
await fs.readFile(new URL("../../../package.json", import.meta.url), "utf8"), | ||
); | ||
|
||
export interface RootConfig { | ||
currentChannelId?: string; | ||
channels?: { | ||
[channelId: string]: { | ||
secret: string; | ||
accessToken: string; | ||
expiresIn: number; | ||
issuedAt: number; | ||
}; | ||
}; | ||
common?: { | ||
baseUrl?: { | ||
liff: string; | ||
line: string; | ||
}; | ||
}; | ||
} | ||
|
||
export const store = new Conf<RootConfig>({ | ||
projectName: packageJson.name, | ||
projectVersion: packageJson.version, | ||
schema: { | ||
currentChannelId: { | ||
type: "string", | ||
}, | ||
channels: { | ||
type: "object", | ||
properties: { | ||
secret: { | ||
type: "string", | ||
description: "The secret for the channel", | ||
}, | ||
accessToken: { | ||
type: "string", | ||
description: "The access token for the channel", | ||
}, | ||
expiresIn: { | ||
type: "number", | ||
description: "The number of seconds the access token is valid for", | ||
}, | ||
issuedAt: { | ||
type: "number", | ||
description: | ||
"The milliseconds timestamp when the access token was issued", | ||
}, | ||
}, | ||
}, | ||
common: { | ||
type: "object", | ||
properties: { | ||
baseUrl: { | ||
type: "object", | ||
properties: { | ||
liff: { | ||
type: "string", | ||
description: "The base URL for LIFF Application", | ||
}, | ||
line: { | ||
type: "string", | ||
description: "The base URL for LINE API", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); |
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
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
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