Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrttn committed Nov 28, 2023
1 parent dfb666c commit 52416cd
Show file tree
Hide file tree
Showing 28 changed files with 128 additions and 118 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
"@babel/eslint-parser": "^7.18.9",
"@babel/eslint-plugin": "^7.18.10",
"@sucrase/jest-plugin": "^2.2.1",
"@types/inflection": "^1.13.1",
"@types/inflection": "^1.13.2",
"@types/jest": "^29.0.0",
"@types/node": "^18.7.14",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"@types/node": "^18.18.13",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"eslint": "^8.23.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-transloadit": "^2.0.0",
Expand All @@ -58,6 +58,6 @@
"prettier": "^2.8.6",
"replace-require-with-import": "^2.1.0",
"sucrase": "^3.25.0",
"typescript": "^4.8.2"
"typescript": "^5.3.2"
}
}
2 changes: 1 addition & 1 deletion packages/abbr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"directory": "packages/abbr"
},
"main": "dist/abbr.js",
"typings": "dist/abbr.d.ts",
"types": "dist/abbr.d.ts",
"files": [
"dist"
],
Expand Down
6 changes: 3 additions & 3 deletions packages/analyze-step/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"directory": "packages/analyze-step"
},
"main": "dist/analyzeStep.js",
"typings": "dist/analyzeStep.d.ts",
"types": "dist/analyzeStep.d.ts",
"files": [
"dist"
],
Expand All @@ -32,7 +32,7 @@
"version": "0.1.3",
"gitHead": "b73ab4880b9c4c48db32f249f776974a137510c4",
"devDependencies": {
"@types/jsonpath": "^0.2.0",
"@types/lodash": "^4"
"@types/jsonpath": "^0.2.4",
"@types/lodash": "^4.14.202"
}
}
34 changes: 19 additions & 15 deletions packages/analyze-step/src/analyzeStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function humanJoin(array: string[], reduce = true, glueword = 'and'): string {
}
}

