Skip to content

Commit

Permalink
chore: add utils pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciNyan committed Aug 18, 2024
1 parent ef56c2f commit cc26ca8
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 110 deletions.
2 changes: 1 addition & 1 deletion action/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { parseOutputs } from './parseOutputs'
import { parseArray, parseBoolean, parseString } from './utils'
import * as core from '@actions/core'
import * as fs from 'fs'
import * as path from 'path'
import { fetchStats, renderStats } from 'pixel-profile'
import { parseArray, parseBoolean, parseString } from 'pixel-profile-utils'

async function main() {
try {
Expand Down
4 changes: 2 additions & 2 deletions action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"dependencies": {
"@actions/core": "1.10.1",
"@resvg/resvg-js-linux-x64-gnu": "2.6.0",
"ts-known": "^0.1.3",
"pixel-profile": "workspace:*"
"pixel-profile": "workspace:*",
"pixel-profile-utils": "workspace:*"
},
"devDependencies": {
"@vercel/ncc": "0.38.0",
Expand Down
79 changes: 0 additions & 79 deletions action/utils.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/pixel-profile-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"dotenv": "^16.3.1",
"hono": "^4.0.8",
"pixel-profile": "workspace:*",
"pixel-profile-utils": "workspace:*",
"ts-known": "^0.1.3"
},
"packageManager": "pnpm@9.7.0",
Expand Down
29 changes: 1 addition & 28 deletions packages/pixel-profile-server/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isString, objectOf, optional } from 'ts-known'
export { parseArray, parseBoolean, parseString } from 'pixel-profile-utils'

export const hasMessage = objectOf({
message: isString
Expand Down Expand Up @@ -49,31 +50,3 @@ export function dateDiff(d1: number | string | Date, d2: number | string | Date)

return Math.round(diff / (1000 * 60))
}

export function parseArray(str: string | string[]): string[] {
if (Array.isArray(str)) {
return []
}

if (!str) {
return []
}

return str.split(',')
}

export function parseBoolean(value: string | string[]): boolean | undefined {
if (!isString(value)) {
return undefined
}

if (value.toLowerCase() === 'true') {
return true
} else if (value.toLowerCase() === 'false') {
return false
}
}

export function parseString(value: string | string[]): string | undefined {
return isString(value) ? value : undefined
}
43 changes: 43 additions & 0 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "pixel-profile-utils",
"version": "0.1.0",
"homepage": "https://github.com/LuciNyan/pixel-profile",
"bugs": {
"url": "https://github.com/LuciNyan/pixel-profile/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/LuciNyan/pixel-profile.git"
},
"module": "./dist/index.js",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"dev": "cross-env NODE_ENV=development tsup src/index.ts --watch",
"build": "tsup",
"test-type": "tsc --noEmit"
},
"type": "module",
"author": "LuciNyan",
"license": "MIT",
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.js"
}
},
"devDependencies": {
"tsup": "^8.0.2"
},
"dependencies": {
"ts-known": "^0.1.3"
},
"lint-staged": {
"*.{js,css,md}": "prettier --write",
"*.{ts,tsx}": "eslint --fix"
},
"packageManager": "pnpm@9.7.0",
"engines": {
"node": ">=18.17.0"
}
}
1 change: 1 addition & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { parseArray, parseBoolean, parseString } from './params'
29 changes: 29 additions & 0 deletions packages/utils/src/params.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { isString } from 'ts-known'

export function parseArray(str: string | string[] | undefined): string[] {
if (Array.isArray(str)) {
return str
}

if (!str) {
return []
}

return str.split(',')
}

export function parseBoolean(value: string | string[] | undefined): boolean | undefined {
if (!isString(value)) {
return undefined
}

if (value.toLowerCase() === 'true') {
return true
} else if (value.toLowerCase() === 'false') {
return false
}
}

export function parseString(value: string | string[] | undefined): string | undefined {
return isString(value) ? value : undefined
}
14 changes: 14 additions & 0 deletions packages/utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"strict": true,
},
"include": [
"src"
],
"exclude": ["node_modules"]
}
15 changes: 15 additions & 0 deletions packages/utils/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig } from 'tsup'

export default defineConfig({
entry: ['src/index.ts'],
splitting: false,
sourcemap: false,
target: 'node16',
dts: true,
minify: process.env.NODE_ENV !== 'development',
format: ['esm'],
esbuildOptions(options) {
options.tsconfig = 'tsconfig.json'
options.legalComments = 'external'
}
})
66 changes: 66 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cc26ca8

Please sign in to comment.