@samhammer/migrate-mongo-sag 0.0.1 → 0.0.2

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.
@@ -1,2 +1,2 @@
1
1
  #! /usr/bin/env node
2
- "use strict";const s=require("migrate-mongo"),l=require("commander"),i=require("dotenv"),p=require("dotenv-expand"),m=require("@samhammer/vault-client-sag"),c=require("lodash"),g=require("child_process"),u="@samhammer/migrate-mongo-sag",v="0.0.1",h="dist/migrate-mongo.js",b={"migrate-mongo":"dist/migrate-mongo.js"},y=["dist/**/*"],f=["mongodb","migration"],E="SamhammerAG",w="MIT",R={build:"vite build","migrate-mongo":"vite build && npx .",format:"prettier --write --parser typescript ./src",lint:"eslint ./src",test:"vitest run"},D={node:"18.19.0",yarn:"4.0.2"},$={"@rushstack/eslint-patch":"^1.10.3","@types/lodash":"^4","@types/migrate-mongo":"^10.0.4","@types/node":"^18.0.0","@typescript-eslint/eslint-plugin":"^7.11.0","@typescript-eslint/parser":"^7.11.0",eslint:"^8.57.0","eslint-config-prettier":"^8.10.0","eslint-plugin-import":"^2.29.1","eslint-plugin-prettier":"^5.1.3",prettier:"^3.2.5",typescript:"^5.4.5",vite:"^5.2.12",vitest:"^1.6.0"},x={"@samhammer/vault-client-sag":"^1.1.0",commander:"^12.1.0",dotenv:"^16.4.5","dotenv-expand":"^11.0.6",lodash:"^4.17.21","migrate-mongo":"^11.0.0",mongodb:"^4.17.2"},k={name:u,version:v,main:h,bin:b,files:y,keywords:f,author:E,license:w,scripts:R,volta:D,devDependencies:$,dependencies:x};async function O(n){S(n),q();const e=[".env.local",".env"],t=A(e);await(await m.getVault()).loadSecretsToEnv(t);const o=i.config({path:e});p.expand({parsed:o.parsed})}function A(n){const e=c.clone(process.env),t=i.config({path:n,processEnv:e}),a=c.pickBy(t.parsed,d=>d.startsWith("VaultKey")),o=p.expand({parsed:a,processEnv:e});return c.invert(o.parsed)}async function S(n){const e=n.getOptionValue("env"),t=n.getOptionValue("brand"),a=n.getOptionValue("app"),o={};e&&(o.Env=e),t&&(o.Brand=t),a&&(o.App=a),i.populate(process.env,o,{override:!0})}function q(){if(process.env.Branch)return;const e={Branch:g.execSync("git rev-parse --abbrev-ref HEAD").toString("utf-8").replace(/[\n\r\s]+$/,"")};i.populate(process.env,e)}const r=new l.Command;r.name("migrate-mongo").description("CLI to migrate mongodb").version(k.version).option("-e, --env <env>","set environment").option("-b, --brand <brand>","set brand").option("-a, --app <app>","set app");r.hook("preSubcommand",async n=>{await O(n)});r.command("create [description]").description("create a new database migration with the provided description").action(async n=>{try{const e=s.create(n),t=await s.config.read();console.log(`CREATED: ${t.migrationsDir}/${e}`)}catch(e){console.error(`ERROR: ${e.message}`,e.stack),process.exit(1)}});r.command("up").description("run all pending database migrations").action(async()=>{const{db:n,client:e}=await s.database.connect();try{(await s.up(n,e)).forEach(a=>console.log(`MIGRATED UP: ${a}`))}catch(t){console.error(`ERROR: ${t.message}`,t.stack),t.migrated.forEach(a=>console.log(`MIGRATED UP: ${a}`)),process.exit(1)}finally{await e.close()}});r.command("down").description("undo the last applied database migration").action(async()=>{const{db:n,client:e}=await s.database.connect();try{(await s.down(n,e)).forEach(a=>console.log(`MIGRATED DOWN: ${a}`))}catch(t){console.error(`ERROR: ${t.message}`,t.stack),process.exit(1)}finally{await e.close()}});r.command("status").description("print the changelog of the database").action(async()=>{const{db:n,client:e}=await s.database.connect();try{(await s.status(n)).forEach(a=>console.log(`APPLIED: ${a.appliedAt} - ${a.fileName}`))}catch(t){console.error(`ERROR: ${t.message}`,t.stack),process.exit(1)}finally{await e.close()}});r.command("dropDatabase").description("deletes the database").action(()=>{console.log("TODO dropDatabase")});r.parse();
2
+ "use strict";const o=require("migrate-mongo"),p=require("commander"),i=require("dotenv"),d=require("dotenv-expand"),m=require("@samhammer/vault-client-sag"),c=require("lodash"),g=require("child_process"),u="@samhammer/migrate-mongo-sag",v="0.0.2",f="dist/migrate-mongo.js",b={"migrate-mongo":"dist/migrate-mongo.js"},h=["dist/**/*"],y=["mongodb","migration"],w="SamhammerAG",E="MIT",R={build:"vite build","migrate-mongo":"vite build && npx .",format:"prettier --write --parser typescript ./src",lint:"eslint ./src",test:"vitest run"},x={"@rushstack/eslint-patch":"^1.10.3","@types/lodash":"^4","@types/migrate-mongo":"^8.2.0","@types/node":"^18.0.0","@typescript-eslint/eslint-plugin":"^7.11.0","@typescript-eslint/parser":"^7.11.0",eslint:"^8.57.0","eslint-config-prettier":"^8.10.0","eslint-plugin-import":"^2.29.1","eslint-plugin-prettier":"^5.1.3",prettier:"^3.2.5",typescript:"^5.4.5",vite:"^5.2.12",vitest:"^1.6.0"},D={"@samhammer/vault-client-sag":"^1.1.0",commander:"^12.1.0",dotenv:"^16.4.5","dotenv-expand":"^11.0.6",lodash:"^4.17.21","migrate-mongo":"^9.0.0",mongodb:"^4.17.2"},N={node:"18.19.0",yarn:"4.0.2"},$={name:u,version:v,main:f,bin:b,files:h,keywords:y,author:w,license:E,scripts:R,devDependencies:x,dependencies:D,volta:N};async function k(n){S(n),q();const e=[".env.local",".env"],t=O(e);await(await m.getVault()).loadSecretsToEnv(t);const s=i.config({path:e});d.expand({parsed:s.parsed})}function O(n){const e=c.clone(process.env),t=i.config({path:n,processEnv:e}),a=c.pickBy(t.parsed,l=>l.startsWith("VaultKey")),s=d.expand({parsed:a,processEnv:e});return c.invert(s.parsed)}async function S(n){const e=n.getOptionValue("env"),t=n.getOptionValue("brand"),a=n.getOptionValue("suffix"),s={};e&&(s.Environment=e),t&&(s.Brand=t),a&&(s.Suffix=a),i.populate(process.env,s,{override:!0})}function q(){if(process.env.Branch)return;const e={Branch:g.execSync("git rev-parse --abbrev-ref HEAD").toString("utf-8").replace(/[\n\r\s]+$/,"")};i.populate(process.env,e)}async function A(n){const e=process.env.MongoDbOptions__UserName;return e&&await n.removeUser(e),await n.dropDatabase(),{databaseName:n.databaseName,userName:e??""}}const r=new p.Command;r.name("migrate-mongo").description("CLI to migrate mongodb").version($.version).option("-e, --env <env>","set process.env.Environment").option("-b, --brand <brand>","set process.env.Brand").option("-s, --suffix <suffix>","set process.env.Suffix");r.hook("preSubcommand",async n=>{await k(n)});r.command("create [description]").description("create a new database migration with the provided description").action(async n=>{try{const e=o.create(n),t=await o.config.read();console.log(`CREATED: ${t.migrationsDir}/${e}`)}catch(e){console.error(`ERROR: ${e.message}`,e.stack),process.exit(1)}});r.command("up").description("run all pending database migrations").action(async()=>{const{db:n,client:e}=await o.database.connect();try{(await o.up(n,e)).forEach(a=>console.log(`MIGRATED UP: ${a}`))}catch(t){console.error(`ERROR: ${t.message}`,t.stack),t.migrated.forEach(a=>console.log(`MIGRATED UP: ${a}`)),process.exit(1)}finally{await e.close()}});r.command("down").description("undo the last applied database migration").action(async()=>{const{db:n,client:e}=await o.database.connect();try{(await o.down(n,e)).forEach(a=>console.log(`MIGRATED DOWN: ${a}`))}catch(t){console.error(`ERROR: ${t.message}`,t.stack),process.exit(1)}finally{await e.close()}});r.command("status").description("print the changelog of the database").action(async()=>{const{db:n,client:e}=await o.database.connect();try{(await o.status(n)).forEach(a=>console.log(`${a.appliedAt}: ${a.fileName}`))}catch(t){console.error(`ERROR: ${t.message}`,t.stack),process.exit(1)}finally{await e.close()}});r.command("dropDatabase").description("deletes the database").action(async()=>{const{db:n,client:e}=await o.database.connect();try{const t=await A(n);console.log("DROPPED DB:",t.databaseName,t.userName)}catch(t){console.error(`ERROR: ${t.message}`,t.stack),process.exit(1)}finally{await e.close()}});r.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samhammer/migrate-mongo-sag",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "main": "dist/migrate-mongo.js",
5
5
  "bin": {
6
6
  "migrate-mongo": "dist/migrate-mongo.js"
@@ -21,14 +21,10 @@
21
21
  "lint": "eslint ./src",
22
22
  "test": "vitest run"
23
23
  },
24
- "volta": {
25
- "node": "18.19.0",
26
- "yarn": "4.0.2"
27
- },
28
24
  "devDependencies": {
29
25
  "@rushstack/eslint-patch": "^1.10.3",
30
26
  "@types/lodash": "^4",
31
- "@types/migrate-mongo": "^10.0.4",
27
+ "@types/migrate-mongo": "^8.2.0",
32
28
  "@types/node": "^18.0.0",
33
29
  "@typescript-eslint/eslint-plugin": "^7.11.0",
34
30
  "@typescript-eslint/parser": "^7.11.0",
@@ -47,7 +43,11 @@
47
43
  "dotenv": "^16.4.5",
48
44
  "dotenv-expand": "^11.0.6",
49
45
  "lodash": "^4.17.21",
50
- "migrate-mongo": "^11.0.0",
46
+ "migrate-mongo": "^9.0.0",
51
47
  "mongodb": "^4.17.2"
48
+ },
49
+ "volta": {
50
+ "node": "18.19.0",
51
+ "yarn": "4.0.2"
52
52
  }
53
53
  }