@cedarjs/cli-data-migrate 7.0.0-canary.3083 → 7.0.0-canary.3084

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- var I=(t,n,r)=>()=>{if(r)throw r[0];try{return t&&(n=t(t=0)),n}catch(e){throw r=[e],e}};import d from"node:fs";import m from"node:path";import{Listr as k}from"listr2";import{createServer as _,isRunnableDevEnvironment as L}from"vite";import{colors as f}from"@cedarjs/cli-helpers";import{getPaths as l,getDataMigrationsPath as N,resolveFile as O,importStatementPath as v}from"@cedarjs/project-config";function V(t){if(d.existsSync(t)&&d.statSync(t).isFile())return t;let n=/\.jsx?$/.test(t)?t.replace(/\.jsx?$/,""):t;for(let r of[".ts",".tsx",".js",".jsx"])if(d.existsSync(n+r))return n+r;if(d.existsSync(t)&&d.statSync(t).isDirectory())for(let r of["index",m.basename(t)])for(let e of[".ts",".tsx",".js",".jsx"]){let o=m.join(t,r+e);if(d.existsSync(o))return o}return t}async function x({importDbClientFromDist:t,distPath:n}){let r,e=null,o;async function g(){e||(o||(o=await import("@cedarjs/vite")),e=await _({mode:"production",optimizeDeps:{noDiscovery:!0,include:void 0},server:{hmr:!1,watch:null},environments:{nodeRunnerEnv:{}},resolve:{alias:[{find:/^api\//,replacement:l().api.base+"/"},{find:/^src\//,replacement:"src/",customResolver:(a,p,u)=>{let y=v(l().api.base);if(p?.startsWith(y)){let D=v(l().api.src),b=a.replace("src",D);return{id:V(b)}}return null}}]},plugins:[o.cedarCjsCompatPlugin(),o.cedarjsResolveCedarStyleImportsPlugin(),o.cedarImportDirPlugin(),o.cedarAutoImportsPlugin()]}));let i=e.environments.nodeRunnerEnv;if(!i||!L(i))throw new Error("Vite environment is not runnable.");return i.runner}if(t){if(!d.existsSync(n)){console.warn(`Can't find api dist at ${n}. You may need to build first: yarn cedar build api`),process.exitCode=1;return}let i=m.join(n,"lib"),a=m.join(i,"db.js");if(!d.existsSync(a)){console.error(`Can't find db.js at ${a}. CedarJS expects the db.js file to be in the ${i} directory`),process.exitCode=1;return}r=(await import(a)).db}else{let i=O(m.join(l().api.lib,"db"));if(!i){console.error(`Can't find your db file in ${l().api.lib}`),process.exitCode=1;return}try{r=(await(await g()).import(i)).db}catch(a){throw await e?.close(),a}}let s=await B(r);if(!s.length){console.info(f.success(`
2
+ var I=(t,n,r)=>()=>{if(r)throw r[0];try{return t&&(n=t(t=0)),n}catch(e){throw r=[e],e}};import d from"node:fs";import m from"node:path";import{Listr as k}from"listr2";import{createServer as _,isRunnableDevEnvironment as L}from"vite";import{colors as f}from"@cedarjs/cli-helpers/colors";import{getPaths as l,getDataMigrationsPath as N,resolveFile as O,importStatementPath as v}from"@cedarjs/project-config";function V(t){if(d.existsSync(t)&&d.statSync(t).isFile())return t;let n=/\.jsx?$/.test(t)?t.replace(/\.jsx?$/,""):t;for(let r of[".ts",".tsx",".js",".jsx"])if(d.existsSync(n+r))return n+r;if(d.existsSync(t)&&d.statSync(t).isDirectory())for(let r of["index",m.basename(t)])for(let e of[".ts",".tsx",".js",".jsx"]){let o=m.join(t,r+e);if(d.existsSync(o))return o}return t}async function x({importDbClientFromDist:t,distPath:n}){let r,e=null,o;async function g(){e||(o||(o=await import("@cedarjs/vite")),e=await _({mode:"production",optimizeDeps:{noDiscovery:!0,include:void 0},server:{hmr:!1,watch:null},environments:{nodeRunnerEnv:{}},resolve:{alias:[{find:/^api\//,replacement:l().api.base+"/"},{find:/^src\//,replacement:"src/",customResolver:(a,p,u)=>{let y=v(l().api.base);if(p?.startsWith(y)){let D=v(l().api.src),b=a.replace("src",D);return{id:V(b)}}return null}}]},plugins:[o.cedarCjsCompatPlugin(),o.cedarjsResolveCedarStyleImportsPlugin(),o.cedarImportDirPlugin(),o.cedarAutoImportsPlugin()]}));let i=e.environments.nodeRunnerEnv;if(!i||!L(i))throw new Error("Vite environment is not runnable.");return i.runner}if(t){if(!d.existsSync(n)){console.warn(`Can't find api dist at ${n}. You may need to build first: yarn cedar build api`),process.exitCode=1;return}let i=m.join(n,"lib"),a=m.join(i,"db.js");if(!d.existsSync(a)){console.error(`Can't find db.js at ${a}. CedarJS expects the db.js file to be in the ${i} directory`),process.exitCode=1;return}r=(await import(a)).db}else{let i=O(m.join(l().api.lib,"db"));if(!i){console.error(`Can't find your db file in ${l().api.lib}`),process.exitCode=1;return}try{r=(await(await g()).import(i)).db}catch(a){throw await e?.close(),a}}let s=await B(r);if(!s.length){console.info(f.success(`
3
3
  ${W}
4
4
  `)),process.exitCode=0,await e?.close();return}let c={run:0,skipped:0,error:0},C=s.map(i=>{let a=m.basename(i.path,".js");return{title:a,skip(){return c.error>0?(c.skipped++,!0):!1},async task(){try{let{startedAt:p,finishedAt:u}=await A(r,i.path);c.run++,await F(r,{version:i.version,name:a,startedAt:p,finishedAt:u})}catch(p){c.error++;let u=p instanceof Error?p.message:String(p);console.error(f.error(`Error in data migration: ${u}`))}}}}),E=new k(C,{renderer:"verbose"});try{await E.run(),await r.$disconnect(),console.log(),w(c),console.log(),c.error&&(process.exitCode=1)}catch{process.exitCode=1,await r.$disconnect(),console.log(),w(c),console.log()}finally{e&&await e.close()}async function A(i,a){let y=(await(await g()).import(a)).default,D=new Date;return await y({db:i}),{startedAt:D,finishedAt:new Date}}}async function B(t){let n=await N(l().api.prismaConfig);if(!d.existsSync(n))return[];let r=d.readdirSync(n).filter(s=>["js",".ts"].some(c=>s.endsWith(c))).map(s=>{let[c]=s.split("-");return{version:c,path:m.join(n,s)}}),o=(await t.rW_DataMigration.findMany({orderBy:{version:"asc"}})).map(s=>s.version.toString());return r.filter(({version:s})=>!o.includes(s)).sort(U)}function U(t,n){let r=parseInt(t.version),e=parseInt(n.version);return r>e?1:r<e?-1:0}async function F(t,{version:n,name:r,startedAt:e,finishedAt:o}){await t.rW_DataMigration.create({data:{version:n,name:r,startedAt:e,finishedAt:o}})}function w(t){t.run&&console.info(f.success(`${t.run} data migration(s) completed successfully.`)),t.error&&console.error(f.error(`${t.error} data migration(s) exited with errors.`)),t.skipped&&console.warn(f.warning(`${t.skipped} data migration(s) skipped due to previous error.`))}var W,j=I(()=>{"use strict";W="No pending data migrations run, already up-to-date."});import S from"path";import{config as G}from"dotenv-defaults";import{hideBin as J}from"yargs/helpers";import T from"yargs/yargs";import{getPaths as P}from"@cedarjs/project-config";import{terminalLink as $}from"termi-link";import{getPaths as R}from"@cedarjs/project-config";var h="Run any outstanding Data Migrations against the database";function M(t){return t.option("import-db-client-from-dist",{type:"boolean",alias:["db-from-dist"],description:"Import the db client from dist",default:!1}).option("dist-path",{type:"string",alias:"d",description:"Path to the api dist directory",default:R().api.dist}).epilogue(`Also see the ${$("CedarJS CLI Reference","https://cedarjs.com/docs/cli-commands#datamigrate-up")}`)}j();process.env.CEDAR_ENV_FILES_LOADED||(G({path:S.join(P().base,".env"),defaults:S.join(P().base,".env.defaults"),multiline:!0}),process.env.CEDAR_ENV_FILES_LOADED="true");T(J(process.argv)).scriptName("data-migrate").command("$0",h,M,x).parse();
@@ -2,7 +2,7 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import execa from "execa";
4
4
  import { Listr } from "listr2";
5
- import { colors as c } from "@cedarjs/cli-helpers";
5
+ import { colors as c } from "@cedarjs/cli-helpers/colors";
6
6
  import {
7
7
  getPaths,
8
8
  getSchemaPath,
@@ -2,7 +2,7 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { Listr } from "listr2";
4
4
  import { createServer, isRunnableDevEnvironment } from "vite";
5
- import { colors as c } from "@cedarjs/cli-helpers";
5
+ import { colors as c } from "@cedarjs/cli-helpers/colors";
6
6
  import {
7
7
  getPaths,
8
8
  getDataMigrationsPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli-data-migrate",
3
- "version": "7.0.0-canary.3083",
3
+ "version": "7.0.0-canary.3084",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -26,9 +26,9 @@
26
26
  "test:unit": "vitest run src"
27
27
  },
28
28
  "dependencies": {
29
- "@cedarjs/cli-helpers": "7.0.0-canary.3083",
30
- "@cedarjs/project-config": "7.0.0-canary.3083",
31
- "@cedarjs/vite": "7.0.0-canary.3083",
29
+ "@cedarjs/cli-helpers": "7.0.0-canary.3084",
30
+ "@cedarjs/project-config": "7.0.0-canary.3084",
31
+ "@cedarjs/vite": "7.0.0-canary.3084",
32
32
  "dotenv-defaults": "5.0.2",
33
33
  "execa": "5.1.1",
34
34
  "listr2": "10.2.2",
@@ -37,7 +37,7 @@
37
37
  "yargs": "17.7.3"
38
38
  },
39
39
  "devDependencies": {
40
- "@cedarjs/framework-tools": "7.0.0-canary.3083",
40
+ "@cedarjs/framework-tools": "7.0.0-canary.3084",
41
41
  "@prisma/client": "7.10.0",
42
42
  "@types/yargs": "17.0.35",
43
43
  "memfs": "4.68.2",