UNPKG

adobe-font-extractor

Version:

A command-line utility for extracting Adobe fonts on macOS and Windows.

2 lines (1 loc) 9.08 kB
import{buildInstallCommand as nt,buildUninstallCommand as it}from"@stricli/auto-complete";import{buildApplication as at,buildRouteMap as ct}from"@stricli/core";var E="adobe-font-extractor",R="1.0.0";var N="A command-line utility for extracting Adobe fonts on macOS and Windows.";import*as L from"node:path";import{buildCommand as ot}from"@stricli/core";import{type as T}from"arktype";import K from"picomatch";var b="*";function h(t){let o=K(t.globPattern);return r=>o(r.name)}var j=["silent","error","info","debug"];function x(t){function o(e){switch(t){case"silent":return!1;case"error":return["error"].includes(e);case"info":return["error","info"].includes(e);case"debug":return["error","info","debug"].includes(e);default:return t}}let r=!0;return{newLine(){r||(console.log(),r=!0)},log(e,s){o(e)&&(console.log(s),r=!1)},section(e){this.newLine(),this.log("info",`# ${e}`)},task(e){this.newLine(),this.log("info",`${e}${e.endsWith("...")?"":"..."}`)},success(e){this.log("info",`[+] ${e}`)},debug(e){this.log("debug",`[#] ${e}`)},info(e){this.log("info",`[i] ${e}`)},warn(e){this.log("info",`[!] ${e}`)},error(e){this.log("error",`[-] ${e}`)},summary(e){e.forEach(s=>{switch(s.type){case"info":return this.info(s.message);case"error":return this.error(s.message);case"section":return this.section(s.message);case"warn":return this.warn(s.message);default:return s.type}})}}}import{ArkErrors as Q}from"arktype";function S(t){return o=>{let r=t(o);if(r instanceof Q)throw new SyntaxError(r.summary,{cause:r});return r}}var C={g:"globPattern",s:"sourceDirectory",v:"verbosity"},v={sourceDirectory:{optional:!0,kind:"parsed",brief:"Custom source directory to search for fonts",parse:S(T("string")),placeholder:"source",hidden:!0},verbosity:{kind:"enum",values:j,brief:"Set the verbosity",default:"info"},globPattern:{kind:"parsed",brief:"Filter fonts by glob pattern (must be quoted)",placeholder:"pattern",default:`${b}`,parse:S(T("string"))}};import*as c from"node:fs/promises";import J from"node:path";async function A(t,o){t||await o()}async function _(t){try{let{force:o,dryRun:r,dest:e,src:s}=t,n=await Y(e);return await A(r,async()=>{await c.mkdir(J.dirname(e),{recursive:!0})}),n?o?(await A(r,async()=>{await c.copyFile(s,e)}),{status:"overridden"}):{status:"skipped"}:(await A(r,async()=>{await c.copyFile(s,e)}),{status:"success"})}catch(o){return{status:"error",cause:o}}}async function Y(t){try{return await c.access(t),!!(await c.stat(t)).isFile()}catch{return!1}}import*as m from"node:fs/promises";async function F(t){try{return await m.access(t,m.constants.F_OK),(await m.stat(t)).isDirectory()}catch{return!1}}import*as O from"node:fs/promises";import G from"node:path";import*as V from"fontkit";async function p(t){let{source:o}=t,r=[],e=await O.readdir(o,{withFileTypes:!0});for(let s of e){let n=G.join(o,s.name);if(s.isDirectory())r.push(...await p({source:n}));else if(s.isFile()&&/\.(otf|ttf)$/i.test(s.name)){let i=await H(n);if(!i)continue;r.push({name:i,path:n})}}return r}async function H(t){try{let o=await V.open(t);return"postscriptName"in o?o.postscriptName.trim():null}catch{return null}}import*as U from"node:os";import{ArkErrors as X,type as Z}from"arktype";var tt=Z("'darwin' | 'win32'");function k(){let t=tt(U.platform());return t instanceof X?{status:"incompatible",message:t.summary}:{status:"compatible",name:t}}import*as I from"node:os";import P from"node:path";function w(t,o){if(o.sourceDirectory)return{type:"custom",path:P.resolve(o.sourceDirectory)};switch(t){case"darwin":return{type:"platform-default",path:P.join(I.homedir(),"Library","Application Support","Adobe","CoreSync","plugins","livetype")};case"win32":return{type:"platform-default",path:P.join(I.homedir(),"AppData","Roaming","Adobe","CoreSync","plugins","livetype")};default:return t}}import et from"node:path";function f(t){return et.relative(process.cwd(),t)}var z=ot({async func(t,o){let r=performance.now(),e=x(t.verbosity);e.section("Adobe Font Extractor".toUpperCase()),e.newLine();let s=k();if(s.status==="incompatible")return e.error(s.message),process.exit(1);let n=w(s.name,t);if(!await F(n.path))return n.type==="custom"?e.error(`Source directory "${n.path}" does not exist`):e.error(`Font directory "${n.path}" does not exist, make sure you have the Creative Cloud app installed and running.`),process.exit(1);e.task(`Searching fonts${t.sourceDirectory?` in ${t.sourceDirectory}`:""}`);let i=await p({source:n.path});if(i.length===0)return t.sourceDirectory?e.error(`No fonts found in source directory "${t.sourceDirectory}"`):e.error("No fonts found in default Adobe fonts directory, make sure you have Adobe fonts installed and the Creative Cloud app running."),process.exit(0);let a=i.filter(h(t));if(a.length===0)return e.warn(`No fonts matched filter "${t.globPattern}" (${i.length} fonts total)`),process.exit(1);e.success(`Found ${a.length} fonts ${t.globPattern!==b?`matching "${t.globPattern}" (${i.length} fonts total)`:""}`),e.task("Copying fonts");let u=0,d=0,D=0;for(let g of a){let B=L.extname(g.path),y=L.join(o,`${g.name}${B}`),l=await _({src:g.path,dest:y,force:t.force,dryRun:t.dryRun});if(l.status==="success"||l.status==="overridden")u++,e.debug(`Copied "${g.name}" to "${f(y)}"`);else if(l.status==="skipped")d++,e.warn(`File "${f(y)}" already exists (use --force to overwrite)`);else if(l.status==="error"){if(D++,t.abortOnError)throw l.cause;e.error(`Failed to copy "${f(y)}" (use --abort to abort on errors)`)}}e.success("Finished copying fonts");let{exitCode:W,summary:q}=rt({kind:"fonts-processed",destination:o,fontsFiltered:a.length,fontsCopiedSuccessfully:u,fontsSkipped:d,copyErrors:D,duration:performance.now()-r,flags:t});return e.summary(q),process.exit(W)},parameters:{aliases:{...C,a:"abortOnError",d:"dryRun",f:"force"},flags:{...v,abortOnError:{kind:"boolean",brief:"Abort on recoverable errors",default:!1},force:{kind:"boolean",brief:"Force overwrite existing files",default:!1},dryRun:{kind:"boolean",brief:"Dry run, do not copy files",default:!1}},positional:{kind:"tuple",parameters:[{brief:"Directory to copy fonts to",parse:String,placeholder:"target-directory"}]}},docs:{brief:"Extract installed Adobe fonts",fullDescription:"Extracts installed Adobe fonts to a specified destination directory. If a font is missing, make sure it is installed on the Adobe fonts site (https://fonts.adobe.com) and that the Creative Cloud app is installed and running."}});function rt(t){let o=[{type:"section",message:"Summary"}],r=0;switch(t.flags.dryRun&&o.push({type:"info",message:"Dry run, no files were copied"}),t.kind){case"fonts-processed":{let{destination:e,fontsFiltered:s,fontsCopiedSuccessfully:n,fontsSkipped:i,copyErrors:a,flags:u}=t,d=f(e);o.push({type:"info",message:`Copied ${n} of ${s} fonts to "${d}"`}),i>0&&o.push({type:"info",message:`${i} font${i===1?"":"s"} skipped (already exist${u.force?"ed and were overwritten":""})`}),a>0&&o.push({type:"error",message:`Failed to copy ${a} font${a===1?"":"s"} due to errors`}),a>0&&n===0?r=1:r=0;break}}return o.push({type:"info",message:`Operation took ${t.duration.toFixed(2)} ms (verbosity: ${t.flags.verbosity})`}),{exitCode:r,summary:o}}import{buildCommand as st}from"@stricli/core";var M=st({async func(t){let o=x(t.verbosity);o.section("List Adobe Fonts".toUpperCase()),o.newLine();let r=k();if(r.status==="incompatible")return o.error(r.message),process.exit(1);let e=w(r.name,t);if(!await F(e.path))return e.type==="custom"?o.error(`Source directory "${e.path}" does not exist`):o.error(`Font directory "${e.path}" does not exist, make sure you have the Creative Cloud app installed and running.`),process.exit(1);let s=await p({source:e.path});if(s.length===0)return o.warn("No fonts found in the source directory, make sure you have Adobe fonts installed."),process.exit(0);let n=s.filter(h(t));n.length===0&&(o.warn(`No fonts matched the filter "${t.globPattern}" (${s.length} fonts total)`),process.exit(1)),n.forEach(i=>{o.log("error",`- ${i.name}`)})},parameters:{aliases:{...C},flags:{...v},positional:{kind:"tuple",parameters:[]}},docs:{brief:"List installed Adobe fonts",fullDescription:"List installed Adobe fonts. If a font is missing, make sure it is installed on the Adobe fonts site (https://fonts.adobe.com) and that the Creative Cloud app is installed and running."}});var mt=ct({routes:{extract:z,list:M,install:nt("adobe-font-extractor",{bash:"__adobe-font-extractor_bash_complete"}),uninstall:it("adobe-font-extractor",{bash:!0})},docs:{brief:N,fullDescription:"Lists and extracts installed Adobe fonts. If a font is missing, make sure it is installed on the Adobe fonts site (https://fonts.adobe.com) and that the Creative Cloud app is installed and running.",hideRoute:{install:!0,uninstall:!0}}}),ie=at(mt,{name:E,scanner:{caseStyle:"allow-kebab-for-camel"},documentation:{caseStyle:"convert-camel-to-kebab",disableAnsiColor:!0,useAliasInUsageLine:!0},versionInfo:{currentVersion:R}});import lt from"node:fs";import pt from"node:os";import ft from"node:path";function pe(t){return{process:t,os:pt,fs:lt,path:ft}}export{ie as a,pe as b};