Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: typescript issues fixed #13

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
plugins: ['@typescript-eslint', 'node', 'prettier'],
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
project: ['./tsconfig.json', './tsconfig.cli.json'],
},
extends: [
'eslint:recommended',
Expand Down
55 changes: 55 additions & 0 deletions cli/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env node

const nodemon = require('nodemon');
import { program } from 'commander';
import { readFileSync } from 'fs';
import {
AllowedImageTypeList,
BlurHashMap,
ComponentRange,
} from '../lib/blur-hash-map';

interface CommanderActionOptions {
assets: string;
extensions: string;
componentX: string;
componentY: string;
}
const packageJson: Record<string, string> = JSON.parse(
readFileSync('./package.json', 'utf-8')
);
program
.version(packageJson.version)
.description(packageJson.description)
.option('-a, --assets <assets>', 'Required. Set path to your assets folder')
.option(
'-e, --extensions <extensions>',
'Optional. Define image file extensions. Default: jpg,jpeg,png,bmp,webp'
)
.option('-x, --componentX <componentX>', 'Optional. Default : 4')
.option('-y, --componentY <componentY>', 'Optional. Default : 3')
.action(async function (options: CommanderActionOptions) {
const blurHashGenerator = new BlurHashMap({
assetsRoot: options.assets,
imageExtensions: options.extensions.split(',') as AllowedImageTypeList,
components: {
x: parseInt(options.componentX) as ComponentRange,
y: parseInt(options.componentY) as ComponentRange,
},
});

await blurHashGenerator.init();

// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
nodemon({ watch: options.assets, ext: options.extensions + ',hash' })
.on('quit', function () {
throw 'nodemon exited';
})
.on('restart', function (changedFiles = []) {
for (const file of changedFiles) {
blurHashGenerator.generateOrDelete(file);
}
});
});

program.parse(process.argv);
20 changes: 20 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"devDependencies": {
"@ryansonshine/commitizen": "^4.2.8",
"@ryansonshine/cz-conventional-changelog": "^3.3.4",
"@types/commander": "^2.12.2",
"@types/glob": "^8.1.0",
"@types/jest": "^27.5.2",
"@types/node": "^12.20.11",
Expand Down
2 changes: 1 addition & 1 deletion src/blur-hash-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
renameSync,
} from 'fs';
import { extname, resolve } from 'path';
type ComponentRange = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
export type ComponentRange = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;

export type AllowedImageTypes = 'jpg' | 'jpeg' | 'png' | 'bmp' | 'webp';
export type AllowedImageTypeList = AllowedImageTypes[];
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export type {
BlurHashMapData,
AllowedImageTypeList,
DefaultComponentRatio,
ComponentRange,
} from './blur-hash-map';
10 changes: 10 additions & 0 deletions tsconfig.cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "CommonJS",
"outDir": "bin",
"rootDir": "./cli/",
"strict": true
},
"include": ["cli/*.ts"]
}
Loading