@dropins/build-tools
Advanced tools
Comparing version 0.1.0-alpha2 to 0.1.0-alpha3
@@ -1,9 +0,9 @@ | ||
type GQLResult = { | ||
operation: string; | ||
import { DocumentNode } from 'graphql/language'; | ||
type GQLResult = [DocumentNode, { | ||
success: string[][]; | ||
failure: string[][]; | ||
}; | ||
export declare function getOperationName(operation: string): any; | ||
export declare function mergeGQLElements(operation: string, merges: string[]): GQLResult; | ||
errors: string[][]; | ||
}]; | ||
export declare function mergeGQLElements(declarationAST: DocumentNode, operationAST: DocumentNode): GQLResult; | ||
export {}; | ||
//# sourceMappingURL=extend-elements.d.ts.map |
@@ -1,9 +0,7 @@ | ||
export declare function getFilePath(file: string): Promise<{ | ||
export type FilePath = { | ||
src: string; | ||
dist: string; | ||
} | null>; | ||
export declare function getNodeModulePath(name: string): Promise<{ | ||
src: string; | ||
dist: string; | ||
} | null>; | ||
}; | ||
export declare function getFilePath(file: string): Promise<FilePath | null>; | ||
export declare function getFragmentsFilePath(nodeModuleName: string): Promise<FilePath | null>; | ||
//# sourceMappingURL=get-paths.d.ts.map |
@@ -1,7 +0,7 @@ | ||
import p from"fs/promises";import{parseModule as w}from"esprima";import B from"escodegen";import{parse as f,print as S}from"graphql/language/index.mjs";import x from"path";function b(t){return f(t).definitions[0].name.value}function E(t,n){const e=f(t),o=new Set,a=new Set;return{operation:n.reduce((l,u)=>{var d,g;const[c]=e.definitions,[r]=f(u).definitions,i=r.name.value;return c.kind!==r.kind||c.name.value!==i||c.operation!==r.operation||((d=c.typeCondition)==null?void 0:d.name.value)!==((g=r.typeCondition)==null?void 0:g.name.value)?(a.add([i]),t):(v(c,r).forEach($=>{o.add([i,...$])}),S(e))},t),success:[...o],failure:[...a]}}function v(t,n,e=[]){const o=[];for(const a of n.selectionSet.selections){const s=t.selectionSet.selections.find(r=>{var i;return((i=r.name)==null?void 0:i.value)===a.name.value}),l=[...e,a.name.value],u=(s==null?void 0:s.arguments)??[],c=a.arguments;for(const r of c){const i=u.find(m=>m.name.value===r.name.value);i?i.value=r.value:u.push(r)}if(s!=null&&s.selectionSet&&a.selectionSet)o.push(...v(s,a,l));else{if(a.selectionSet&&l.push(a.selectionSet.selections[0].name.value),o.push(l),s)continue;t.selectionSet.selections.push(a)}}return o}async function j(t){try{await p.access(t);const n=t.replace(/\.\w+$/,".original$&");try{await p.access(n)}catch{await p.copyFile(t,n)}return{src:x.resolve(n),dist:x.resolve(t)}}catch{return null}}async function F(t){const n=x.join(process.cwd(),"node_modules",t,"fragments.js");return await j(n)}function y(t,n){return t.body.filter(e=>e.type==="ExportNamedDeclaration").flatMap(e=>e.specifiers).find(e=>e.exported.name===n)}function h(t,n){return t.body.filter(e=>e.type==="VariableDeclaration").flatMap(e=>e.declarations).find(e=>e.id.name===n)}function M(t){const n=t.init.quasis.map(o=>o.value.raw).join("").trim(),e=t.init.expressions.map(o=>`\${${o.name}}`).join(` | ||
`).trim();return[n,e]}function k(t,n){const e=w(t),o=y(e,n);if(!o)return null;const a=h(e,o.local.name),s=M(a);return{exported:o.exported.name,local:o.local.name,content:s[0],expressions:s[1]}}function A(t,n,e){const o=w(t),a=y(o,n),{local:s}=a,l=h(o,s.name);return l.init={type:"Literal",value:e,raw:`\`${e}\``},B.generate(o,{verbatim:"raw",format:{indent:{style:""},json:!0}}).replace(/\$\{\s(.*)\s\}/g,"${$1}")}async function V(t=[]){console.log("🔎 Checking GraphQl operation files...");let n=new Map;for(const e of t){const{npm:o,operations:a=[]}=e,s=await F(o);if(!s){console.warn("\x1B[31m%s\x1B[0m",`⛔️ GraphQl file in "${o}" not found.`,"\x1B[0m");continue}await p.copyFile(s.src,s.dist),console.log(` | ||
🔄 File "${s.dist}" restored. | ||
`);for(const l of a){const u=n.get(s.dist)||await p.readFile(s.src,"utf-8"),c=b(l),r=k(u,c);if(!r){console.warn("\x1B[31m%s\x1B[0m",`⛔️ Operation "${c}" not found.`,"\x1B[0m");continue}const i=E(r.content,[l]);i.failure.forEach(d=>{console.warn("\x1B[31m%s\x1B[0m",`𐄂 ${d.join(".")}`,"\x1B[0m")}),i.success.forEach(d=>{console.log("\x1B[32m%s\x1B[0m",`✔ ${d.join(".")}`,"\x1B[0m")}),r.expressions&&(i.operation+=` | ||
`+r.expressions);const m=A(u,c,i.operation);n.set(s.dist,m)}}await Promise.all(Array.from(n.keys()).map(async e=>{const o=n.get(e);await p.writeFile(e,o),console.log(` | ||
import c from"fs/promises";import{parseModule as j}from"esprima";import E from"escodegen";import{parse as x,print as S}from"graphql";import d from"path";function C(n,t){const[e]=t.definitions,o=e.name.value,s=n.definitions.find(r=>{var l,u;return r.kind===e.kind&&r.name.value===o&&r.operation===e.operation&&((l=r.typeCondition)==null?void 0:l.name.value)===((u=e.typeCondition)==null?void 0:u.name.value)});if(!s)return[n,{success:[],errors:[[o]]}];const a=h(s,e).map(r=>[o,...r]);return[n,{success:a,errors:[]}]}function h(n,t,e=[]){const o=[];for(const s of t.selectionSet.selections){const i=k(n,s),a=[...e,s.name.value];D(i,s),i!=null&&i.selectionSet&&s.selectionSet?o.push(...h(i,s,a)):M(n,s,i,a,o)}return o}function k(n,t){return n.selectionSet.selections.find(e=>{var o;return((o=e.name)==null?void 0:o.value)===t.name.value})}function D(n,t){const e=(n==null?void 0:n.arguments)??[],o=t.arguments;for(const s of o){const i=e.find(a=>a.name.value===s.name.value);i?i.value=s.value:e.push(s)}}function M(n,t,e,o,s){t.selectionSet&&o.push(t.selectionSet.selections[0].name.value),s.push(o),e||n.selectionSet.selections.push(t)}async function V(n){try{await c.access(n);const t=n.replace(/\.\w+$/,".original$&");try{await c.access(t)}catch{await c.copyFile(n,t)}return{src:d.resolve(t),dist:d.resolve(n)}}catch{return null}}async function G(n){const t=d.join(process.cwd(),"node_modules",n,"fragments.js");return await V(t)}function v(n,t){return n.body.filter(e=>e.type==="ExportNamedDeclaration").flatMap(e=>e.specifiers).find(e=>e.exported.name===t)}function w(n,t){return n.body.filter(e=>e.type==="VariableDeclaration").flatMap(e=>e.declarations).find(e=>e.id.name===t)}function L(n){const t=n.init.quasis.map(o=>o.value.raw).join("").trim(),e=n.init.expressions.map(o=>`\${${o.name}}`).join(` | ||
`).trim();return[t,e]}function Q(n,t){const e=v(n,t);if(!e)return null;const o=w(n,e.local.name),s=L(o);return{exported:e.exported.name,local:e.local.name,content:s[0],expressions:s[1]}}function A(n,t,e){const o=v(n,t),{local:s}=o,i=w(n,s.name);return i.init={type:"Literal",value:e,raw:`\`${e}\``},E.generate(n,{verbatim:"raw",format:{indent:{style:""},json:!0}}).replace(/\$\{\s(.*)\s\}/g,"${$1}")}async function _(n=[]){console.log("🔎 Checking GraphQl operation files...");let t=new Map;for(const e of n){const{npm:o,operations:s=[]}=e,i=await G(o);if(!i){console.warn("\x1B[31m%s\x1B[0m",`⛔️ Cannot access fragments.js file in "${o}".`,"\x1B[0m");continue}await c.copyFile(i.src,i.dist),console.log(` | ||
🔄 File "${i.dist}" restored. | ||
`);for(const a of s){const r=t.get(i.dist)??await c.readFile(i.src,"utf-8"),l=j(r),u=x(a),p=u.definitions[0].name.value,f=Q(l,p);if(!f){console.warn("\x1B[31m%s\x1B[0m",`⛔️ Could not find export "${p}" in "${i.dist}".`,"\x1B[0m");continue}const y=x(f.content),[$,{success:B,errors:F}]=C(y,u);F.forEach(m=>{console.warn("\x1B[31m%s\x1B[0m",`𐄂 ${m.join(".")}`,"\x1B[0m")}),B.forEach(m=>{console.log("\x1B[32m%s\x1B[0m",`✔ ${m.join(".")}`,"\x1B[0m")});let g=S($);f.expressions&&(g+=` | ||
`+f.expressions);const b=A(l,p,g);t.set(i.dist,b)}}for(const e of t.keys()){const o=t.get(e);await c.writeFile(e,o),console.log(` | ||
💾 File "${e}" updated. | ||
`)}))}export{V as default,V as overrideGQLOperations}; | ||
`)}}export{_ as default,_ as overrideGQLOperations}; |
@@ -1,1 +0,1 @@ | ||
{"name":"@dropins/build-tools","version":"0.1.0-alpha2","description":"A package that provides build tools for Dropins","license":"MIT","type":"module","engines":{"node":">=16"},"scripts":{"lint":"eslint","test":"jest","test:ci":"jest --config jest.config.js --passWithNoTests --coverage","build":"vite build","postbuild":"cp ./package.json ./dist"},"dependencies":{"escodegen":"^2.1.0","esprima":"^4.0.1","graphql":"^16.9.0"},"devDependencies":{"@types/escodegen":"^0.0.10","@types/esprima":"^4.0.6","typescript":"^4.7.3","vite":"^5.2.10","vite-plugin-dts":"^3.9.1"}} | ||
{"name":"@dropins/build-tools","version":"0.1.0-alpha3","description":"A package that provides build tools for Dropins","license":"MIT","type":"module","engines":{"node":">=16"},"scripts":{"lint":"eslint","test":"jest","test:ci":"jest --config jest.config.js --passWithNoTests --coverage","build":"vite build","postbuild":"cp ./package.json ./dist"},"dependencies":{"escodegen":"^2.1.0","esprima":"^4.0.1","graphql":"^16.9.0"},"devDependencies":{"@types/escodegen":"^0.0.10","@types/esprima":"^4.0.6","typescript":"^4.7.3","vite":"^5.2.10","vite-plugin-dts":"^3.9.1"}} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
6706
46