Compare commits

..

No commits in common. "6ba7fb15553b1beadda7d4a9954ea796ceca6d57" and "7e0b4c7b732324a60a58536d33b0bfdf88fcb260" have entirely different histories.

15 changed files with 92 additions and 66 deletions

View file

@ -1,2 +0,0 @@
.git/
node_modules/

View file

@ -1,6 +0,0 @@
FROM node:20
WORKDIR /root/kot
ADD . .
RUN npm install
RUN npm install -g
ENTRYPOINT ["kot"]

View file

@ -26,7 +26,7 @@ $ kot checkout
From the same directory as this README: From the same directory as this README:
```sh-session ```sh-session
$ npm install -g $ npm run setup
``` ```
Now the `kot` command should be available on your system. Now the `kot` command should be available on your system.

View file

@ -3,10 +3,13 @@
const oclif = require('@oclif/core') const oclif = require('@oclif/core')
const path = require('path') const path = require('path')
const project = path.join(__dirname, '..', 'tsconfig.json')
// In dev mode -> use ts-node and dev plugins // In dev mode -> use ts-node and dev plugins
process.env.NODE_ENV = 'development' process.env.NODE_ENV = 'development'
require('ts-node').register({project})
// In dev mode, always show stack traces // In dev mode, always show stack traces
oclif.settings.debug = true; oclif.settings.debug = true;

View file

@ -12,6 +12,7 @@
"repository": "https://git.adamu.jp/adam/kingoftime-cli", "repository": "https://git.adamu.jp/adam/kingoftime-cli",
"files": [ "files": [
"/bin", "/bin",
"/dist",
"/npm-shrinkwrap.json", "/npm-shrinkwrap.json",
"/oclif.manifest.json" "/oclif.manifest.json"
], ],
@ -22,27 +23,37 @@
}, },
"devDependencies": { "devDependencies": {
"@oclif/test": "^2.3.14", "@oclif/test": "^2.3.14",
"@types/chai": "^4",
"@types/mocha": "^9.0.0",
"@types/node": "^16.18.23",
"chai": "^4", "chai": "^4",
"eslint": "^7.32.0", "eslint": "^7.32.0",
"eslint-config-oclif": "^4", "eslint-config-oclif": "^4",
"eslint-config-oclif-typescript": "^1.0.3",
"mocha": "^9", "mocha": "^9",
"oclif": "^3.8.0" "oclif": "^3.8.0",
"shx": "^0.3.3",
"ts-node": "^10.9.1",
"tslib": "^2.5.0",
"typescript": "^4.9.5"
}, },
"oclif": { "oclif": {
"bin": "kot", "bin": "kot",
"dirname": "kot", "dirname": "kot",
"commands": "./src/commands", "commands": "./dist/commands",
"plugins": [ "plugins": [
"@oclif/plugin-help" "@oclif/plugin-help"
] ]
}, },
"scripts": { "scripts": {
"lint": "eslint . --ext .js --config .eslintrc", "build": "shx rm -rf dist && tsc -b",
"lint": "eslint . --ext .ts --config .eslintrc",
"postpack": "shx rm -f oclif.manifest.json", "postpack": "shx rm -f oclif.manifest.json",
"posttest": "npm run lint", "posttest": "npm run lint",
"prepack": "oclif manifest && oclif readme", "prepack": "npm run build && oclif manifest && oclif readme",
"test": "mocha --forbid-only \"test/**/*.test.js\"", "test": "mocha --forbid-only \"test/**/*.test.ts\"",
"version": "oclif readme && git add README.md" "version": "oclif readme && git add README.md",
"setup": "npm install && npm run build && npm link"
}, },
"engines": { "engines": {
"node": ">=12.0.0" "node": ">=12.0.0"
@ -50,5 +61,6 @@
"bugs": "https://git.adamu.jp/adam/kingoftime-cli/issues", "bugs": "https://git.adamu.jp/adam/kingoftime-cli/issues",
"keywords": [ "keywords": [
"oclif" "oclif"
] ],
"types": "dist/index.d.ts"
} }

View file

@ -1,20 +0,0 @@
const {Command} = require('@oclif/core')
const {tokenFlags} = require('../tokenFlags')
const {checkin} = require('../kingoftime')
class CheckinCommand extends Command {
static description = 'Check in'
static examples = [
'<%= config.bin %> <%= command.id %>',
]
static flags = tokenFlags
async run() {
const {flags} = await this.parse(CheckinCommand)
await checkin(flags.token, flags['user-token'])
}
}
module.exports = CheckinCommand

16
src/commands/checkin.ts Normal file
View file

