-- 설치하지 않고 레지스트리 메타데이터를 읽는다
npmView :: Package -> Field -> IO Json
npmView "cowsay" "versions" -- 게시된 모든 버전
npmView "cowsay" "time" -- 버전마다 게시된 시각
-- npm 은 실행 중인 스크립트 이름을 npm_lifecycle_event 로 넘긴다
stage :: String -> Maybe String
stage = stripPrefix "dev:" -- ${npm_lifecycle_event#dev:} — sh 로 돌아서 POSIX # 만 (bash 의 // 는 안 된다)
stage "dev:hello" == Just "hello"
-- 이렇게 하기보다 스크립트를 따로 쓰는 게 낫다
-- CRA: .env 의 ${VAR} 를 이미 있는 환경 변수로 채운다 (dotenv-expand)
expand :: Env -> String -> String
expand env = replaceVars (\v -> fromMaybe "" (lookup v env))
-- turbo 가 태스크마다 TURBO_HASH 를 넣어 준다 — REACT_APP_VERSION 을 자동으로 채울 방법을 찾다가 해시를 붙였다
expand [("TURBO_HASH", "ab12")] "0.0.0-${TURBO_HASH}" == "0.0.0-ab12" -- REACT_APP_VERSION
-- inotify: 사용자당 감시 개수에 상한이 있다
watched :: [File] -> Bool
watched files = length files <= maxUserWatches -- 넘으면 webpack 이 변경을 못 알아챈다
-- "System limit for number of file watchers reached"
-- echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
-- 빌드 버전에 꼬리표
version :: Either Timestamp TurboHash -> String
version (Left t) = "1.0.0-" ++ show t -- $(date +%s): 1970-01-01 UTC 이후 초, 빌드마다 다르다
version (Right h) = "1.0.0-" ++ h -- .env 의 ${TURBO_HASH} — 실제로는 이쪽 (dotenv-expand)
로컬에서만 실행 해야하는 프로젝트가 있길래 아무래도 사전설정 같은 귀찮은 문제가 있으니 pkg를 사용하면 좋을 것 같아서 들어가봤는데 개발이 중단 되었다.
노드 21버젼에서 해당 기능이 지원되는데 재미있는 시도들이 많이 나왔으면 좋겠다.
-- Node 에서 Excel: COM(ActiveX) 으로 실행 중인 앱을 잡고 객체 모델을 따라 내려간다
activeX :: ProgId -> IO Application -- new ActiveXObject('Excel.Application') · node-activex
-- Application → Workbooks → Worksheets → Range
activeRow :: IO Range
activeRow = entireRow . activeCell <$> activeX "Excel.Application" -- Excel View: 활성 셀의 행을 별도 창에
-- 아직 안 해본 것: 객체 모델 · view 기능을 스프레드시트로
- Node.js Child Processes: Everything you need to know1
- The definitive Node.js handbook
- Tao of Node - Design, Architecture & Best Practices
- Useful Built-in Node.js APIs
glob
- GitHub - isaacs/node-glob
- GitHub - mrmlnc/fast-glob
- GitHub - sindresorhus/globby
- GitHub - SuperchupuDev/tinyglobby
Footnotes
-
spawn(), exec(), execFile(), fork() ↩
-- 이미지 다운로드: 응답을 Buffer 로 받아 파일로
download :: Url -> IO ()
download url = do
buf <- fromArrayBuffer <$> (fetch url >>= arrayBuffer)
createDirectoryIfMissing folder -- 없으면 mkdir
writeFile (folder </> takeFileName (pathname url)) buf
-- start 에서 링크로 닿는 URL 전부 — 처리 결과가 다시 입력이 되어 언제 끝날지 모를 때
crawl :: (Url -> [Url]) -> Url -> Set Url
crawl links start = go Set.empty [start]
where
go seen [] = seen -- onIdle: 대기열·실행 중 둘 다 0
go seen (u : q)
| u `member` seen = go seen q -- seen.has
| otherwise = go (insert u seen) (q ++ links u) -- seen.add 와 자식 추가가 한 걸음: 끼어들 틈이 없다
-- 끼어들 틈이 없는 건 단일 스레드라서다: 함수는 도중에 선점되지 않는다. has 와 add 사이에 await 가 없으니 락이 필요 없다
-- 요청보다 먼저 표시한다. 요청 뒤에 표시하면 그 사이 같은 URL 이 또 들어온다
-- 서로 가리키는 페이지가 있어도 끝나고, 결과 크기가 고유 URL 수와 같으면 된 것이다
-- PNG 마다: 여백을 자르고 절반으로
half :: Image -> Image
half img = resize (round (w / 2), round (h / 2)) t
where t = trim img -- 가장자리 여백 제거
(w, h) = size t -- 잘린 뒤 크기를 다시 읽는다
-- for entry in fg('./**/*.png'): half entry → entry.replace(.png, .half.png)
-- crop: extract { left = 50, top = 50, width = 200, height = 400 }
ID3 is a metadata container most often used in conjunction with the MP3 audio file format.
Footnotes
- yarn upgrade-interactive | Yarn1
- Find newer versions of package dependencies than what your package.json allows2
Footnotes
-
이 명령은 업그레이드를 수행하기 전에 오래된 패키지를 표시하여 사용자가 업그레이드할 패키지를 선택할 수 있도록 합니다. ↩
-
npm-check-updates는 지정된 버전을 무시하고 package.json 종속성을 최신 버전으로 업그레이드합니다 . ↩
-- 엑셀 → 언어별 JSON. header: 1 이면 행이 배열 — 열을 인덱스로 자른다
locales :: [[Cell]] -> (Map Key String, Map Key String)
locales rows = (fromList [(k, en) | (k, en, _) <- rs], fromList [(k, ko) | (k, _, ko) <- rs])
where rs = [ (normalize key, en, ko)
| row <- drop 1 rows -- 머리글 행
, let [key, en, ko] = take 3 (drop 1 row) -- 2~4번째 열
, any nonEmpty row ] -- 빈 행도 [] 로 나온다
normalize = map toLower . replace "-" "_"
-- → en.json · ko.json
-- 로컬 디렉터리를 의존성으로 — 상대 경로로 정규화되어 저장된다
dep :: Path -> (Name, Spec)
dep path = (packageName path, "file:" ++ relative path)
dep "../foo/bar" == ("bar", "file:../foo/bar") -- npm install --save ../foo/bar