@cedarjs/cli-data-migrate 1.0.0-canary.12311 → 1.0.0-canary.12316

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
- "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();
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 c=(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,m,C=w(()=>{"use strict";a=c(require("chalk")),m={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(!g.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=f.default.join(r,"lib"),d=f.default.join(p,"db.js");if(!g.default.existsSync(d)){console.error(`Can't find db.js at ${d}. CedarJS expects the db.js file to be in the ${p} directory`),process.exitCode=1;return}e=(await import(d)).db}else(0,h.registerApiSideBabelHook)(),i=!0,e=require(f.default.join((0,b.getPaths)().api.lib,"db")).db;let o=await B(e);if(!o.length){console.info(m.success(`
3
+ ${H}
4
+ `)),process.exitCode=0;return}let s={run:0,skipped:0,error:0},n=o.map(p=>{let d=f.default.basename(p.path,".js");return{title:d,skip(){return s.error>0?(s.skipped++,!0):!1},async task(){i||(0,h.registerApiSideBabelHook)();try{let{startedAt:u,finishedAt:I}=await G(e,p.path);s.run++,await T(e,{version:p.version,name:d,startedAt:u,finishedAt:I})}catch(u){s.error++,console.error(m.error(`Error in data migration: ${u.message}`))}}}}),l=new j.Listr(n,{renderer:"verbose"});try{await l.run(),await e.$disconnect(),console.log(),E(s),console.log(),s.error&&(process.exitCode=1)}catch{process.exitCode=1,await e.$disconnect(),console.log(),E(s),console.log()}}async function B(t){let r=(0,b.getPaths)().api.dataMigrations;if(!g.default.existsSync(r))return[];let e=g.default.readdirSync(r).filter(n=>["js",".ts"].some(l=>n.endsWith(l))).map(n=>{let[l]=n.split("-");return{version:l,path:f.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 E(t){t.run&&console.info(m.success(`${t.run} data migration(s) completed successfully.`)),t.error&&console.error(m.error(`${t.error} data migration(s) exited with errors.`)),t.skipped&&console.warn(m.warning(`${t.skipped} data migration(s) skipped due to previous error.`))}var g,f,j,h,b,H,P=w(()=>{"use strict";g=c(require("fs")),f=c(require("path")),j=require("listr2"),h=require("@cedarjs/babel-config"),b=require("@cedarjs/project-config");C();H="No pending data migrations run, already up-to-date."});var y=c(require("path")),S=require("dotenv-defaults"),$=require("yargs/helpers"),_=c(require("yargs/yargs")),D=require("@cedarjs/project-config");var v=c(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")}`)}P();process.env.REDWOOD_ENV_FILES_LOADED||((0,S.config)({path:y.default.join((0,D.getPaths)().base,".env"),defaults:y.default.join((0,D.getPaths)().base,".env.defaults"),multiline:!0}),process.env.REDWOOD_ENV_FILES_LOADED="true");(0,_.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"
@@ -52,13 +52,11 @@ async function handler({
52
52
  process.exitCode = 1;
53
53
  return;
54
54
  }
55
- const distLibDbPath = import_path.default.join(distPath, "lib", "db.js");
55
+ const distLibPath = import_path.default.join(distPath, "lib");
56
+ const distLibDbPath = import_path.default.join(distLibPath, "db.js");
56
57
  if (!import_fs.default.existsSync(distLibDbPath)) {
57
58
  console.error(
58
- `Can't find db.js at ${distLibDbPath}. Redwood expects the db.js file to be in the ${import_path.default.join(
59
- distPath,
60
- "lib"
61
- )} directory`
59
+ `Can't find db.js at ${distLibDbPath}. CedarJS expects the db.js file to be in the ${distLibPath} directory`
62
60
  );
63
61
  process.exitCode = 1;
64
62
  return;
@@ -176,7 +174,7 @@ function sortDataMigrationsByVersion(dataMigrationA, dataMigrationB) {
176
174
  return 0;
177
175
  }
178
176
  async function runDataMigration(db, dataMigrationPath) {
179
- const dataMigration = await import(dataMigrationPath);
177
+ const dataMigration = require(dataMigrationPath);
180
178
  const startedAt = /* @__PURE__ */ new Date();
181
179
  await dataMigration.default({ db });
182
180
  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.12311+42cf2e406",
3
+ "version": "1.0.0-canary.12316+9fbbf96b8",
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.12311",
29
- "@cedarjs/project-config": "1.0.0-canary.12311",
28
+ "@cedarjs/babel-config": "1.0.0-canary.12316",
29
+ "@cedarjs/project-config": "1.0.0-canary.12316",
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.12311",
39
+ "@cedarjs/framework-tools": "1.0.0-canary.12316",
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": "42cf2e406127f07e7047bb9bae543d35e6e731b7"
48
+ "gitHead": "9fbbf96b848616acb9561c86b887e355c92ef351"
49
49
  }