@ -0,0 +1,16 @@
import {Command} from '@oclif/core'
import {tokenFlags} from '../token-flags'
import {checkin} from '../kingoftime'
export default class Checkout extends Command {
static description = 'Check in';
static examples = ['<%= config.bin %> <%= command.id %>'];
static flags = tokenFlags;
public async run(): Promise<void> {
const {flags} = await this.parse(Checkout)
await checkin(flags.token, flags['user-token'])
}
}

View file

@ -1,20 +0,0 @@
const {Command} = require('@oclif/core')
const {tokenFlags} = require('../tokenFlags')
const {checkout} = require('../kingoftime')
class CheckoutCommand extends Command {
static description = 'Check out'
static examples = [
'<%= config.bin %> <%= command.id %>',
]
static flags = tokenFlags
async run() {
const {flags} = await this.parse(CheckoutCommand)
await checkout(flags.token, flags['user-token'])
}
}
module.exports = CheckoutCommand

16
src/commands/checkout.ts Normal file
View file

@ -0,0 +1,16 @@
import {Command} from '@oclif/core'
import {tokenFlags} from '../token-flags'
import {checkout} from '../kingoftime'
export default class Checkout extends Command {
static description = 'Check out';
static examples = ['<%= config.bin %> <%= command.id %>'];
static flags = tokenFlags;
public async run(): Promise<void> {
const {flags} = await this.parse(Checkout)
await checkout(flags.token, flags['user-token'])
}
}

View file

@ -1,9 +1,13 @@
const axios = require('axios') import axios from 'axios'
const CHECK_IN_ID = 'qmXXCxw9WEWN3X/YrkMWuQ==' const CHECK_IN_ID = 'qmXXCxw9WEWN3X/YrkMWuQ=='
const CHECK_OUT_ID = 'j8ekmJaw6W3M4w3i6hlSIQ==' const CHECK_OUT_ID = 'j8ekmJaw6W3M4w3i6hlSIQ=='
async function kingoftime(operationId, token, userToken) { async function kingoftime(
operationId: string,
token: string,
userToken: string,
) {
const response = await axios({ const response = await axios({
method: 'post', method: 'post',
url: 'https://s2.ta.kingoftime.jp/gateway/bprgateway', url: 'https://s2.ta.kingoftime.jp/gateway/bprgateway',
@ -22,12 +26,13 @@ async function kingoftime(operationId, token, userToken) {
console.log(response.data) console.log(response.data)
} }
async function checkin(token, userToken) { export async function checkin(token: string, userToken: string): Promise<void> {
await kingoftime(CHECK_IN_ID, token, userToken) await kingoftime(CHECK_IN_ID, token, userToken)
} }
async function checkout(token, userToken) { export async function checkout(
token: string,
userToken: string,
): Promise<void> {
await kingoftime(CHECK_OUT_ID, token, userToken) await kingoftime(CHECK_OUT_ID, token, userToken)
} }
module.exports = {checkin, checkout}

View file

@ -1,9 +1,9 @@
const {Flags} = require('@oclif/core') import {Flags} from '@oclif/core'
const tokenVar = 'KINGOFTIME_TOKEN' const tokenVar = 'KINGOFTIME_TOKEN'
const userTokenVar = 'KINGOFTIME_USER_TOKEN' const userTokenVar = 'KINGOFTIME_USER_TOKEN'
const tokenFlags = { export const tokenFlags = {
token: Flags.string({ token: Flags.string({
env: tokenVar, env: tokenVar,
description: `Defaults to the ${tokenVar} environment variable.`, description: `Defaults to the ${tokenVar} environment variable.`,
@ -15,5 +15,3 @@ const tokenFlags = {
required: true, required: true,
}), }),
} }
module.exports = {tokenFlags}

View file

@ -1,4 +1,5 @@
const path = require('path') const path = require('path')
process.env.TS_NODE_PROJECT = path.resolve('test/tsconfig.json')
process.env.NODE_ENV = 'development' process.env.NODE_ENV = 'development'
global.oclif = global.oclif || {} global.oclif = global.oclif || {}

9
test/tsconfig.json Normal file
View file

@ -0,0 +1,9 @@
{
"extends": "../tsconfig",
"compilerOptions": {
"noEmit": true
},
"references": [
{"path": ".."}
]
}

14
tsconfig.json Normal file
View file

@ -0,0 +1,14 @@
{
"compilerOptions": {
"declaration": true,
"importHelpers": true,
"module": "commonjs",
"outDir": "dist",
"rootDir": "src",
"strict": true,
"target": "es2019"
},
"include": [
"src/**/*"
]
}