if (countedArray.length === 1) {
if (countedArray.length === 1 && typeof countedArray[0] === 'string') {
return countedArray[0]
}

Expand Down Expand Up @@ -67,9 +67,9 @@ function humanFilter(step: FileFilterStep): string {
for (const type of types) {
collection[type] = collection[type] || []
if (typeof step[type] === 'string') {
collection[type].push(`Filter by code evaluation`)
collection[type]?.push(`Filter by code evaluation`)
} else if (step[type] && Array.isArray(step[type])) {
for (const [key, operator, val] of Object.values(step[type])) {
for (const [key, operator, val] of Object.values(step[type]!)) {
const template = clone(templates[operator])
if (!template) {
throw new Error(
Expand Down Expand Up @@ -145,7 +145,7 @@ function humanFilter(step: FileFilterStep): string {
humanDescr = humanDescr.replace('wi2th', 'with')
}

collection[type].push(humanDescr)
collection[type]?.push(humanDescr)
lastTemplate = template
}
}
Expand Down Expand Up @@ -211,11 +211,11 @@ function humanDimensions(step: StepWithDimensions): string {

if ('width' in step && 'height' in step) {
str += ` to ${step.width}×${step.height}`
} else if ('width' in step) {
} else if (step.width) {
str += ` to ${step.width} pixels wide`
} else if ('height' in step) {
} else if (step.height) {
str += ` to ${step.height} pixels high`
} else if ('crop' in step) {
} else if (step.crop) {
str += ` to ${step.crop.x2 - step.crop.x1}×${step.crop.y2 - step.crop.y1} starting at ${
step.crop.x1
}×${step.crop.y1} from the top left`
Expand All @@ -233,6 +233,8 @@ type ExtraMeta = {
}

function humanPreset(step: PresetStep, extrameta: ExtraMeta = {}): string {
if (!step.preset) return ''

let str = inflect.humanize(step.preset.replace(/[-_]/g, ' '))

if (str.match(/^ipad/i)) {
Expand Down Expand Up @@ -278,6 +280,8 @@ type FormatStep = {
}

function humanFormat(step: FormatStep): string {
if (!step.format) return ''

let str = inflect.humanize(step.format.replace(/[-_]/g, ' '))

if (str.match(/^webp/i)) {
Expand Down Expand Up @@ -309,9 +313,9 @@ export default function humanize(step: Step, robots: Robots, extrameta: ExtraMet
let str = ``

const robot = robots[step.robot]
str = robot.purpose_words
str = robot?.purpose_words ?? ''

if (robot.rname === '/video/encode') {
if (robot?.rname === '/video/encode') {
if (JSON.stringify(step).match(/watermark/)) {
str = `Watermark videos`
} else if (get(step, 'ffmpeg.t') && get(step, 'ffmpeg.ss')) {
Expand Down Expand Up @@ -358,7 +362,7 @@ export default function humanize(step: Step, robots: Robots, extrameta: ExtraMet
}
}

if (robot.rname === '/audio/encode') {
if (robot?.rname === '/audio/encode') {
if (has(step, 'ffmpeg.ss') && has(step, 'ffmpeg.t')) {
str = `Take a ${get(step, 'ffmpeg.t')}s clip out of audio at a specified offset`
} else if (
Expand All @@ -382,15 +386,15 @@ export default function humanize(step: Step, robots: Robots, extrameta: ExtraMet
}
}

if (robot.rname === '/video/adaptive') {
if (robot?.rname === '/video/adaptive') {
if (step.technique === 'hls') {
str = `Convert videos to HLS`
} else if (step.technique === 'dash') {
str = `Convert videos to MPEG-Dash`
}
}

if (robot.rname === '/video/merge') {
if (robot?.rname === '/video/merge') {
const types = JSONPath({ path: '$..as', json: step })
if (types.length) {
str = `Merge ${humanJoin(types)} to create a new video`
Expand All @@ -399,19 +403,19 @@ export default function humanize(step: Step, robots: Robots, extrameta: ExtraMet
}
}

if (robot.rname === '/file/filter') {
if (robot?.rname === '/file/filter') {
str = humanFilter(step as FileFilterStep)
}

if (robot.rname === '/audio/artwork') {
if (robot?.rname === '/audio/artwork') {
if (get(step, 'method') === 'insert') {
str = `Insert audio artwork`
} else {
str = `Extract audio artwork`
}
}

if (robot.rname === '/image/resize') {
if (robot?.rname === '/image/resize') {
if ('watermark_url' in step) {
str = `Watermark images`
} else if ('sepia' in step) {
Expand Down
4 changes: 2 additions & 2 deletions packages/enrich-tweet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/enrich-tweet"
},
"main": "dist/enrichTweet.js",
"typings": "dist/enrichTweet.d.ts",
"types": "dist/enrichTweet.d.ts",
"files": [
"dist"
],
Expand All @@ -31,6 +31,6 @@
"twitter-text": "^3.1.0"
},
"devDependencies": {
"@types/twitter-text": "^3.1.2"
"@types/twitter-text": "^3.1.9"
}
}
2 changes: 1 addition & 1 deletion packages/enrich-tweet/src/enrichTweet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default async function enrichTweet(
): Promise<string | undefined> {
if (!tweet) return

let text = tweet.full_text
let text = tweet.full_text ?? ''

// Expand URLs
if (tweet.entities && tweet.entities.urls.length) {
Expand Down
2 changes: 1 addition & 1 deletion packages/file-exists/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/file-exists"
},
"main": "dist/fileExists.js",
"typings": "dist/fileExists.d.ts",
"types": "dist/fileExists.d.ts",
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/format-duration-ms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"directory": "packages/format-duration-ms"
},
"main": "dist/formatDurationMs.js",
"typings": "dist/formatDurationMs.d.ts",
"types": "dist/formatDurationMs.d.ts",
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/has-property/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/has-property"
},
"main": "dist/has-property.js",
"typings": "dist/has-property.d.ts",
"types": "dist/has-property.d.ts",
"files": [
"dist"
],
Expand Down
6 changes: 3 additions & 3 deletions packages/post/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"directory": "packages/post"
},
"bin": "./post.js",
"typings": "dist/post.d.ts",
"types": "dist/post.d.ts",
"files": [
"dist"
],
Expand All @@ -32,7 +32,7 @@
"version": "0.1.3",
"gitHead": "b73ab4880b9c4c48db32f249f776974a137510c4",
"devDependencies": {
"@types/inquirer": "^8.2.1",
"@types/title": "^3.4.1"
"@types/inquirer": "^8.2.10",
"@types/title": "^3.4.3"
}
}
4 changes: 3 additions & 1 deletion packages/post/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ async function post(): Promise<void> {
throw new Error(`Dir does not exist: '${postDir.replace(process.cwd(), '.')}'`)
}

const mysqlNow = new Date().toISOString().replace('T', ' ').split('.')[0].split(' ')[0]
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const mysqlNow = new Date().toISOString().replace('T', ' ').split('.')[0]!.split(' ')[0]!

// eslint-disable-next-line no-unused-vars
const [dateY, datem] = mysqlNow.split('-')
const answers = await inquirer.prompt([
Expand Down
2 changes: 1 addition & 1 deletion packages/pr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/pr"
},
"main": "dist/pr.js",
"typings": "dist/pr.d.ts",
"types": "dist/pr.d.ts",
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/prd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/prd"
},
"main": "dist/prd.js",
"typings": "dist/prd.d.ts",
"types": "dist/prd.d.ts",
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/prettier-bytes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/prettier-bytes"
},
"main": "dist/prettierBytes.js",
"typings": "dist/prettierBytes.d.ts",
"types": "dist/prettierBytes.d.ts",
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/slugify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/slugify"
},
"main": "dist/slugify.js",
"typings": "dist/slugify.d.ts",
"types": "dist/slugify.d.ts",
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/sort-assembly/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/sort-assembly"
},
"main": "dist/sortAssembly.js",
"typings": "dist/sortAssembly.d.ts",
"types": "dist/sortAssembly.d.ts",
"files": [
"dist"
],
Expand Down
13 changes: 9 additions & 4 deletions packages/sort-assembly/src/sortAssembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ export default function sortAssembly<T extends Record<string, unknown>>(assembly
z: ['uploads', 'results'],
})

if ('results' in sorted && typeof sorted.results === 'object') {
if (sorted.results && typeof sorted.results === 'object') {
for (const stepName of Object.keys(sorted.results)) {
if (!hasProperty(sorted.results, stepName)) continue
const result = sorted.results[stepName]
if (!result || typeof result !== 'object') continue
for (const i of Object.keys(result)) {
if (!hasProperty(result, i)) continue
result[i] = sortResult(result[i])
const value = result[i]
if (!value || typeof value !== 'object') continue
result[i] = sortResult(value)
}
}
}

if ('uploads' in sorted) {
if (sorted.uploads) {
for (const i of Object.keys(sorted.uploads)) {
if (!hasProperty(sorted.uploads, i)) continue
sorted.uploads[i] = sortResult(sorted.uploads[i])
const upload = sorted.uploads[i]
if (!upload || typeof upload !== 'object') continue
sorted.uploads[i] = sortResult(upload)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/sort-object-by-prio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/sort-object-by-prio"
},
"main": "dist/sortObjectByPrio.js",
"typings": "dist/sortObjectByPrio.d.ts",
"types": "dist/sortObjectByPrio.d.ts",
"files": [
"dist"
],
Expand Down
3 changes: 2 additions & 1 deletion packages/sort-object-by-prio/src/sortObjectByPrio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export default function sortObjectByPrio<T extends Record<string, unknown>>(
for (const [prefix, items] of Object.entries(prefixes)) {
let i = 0
for (const matcher of items) {
const modifier = parseInt(String(prefix === '_' ? prefixes[prefix].length - i : i), 10)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const modifier = parseInt(String(prefix === '_' ? prefixes[prefix]!.length - i : i), 10)
const numOfPrefix = 3 + modifier
const strPref = new Array(numOfPrefix).join(prefix)

Expand Down
2 changes: 1 addition & 1 deletion packages/sort-object/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/sort-object"
},
"main": "dist/sortObject.js",
"typings": "dist/sortObject.d.ts",
"types": "dist/sortObject.d.ts",
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/sort-result-meta/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/sort-result-meta"
},
"main": "dist/sortResultMeta.js",
"typings": "dist/sortResultMeta.d.ts",
"types": "dist/sortResultMeta.d.ts",
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/sort-result-meta/src/sortResultMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function isObject(obj: unknown): obj is Record<string, unknown> {
}

export default function sortResultMeta<T extends Meta>(meta: T): T {
if (hasProperty(meta, 'faces')) {
if (meta.faces) {
for (const key of Object.keys(meta.faces)) {
if (!hasProperty(meta.faces, key)) continue

Expand Down
2 changes: 1 addition & 1 deletion packages/sort-result/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"directory": "packages/sort-result"
},
"main": "dist/sortResult.js",
"typings": "dist/sortResult.d.ts",
"types": "dist/sortResult.d.ts",
"files": [
"dist"
],
Expand Down
Loading

0 comments on commit 52416cd

Please sign in to comment.