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

ts-nodeを導入 #246

Merged
merged 8 commits into from
Jul 17, 2023
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
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { createVanillaExtractPlugin } = require('@vanilla-extract/next-plugin');
import { createVanillaExtractPlugin } from '@vanilla-extract/next-plugin';

const withVanillaExtract = createVanillaExtractPlugin();

const nextConfig = {
reactStrictMode: true,
};

module.exports = withVanillaExtract(nextConfig);
export default withVanillaExtract(nextConfig);
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "official",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"build": "yarn pathpida && next build && next export",
Expand All @@ -17,8 +18,8 @@
"build-storybook": "storybook build",
"pathpida": "pathpida --enableStatic --ignorePath .pathpidaignore --output src/utils/ && prettier --write 'src/utils/$path.ts'",
"icons": "svgr -d src/components/base/Icons src/assets/icons",
"images": "node src/scripts/generateImages.js",
"lighthouse": "node src/scripts/lighthouse.js",
"images": "ts-node src/scripts/generateImages.ts",
"lighthouse": "ts-node src/scripts/lighthouse.ts",
"husky": "husky install"
},
"dependencies": {
Expand All @@ -40,6 +41,7 @@
"@storybook/nextjs": "^7.0.26",
"@storybook/react": "^7.0.26",
"@svgr/cli": "^6.5.1",
"@types/minimist": "^1.2.2",
"@types/node": "18.15.0",
"@types/react": "18.0.28",
"@types/react-dom": "18.0.11",
Expand All @@ -63,6 +65,7 @@
"prettier": "^2.8.3",
"sharp": "^0.32.1",
"storybook": "^7.0.26",
"ts-node": "^10.9.1",
"typescript": "4.9.5",
"webpack-merge": "^5.9.0"
},
Expand Down
25 changes: 14 additions & 11 deletions src/scripts/generateImages.js → src/scripts/generateImages.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
const fs = require('fs');
const path = require('path');
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

const sharp = require('sharp');
import sharp from 'sharp';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

/**
* スマホ用の画像を生成する
* @param {string} fullPath
* @param {string} outputPath
*/
const generateMobileImage = async (fullPath, outputPath) => {
const generateMobileImage = async (fullPath: string, outputPath: string): Promise<void> => {
if (fs.existsSync(outputPath)) return;
const image = sharp(fullPath);
const metadata = await image.metadata();

// 通常は発生しないフローだが型定義が`undefined`を許容しており、TSの警告を回避するために記述している
if (!metadata.width || !metadata.height) return;

await image
.resize({
width: Math.round(metadata.width / 2),
Expand All @@ -22,20 +28,17 @@ const generateMobileImage = async (fullPath, outputPath) => {

/**
* デスクトップ用の画像を生成する
* @param {string} fullPath
* @param {string} outputPath
*/
const generateDesktopImage = async (fullPath, outputPath) => {
const generateDesktopImage = async (fullPath: string, outputPath: string): Promise<void> => {
if (fs.existsSync(outputPath)) return;
await sharp(fullPath).toFile(outputPath);
};

/**
* /public/images 以下のディレクトリ内にある png または jpg(jpeg) ファイルを元に webp と avif ファイルを生成する
* またそれぞれの拡張子に応じたスマホ用のファイルも生成する
* @param {string} dirPath
*/
const generateImages = async (dirPath) => {
const generateImages = async (dirPath: string): Promise<void> => {
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
const ignoreDirs = fs
.readFileSync(path.join(__dirname, '../..', '.imagesignore'), 'utf-8')
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/lighthouse.js → src/scripts/lighthouse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { execSync } = require('child_process');
import { execSync } from 'child_process';

const minimist = require('minimist');
import minimist from 'minimist';

const argv = minimist(process.argv.slice(2));
const port = argv.p || 3000;
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
"exclude": ["node_modules"],
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node"
}
}
1,557 changes: 745 additions & 812 deletions yarn.lock

Large diffs are not rendered by default.