@cedarjs/cli-data-migrate 1.0.0-canary.12310 → 1.0.0-canary.12312

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
2
  "use strict";var L=Object.create;var M=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,U=Object.prototype.hasOwnProperty;var w=(t,r)=>()=>(t&&(r=t(t=0)),r);var W=(t,r,e,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of R(r))!U.call(t,o)&&o!==e&&M(t,o,{get:()=>r[o],enumerable:!(i=N(r,o))||i.enumerable});return t};var d=(t,r,e)=>(e=t!=null?L(V(t)):{},W(r||!t||!t.__esModule?M(e,"default",{value:t,enumerable:!0}):e,t));var a,c,E=w(()=>{"use strict";a=d(require("chalk")),c={error:a.default.bold.red,warning:a.default.hex("#ffa500"),highlight:a.default.hex("#ffa500"),success:a.default.green,info:a.default.grey,bold:a.default.bold,underline:a.default.underline,note:a.default.blue,tip:a.default.green,important:a.default.magenta,caution:a.default.red,link:a.default.hex("#e8e8e8")}});async function O({importDbClientFromDist:t,distPath:r}){let e,i=!1;if(t){if(!f.default.existsSync(r)){console.warn(`Can't find api dist at ${r}. You may need to build first: yarn rw build api`),process.exitCode=1;return}let p=m.default.join(r,"lib","db.js");if(!f.default.existsSync(p)){console.error(`Can't find db.js at ${p}. Redwood expects the db.js file to be in the ${m.default.join(r,"lib")} directory`),process.exitCode=1;return}e=(await import(p)).db}else(0,u.registerApiSideBabelHook)(),i=!0,e=require(m.default.join((0,h.getPaths)().api.lib,"db")).db;let o=await B(e);if(!o.length){console.info(c.success(`
3
- ${q}
4
- `)),process.exitCode=0;return}let s={run:0,skipped:0,error:0},n=o.map(p=>{let D=m.default.basename(p.path,".js");return{title:D,skip(){return s.error>0?(s.skipped++,!0):!1},async task(){i||(0,u.registerApiSideBabelHook)();try{let{startedAt:g,finishedAt:I}=await H(e,p.path);s.run++,await T(e,{version:p.version,name:D,startedAt:g,finishedAt:I})}catch(g){s.error++,console.error(c.error(`Error in data migration: ${g.message}`))}}}}),l=new C.Listr(n,{renderer:"verbose"});try{await l.run(),await e.$disconnect(),console.log(),j(s),console.log(),s.error&&(process.exitCode=1)}catch{process.exitCode=1,await e.$disconnect(),console.log(),j(s),console.log()}}async function B(t){let r=(0,h.getPaths)().api.dataMigrations;if(!f.default.existsSync(r))return[];let e=f.default.readdirSync(r).filter(n=>["js",".ts"].some(l=>n.endsWith(l))).map(n=>{let[l]=n.split("-");return{version:l,path:m.default.join(r,n)}}),o=(await t.rW_DataMigration.findMany({orderBy:{version:"asc"}})).map(n=>n.version.toString());return e.filter(({version:n})=>!o.includes(n)).sort(G)}function G(t,r){let e=parseInt(t.version),i=parseInt(r.version);return e>i?1:e<i?-1:0}async function H(t,r){let e=await import(r),i=new Date;return await e.default({db:t}),{startedAt:i,finishedAt:new Date}}async function T(t,{version:r,name:e,startedAt:i,finishedAt:o}){await t.rW_DataMigration.create({data:{version:r,name:e,startedAt:i,finishedAt:o}})}function j(t){t.run&&console.info(c.success(`${t.run} data migration(s) completed successfully.`)),t.error&&console.error(c.error(`${t.error} data migration(s) exited with errors.`)),t.skipped&&console.warn(c.warning(`${t.skipped} data migration(s) skipped due to previous error.`))}var f,m,C,u,h,q,$=w(()=>{"use strict";f=d(require("fs")),m=d(require("path")),C=require("listr2"),u=require("@cedarjs/babel-config"),h=require("@cedarjs/project-config");E();q="No pending data migrations run, already up-to-date."});var b=d(require("path")),S=require("dotenv-defaults"),_=require("yargs/helpers"),P=d(require("yargs/yargs")),y=require("@cedarjs/project-config");var v=d(require("terminal-link")),x=require("@cedarjs/project-config");var k="Run any outstanding Data Migrations against the database";function A(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:(0,x.getPaths)().api.dist}).epilogue(`Also see the ${(0,v.default)("Redwood CLI Reference","https://redwoodjs.com/docs/cli-commands#datamigrate-up")}`)}$();process.env.REDWOOD_ENV_FILES_LOADED||((0,S.config)({path:b.default.join((0,y.getPaths)().base,".env"),defaults:b.default.join((0,y.getPaths)().base,".env.defaults"),multiline:!0}),process.env.REDWOOD_ENV_FILES_LOADED="true");(0,P.default)((0,_.hideBin)(process.argv)).scriptName("data-migrate").command("$0",k,A,O).parse();
3
+ ${H}
4
+ `)),process.exitCode=0;return}let s={run:0,skipped:0,error:0},n=o.map(p=>{let D=m.default.basename(p.path,".js");return{title:D,skip(){return s.error>0?(s.skipped++,!0):!1},async task(){i||(0,u.registerApiSideBabelHook)();try{let{startedAt:g,finishedAt:I}=await G(e,p.path);s.run++,await T(e,{version:p.version,name:D,startedAt:g,finishedAt:I})}catch(g){s.error++,console.error(c.error(`Error in data migration: ${g.message}`))}}}}),l=new C.Listr(n,{renderer:"verbose"});try{await l.run(),await e.$disconnect(),console.log(),j(s),console.log(),s.error&&(process.exitCode=1)}catch{process.exitCode=1,await e.$disconnect(),console.log(),j(s),console.log()}}async function B(t){let r=(0,h.getPaths)().api.dataMigrations;if(!f.default.existsSync(r))return[];let e=f.default.readdirSync(r).filter(n=>["js",".ts"].some(l=>n.endsWith(l))).map(n=>{let[l]=n.split("-");return{version:l,path:m.default.join(r,n)}}),o=(await t.rW_DataMigration.findMany({orderBy:{version:"asc"}})).map(n=>n.version.toString());return e.filter(({version:n})=>!o.includes(n)).sort(q)}function q(t,r){let e=parseInt(t.version),i=parseInt(r.version);return e>i?1:e<i?-1:0}async function G(t,r){let e=require(r),i=new Date;return await e.default({db:t}),{startedAt:i,finishedAt:new Date}}async function T(t,{version:r,name:e,startedAt:i,finishedAt:o}){await t.rW_DataMigration.create({data:{version:r,name:e,startedAt:i,finishedAt:o}})}function j(t){t.run&&console.info(c.success(`${t.run} data migration(s) completed successfully.`)),t.error&&console.error(c.error(`${t.error} data migration(s) exited with errors.`)),t.skipped&&console.warn(c.warning(`${t.skipped} data migration(s) skipped due to previous error.`))}var f,m,C,u,h,H,$=w(()=>{"use strict";f=d(require("fs")),m=d(require("path")),C=require("listr2"),u=require("@cedarjs/babel-config"),h=require("@cedarjs/project-config");E();H="No pending data migrations run, already up-to-date."});var b=d(require("path")),S=require("dotenv-defaults"),_=require("yargs/helpers"),P=d(require("yargs/yargs")),y=require("@cedarjs/project-config");var v=d(require("terminal-link")),x=require("@cedarjs/project-config");var k="Run any outstanding Data Migrations against the database";function A(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:(0,x.getPaths)().api.dist}).epilogue(`Also see the ${(0,v.default)("Redwood CLI Reference","https://redwoodjs.com/docs/cli-commands#datamigrate-up")}`)}$();process.env.REDWOOD_ENV_FILES_LOADED||((0,S.config)({path:b.default.join((0,y.getPaths)().base,".env"),defaults:b.default.join((0,y.getPaths)().base,".env.defaults"),multiline:!0}),process.env.REDWOOD_ENV_FILES_LOADED="true");(0,P.default)((0,_.hideBin)(process.argv)).scriptName("data-migrate").command("$0",k,A,O).parse();
@@ -1 +1 @@
1
- {"version":3,"file":"installHandler.d.ts","sourceRoot":"","sources":["../../src/commands/installHandler.ts"],"names":[],"mappings":"AAUA,wBAAsB,OAAO,kBAsD5B;AAED,eAAO,MAAM,uBAAuB,8HAMlC,CAAA;AAEF,eAAO,MAAM,8BAA8B,2EAC+B,CAAA;AAE1E,eAAO,MAAM,KAAK,QAMN,CAAA"}
1
+ {"version":3,"file":"installHandler.d.ts","sourceRoot":"","sources":["../../src/commands/installHandler.ts"],"names":[],"mappings":"AAUA,wBAAsB,OAAO,kBAmD5B;AAED,eAAO,MAAM,uBAAuB,8HAMlC,CAAA;AAEF,eAAO,MAAM,8BAA8B,2EAC+B,CAAA;AAE1E,eAAO,MAAM,KAAK,QAMN,CAAA"}
@@ -34,9 +34,9 @@ __export(installHandler_exports, {
34
34
  notes: () => notes
35
35
  });
36
36
  module.exports = __toCommonJS(installHandler_exports);
37
- var import_node_fs = __toESM(require("node:fs"));
38
- var import_node_path = __toESM(require("node:path"));
37
+ var import_path = __toESM(require("path"));
39
38
  var import_execa = __toESM(require("execa"));
39
+ var import_fs_extra = __toESM(require("fs-extra"));
40
40
  var import_listr2 = require("listr2");
41
41
  var import_project_config = require("@cedarjs/project-config");
42
42
  var import_colors = __toESM(require("../lib/colors"));
@@ -47,11 +47,8 @@ async function handler() {
47
47
  {
48
48
  title: "Creating the dataMigrations directory...",
49
49
  task() {
50
- import_node_fs.default.mkdirSync(redwoodProjectPaths.api.dataMigrations, {
51
- recursive: true
52
- });
53
- import_node_fs.default.writeFileSync(
54
- import_node_path.default.join(redwoodProjectPaths.api.dataMigrations, ".keep"),
50
+ import_fs_extra.default.outputFileSync(
51
+ import_path.default.join(redwoodProjectPaths.api.dataMigrations, ".keep"),
55
52
  ""
56
53
  );
57
54
  }
@@ -60,8 +57,8 @@ async function handler() {
60
57
  title: "Adding the RW_DataMigration model to schema.prisma...",
61
58
  task() {
62
59
  const dbSchemaFilePath = redwoodProjectPaths.api.dbSchema;
63
- const dbSchemaFileContent = import_node_fs.default.readFileSync(dbSchemaFilePath, "utf-8");
64
- import_node_fs.default.writeFileSync(
60
+ const dbSchemaFileContent = import_fs_extra.default.readFileSync(dbSchemaFilePath, "utf-8");
61
+ import_fs_extra.default.writeFileSync(
65
62
  dbSchemaFilePath,
66
63
  [dbSchemaFileContent.trim(), "", RW_DATA_MIGRATION_MODEL, ""].join(
67
64
  "\n"
@@ -176,7 +176,7 @@ function sortDataMigrationsByVersion(dataMigrationA, dataMigrationB) {
176
176
  return 0;
177
177
  }
178
178
  async function runDataMigration(db, dataMigrationPath) {
179
- const dataMigration = await import(dataMigrationPath);
179
+ const dataMigration = require(dataMigrationPath);
180
180
  const startedAt = /* @__PURE__ */ new Date();
181
181
  await dataMigration.default({ db });
182
182
  const finishedAt = /* @__PURE__ */ new Date();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli-data-migrate",
3
- "version": "1.0.0-canary.12310+fb14aa278",
3
+ "version": "1.0.0-canary.12312+d68f44bdf",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -21,12 +21,12 @@
21
21
  "build:types": "tsc --build --verbose",
22
22
  "prepublishOnly": "NODE_ENV=production yarn build",
23
23
  "test": "yarn test:unit && yarn test:dist",
24
- "test:dist": "yarn vitest run ./dist.test.ts",
25
- "test:unit": "yarn vitest run src/"
24
+ "test:dist": "yarn jest ./dist.test.ts",
25
+ "test:unit": "yarn jest src"
26
26
  },
27
27
  "dependencies": {
28
- "@cedarjs/babel-config": "1.0.0-canary.12310",
29
- "@cedarjs/project-config": "1.0.0-canary.12310",
28
+ "@cedarjs/babel-config": "1.0.0-canary.12312",
29
+ "@cedarjs/project-config": "1.0.0-canary.12312",
30
30
  "chalk": "4.1.2",
31
31
  "dotenv-defaults": "5.0.2",
32
32
  "execa": "5.1.1",
@@ -36,14 +36,14 @@
36
36
  "yargs": "17.7.2"
37
37
  },
38
38
  "devDependencies": {
39
- "@cedarjs/framework-tools": "1.0.0-canary.12310",
39
+ "@cedarjs/framework-tools": "1.0.0-canary.12312",
40
40
  "@prisma/client": "5.20.0",
41
41
  "@types/fs-extra": "11.0.4",
42
42
  "@types/yargs": "17.0.33",
43
+ "jest": "29.7.0",
43
44
  "memfs": "4.17.2",
44
45
  "tsx": "4.19.4",
45
- "typescript": "5.6.2",
46
- "vitest": "2.1.9"
46
+ "typescript": "5.6.2"
47
47
  },
48
- "gitHead": "fb14aa278177f0db30e6b03223ccfe02163a9f5e"
48
+ "gitHead": "d68f44bdff95ab34e366a37722af588649d8f046"
49
49
  }