@memberjunction/cli 1.8.1 → 2.1.1

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/README.md CHANGED
@@ -12,7 +12,7 @@ $ npm install -g @memberjunction/cli
12
12
  $ mj COMMAND
13
13
  running command...
14
14
  $ mj (--version)
15
- @memberjunction/cli/1.8.1 linux-x64 node-v20.14.0
15
+ @memberjunction/cli/2.1.1 linux-x64 node-v20.15.1
16
16
  $ mj --help [COMMAND]
17
17
  USAGE
18
18
  $ mj COMMAND
@@ -21,10 +21,32 @@ USAGE
21
21
  <!-- usagestop -->
22
22
  # Commands
23
23
  <!-- commands -->
24
+ * [`mj clean`](#mj-clean)
24
25
  * [`mj help [COMMAND]`](#mj-help-command)
25
26
  * [`mj install`](#mj-install)
27
+ * [`mj migrate`](#mj-migrate)
26
28
  * [`mj version`](#mj-version)
27
29
 
30
+ ## `mj clean`
31
+
32
+ Resets the MemberJunction database to a pre-installation state
33
+
34
+ ```
35
+ USAGE
36
+ $ mj clean [-v]
37
+
38
+ FLAGS
39
+ -v, --verbose Enable additional logging
40
+
41
+ DESCRIPTION
42
+ Resets the MemberJunction database to a pre-installation state
43
+
44
+ EXAMPLES
45
+ $ mj clean
46
+ ```
47
+
48
+ _See code: [src/commands/clean/index.ts](https://github.com/MemberJunction/MJ/blob/v2.1.1/src/commands/clean/index.ts)_
49
+
28
50
  ## `mj help [COMMAND]`
29
51
 
30
52
  Display help for mj.
@@ -43,7 +65,7 @@ DESCRIPTION
43
65
  Display help for mj.
44
66
  ```
45
67
 
46
- _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.0/src/commands/help.ts)_
68
+ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.3/src/commands/help.ts)_
47
69
 
48
70
  ## `mj install`
49
71
 
@@ -63,7 +85,27 @@ EXAMPLES
63
85
  $ mj install
64
86
  ```
65
87
 
66
- _See code: [src/commands/install/index.ts](https://github.com/MemberJunction/MJ/blob/v1.8.1/src/commands/install/index.ts)_
88
+ _See code: [src/commands/install/index.ts](https://github.com/MemberJunction/MJ/blob/v2.1.1/src/commands/install/index.ts)_
89
+
90
+ ## `mj migrate`
91
+
92
+ Migrate MemberJunction database to latest version
93
+
94
+ ```
95
+ USAGE
96
+ $ mj migrate [-v]
97
+
98
+ FLAGS
99
+ -v, --verbose Enable additional logging
100
+
101
+ DESCRIPTION
102
+ Migrate MemberJunction database to latest version
103
+
104
+ EXAMPLES
105
+ $ mj migrate
106
+ ```
107
+
108
+ _See code: [src/commands/migrate/index.ts](https://github.com/MemberJunction/MJ/blob/v2.1.1/src/commands/migrate/index.ts)_
67
109
 
68
110
  ## `mj version`
69
111
 
@@ -83,5 +125,5 @@ FLAG DESCRIPTIONS
83
125
  Additionally shows the architecture, node version, operating system, and versions of plugins that the CLI is using.
84
126
  ```
85
127
 
86
- _See code: [@oclif/plugin-version](https://github.com/oclif/plugin-version/blob/v2.2.2/src/commands/version.ts)_
128
+ _See code: [@oclif/plugin-version](https://github.com/oclif/plugin-version/blob/v2.2.4/src/commands/version.ts)_
87
129
  <!-- commandsstop -->
@@ -0,0 +1,11 @@
1
+ import { Command } from '@oclif/core';
2
+ import { ParserOutput } from '@oclif/core/lib/interfaces/parser';
3
+ export default class Clean extends Command {
4
+ static description: string;
5
+ static examples: string[];
6
+ static flags: {
7
+ verbose: import("@oclif/core/lib/interfaces/parser").BooleanFlag<boolean>;
8
+ };
9
+ flags: ParserOutput<Clean>['flags'];
10
+ run(): Promise<void>;
11
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const core_1 = require("@oclif/core");
7
+ const node_flyway_1 = require("node-flyway");
8
+ const config_1 = require("../../config");
9
+ const ora_classic_1 = __importDefault(require("ora-classic"));
10
+ class Clean extends core_1.Command {
11
+ static description = 'Resets the MemberJunction database to a pre-installation state';
12
+ static examples = [
13
+ `<%= config.bin %> <%= command.id %>
14
+ `,
15
+ ];
16
+ static flags = {
17
+ verbose: core_1.Flags.boolean({ char: 'v', description: 'Enable additional logging' }),
18
+ };
19
+ flags;
20
+ async run() {
21
+ const parsed = await this.parse(Clean);
22
+ this.flags = parsed.flags;
23
+ if (!config_1.config) {
24
+ this.error('No configuration found');
25
+ }
26
+ const flywayConfig = (0, config_1.getFlywayConfig)(config_1.config);
27
+ const flyway = new node_flyway_1.Flyway(flywayConfig);
28
+ this.log('Resetting MJ database to pre-installation state');
29
+ this.log('Note that users and roles have not been dropped');
30
+ const spinner = (0, ora_classic_1.default)('Cleaning up...');
31
+ spinner.start();
32
+ const result = await flyway.clean();
33
+ if (result.success) {
34
+ spinner.succeed();
35
+ this.log(`The database has been reset. Schemas dropped:\n\t- ${result.flywayResponse?.schemasDropped.join('\n\t- ')}`);
36
+ }
37
+ else {
38
+ spinner.fail();
39
+ if (result.error) {
40
+ this.logToStderr(result.error.message);
41
+ if (this.flags.verbose) {
42
+ this.logToStderr(`ERROR CODE: ${result.error.errorCode}`);
43
+ this.logToStderr(result.error.stackTrace);
44
+ }
45
+ }
46
+ this.error('Command failed');
47
+ }
48
+ }
49
+ }
50
+ exports.default = Clean;
@@ -28,12 +28,12 @@ declare const configSchema: z.ZodObject<{
28
28
  anthropicAPIKey: z.ZodOptional<z.ZodString>;
29
29
  mistralAPIKey: z.ZodOptional<z.ZodString>;
30
30
  }, "strip", z.ZodTypeAny, {
31
- dbUrl: string;
32
- dbInstance: string;
33
- dbTrustServerCertificate: "N" | "Y";
34
31
  dbDatabase: string;
35
32
  dbPort: number;
36
33
  codeGenLogin: string;
34
+ dbTrustServerCertificate: "Y" | "N";
35
+ dbUrl: string;
36
+ dbInstance: string;
37
37
  codeGenPwD: string;
38
38
  mjAPILogin: string;
39
39
  mjAPIPwD: string;
@@ -45,7 +45,7 @@ declare const configSchema: z.ZodObject<{
45
45
  auth0ClientId?: string | undefined;
46
46
  auth0ClientSecret?: string | undefined;
47
47
  auth0Domain?: string | undefined;
48
- createNewUser?: "N" | "Y" | undefined;
48
+ createNewUser?: "Y" | "N" | undefined;
49
49
  userFirstName?: string | undefined;
50
50
  userLastName?: string | undefined;
51
51
  userName?: string | undefined;
@@ -53,12 +53,12 @@ declare const configSchema: z.ZodObject<{
53
53
  anthropicAPIKey?: string | undefined;
54
54
  mistralAPIKey?: string | undefined;
55
55
  }, {
56
- dbUrl: string;
57
- dbInstance: string;
58
- dbTrustServerCertificate: "N" | "Y";
59
56
  dbDatabase: string;
60
57
  dbPort: number;
61
58
  codeGenLogin: string;
59
+ dbTrustServerCertificate: "Y" | "N";
60
+ dbUrl: string;
61
+ dbInstance: string;
62
62
  codeGenPwD: string;
63
63
  mjAPILogin: string;
64
64
  mjAPIPwD: string;
@@ -69,7 +69,7 @@ declare const configSchema: z.ZodObject<{
69
69
  auth0ClientId?: string | undefined;
70
70
  auth0ClientSecret?: string | undefined;
71
71
  auth0Domain?: string | undefined;
72
- createNewUser?: "N" | "Y" | undefined;
72
+ createNewUser?: "Y" | "N" | undefined;
73
73
  userEmail?: string | undefined;
74
74
  userFirstName?: string | undefined;
75
75
  userLastName?: string | undefined;
@@ -88,12 +88,12 @@ export default class Install extends Command {
88
88
  userConfig: Config;
89
89
  run(): Promise<void>;
90
90
  getUserConfiguration(): Promise<{
91
- dbUrl: string;
92
- dbInstance: string;
93
- dbTrustServerCertificate: "N" | "Y";
94
91
  dbDatabase: string;
95
92
  dbPort: number;
96
93
  codeGenLogin: string;
94
+ dbTrustServerCertificate: "Y" | "N";
95
+ dbUrl: string;
96
+ dbInstance: string;
97
97
  codeGenPwD: string;
98
98
  mjAPILogin: string;
99
99
  mjAPIPwD: string;
@@ -105,7 +105,7 @@ export default class Install extends Command {
105
105
  auth0ClientId?: string | undefined;
106
106
  auth0ClientSecret?: string | undefined;
107
107
  auth0Domain?: string | undefined;
108
- createNewUser?: "N" | "Y" | undefined;
108
+ createNewUser?: "Y" | "N" | undefined;
109
109
  userFirstName?: string | undefined;
110
110
  userLastName?: string | undefined;
111
111
  userName?: string | undefined;
@@ -0,0 +1,11 @@
1
+ import { Command } from '@oclif/core';
2
+ import { ParserOutput } from '@oclif/core/lib/interfaces/parser';
3
+ export default class Migrate extends Command {
4
+ static description: string;
5
+ static examples: string[];
6
+ static flags: {
7
+ verbose: import("@oclif/core/lib/interfaces/parser").BooleanFlag<boolean>;
8
+ };
9
+ flags: ParserOutput<Migrate>['flags'];
10
+ run(): Promise<void>;
11
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const core_1 = require("@oclif/core");
7
+ const node_flyway_1 = require("node-flyway");
8
+ const config_1 = require("../../config");
9
+ const ora_classic_1 = __importDefault(require("ora-classic"));
10
+ class Migrate extends core_1.Command {
11
+ static description = 'Migrate MemberJunction database to latest version';
12
+ static examples = [
13
+ `<%= config.bin %> <%= command.id %>
14
+ `,
15
+ ];
16
+ static flags = {
17
+ verbose: core_1.Flags.boolean({ char: 'v', description: 'Enable additional logging' }),
18
+ };
19
+ flags;
20
+ async run() {
21
+ const parsed = await this.parse(Migrate);
22
+ this.flags = parsed.flags;
23
+ if (!config_1.config) {
24
+ this.error('No configuration found');
25
+ }
26
+ const flywayConfig = (0, config_1.getFlywayConfig)(config_1.config);
27
+ const flyway = new node_flyway_1.Flyway(flywayConfig);
28
+ if (this.flags.verbose) {
29
+ this.log(`Connecting to ${flywayConfig.url}`);
30
+ this.log(`Migrating ${config_1.config.coreSchema} schema using migrations from:\n\t- ${flywayConfig.migrationLocations.join('\n\t- ')}\n`);
31
+ }
32
+ const spinner = (0, ora_classic_1.default)('Running migrations...');
33
+ spinner.start();
34
+ const result = await flyway.migrate();
35
+ if (result.success) {
36
+ spinner.succeed();
37
+ this.log(`Migrations complete in ${result.additionalDetails.executionTime / 1000}s`);
38
+ if (result.flywayResponse?.success && this.flags.verbose) {
39
+ this.log(`\tUpdated to ${result.flywayResponse?.targetSchemaVersion}`);
40
+ }
41
+ }
42
+ else {
43
+ spinner.fail();
44
+ if (result.error) {
45
+ this.logToStderr(result.error.message);
46
+ if (this.flags.verbose) {
47
+ this.logToStderr(`ERROR CODE: ${result.error.errorCode}`);
48
+ this.logToStderr(result.error.stackTrace);
49
+ }
50
+ }
51
+ this.error('Migrations failed');
52
+ }
53
+ }
54
+ }
55
+ exports.default = Migrate;
@@ -0,0 +1,48 @@
1
+ import { z } from 'zod';
2
+ import { FlywayConfig } from 'node-flyway/dist/types/types';
3
+ export type MJConfig = z.infer<typeof mjConfigSchema>;
4
+ declare const mjConfigSchema: z.ZodObject<{
5
+ dbHost: z.ZodDefault<z.ZodString>;
6
+ dbDatabase: z.ZodString;
7
+ dbPort: z.ZodDefault<z.ZodNumber>;
8
+ codeGenLogin: z.ZodString;
9
+ codeGenPassword: z.ZodString;
10
+ migrationsLocation: z.ZodDefault<z.ZodOptional<z.ZodString>>;
11
+ dbTrustServerCertificate: z.ZodDefault<z.ZodEnum<["Y", "N"]>>;
12
+ coreSchema: z.ZodDefault<z.ZodOptional<z.ZodString>>;
13
+ cleanDisabled: z.ZodDefault<z.ZodBoolean>;
14
+ }, "strip", z.ZodTypeAny, {
15
+ cleanDisabled: boolean;
16
+ dbHost: string;
17
+ dbDatabase: string;
18
+ dbPort: number;
19
+ codeGenLogin: string;
20
+ codeGenPassword: string;
21
+ migrationsLocation: string;
22
+ dbTrustServerCertificate: "Y" | "N";
23
+ coreSchema: string;
24
+ }, {
25
+ dbDatabase: string;
26
+ codeGenLogin: string;
27
+ codeGenPassword: string;
28
+ cleanDisabled?: boolean | undefined;
29
+ dbHost?: string | undefined;
30
+ dbPort?: number | undefined;
31
+ migrationsLocation?: string | undefined;
32
+ dbTrustServerCertificate?: "Y" | "N" | undefined;
33
+ coreSchema?: string | undefined;
34
+ }>;
35
+ export declare const config: {
36
+ cleanDisabled: boolean;
37
+ dbHost: string;
38
+ dbDatabase: string;
39
+ dbPort: number;
40
+ codeGenLogin: string;
41
+ codeGenPassword: string;
42
+ migrationsLocation: string;
43
+ dbTrustServerCertificate: "Y" | "N";
44
+ coreSchema: string;
45
+ } | undefined;
46
+ export declare const createFlywayUrl: (mjConfig: MJConfig) => string;
47
+ export declare const getFlywayConfig: (mjConfig: MJConfig) => FlywayConfig;
48
+ export {};
package/dist/config.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFlywayConfig = exports.createFlywayUrl = exports.config = void 0;
4
+ const zod_1 = require("zod");
5
+ const cosmiconfig_1 = require("cosmiconfig");
6
+ const explorer = (0, cosmiconfig_1.cosmiconfigSync)('mj');
7
+ const result = explorer.search(process.cwd());
8
+ const mjConfigSchema = zod_1.z.object({
9
+ dbHost: zod_1.z.string().default('localhost'),
10
+ dbDatabase: zod_1.z.string(),
11
+ dbPort: zod_1.z.number({ coerce: true }).default(1433),
12
+ codeGenLogin: zod_1.z.string(),
13
+ codeGenPassword: zod_1.z.string(),
14
+ migrationsLocation: zod_1.z.string().optional().default('filesystem:./migrations'),
15
+ dbTrustServerCertificate: zod_1.z.enum(['Y', 'N']).default('Y'),
16
+ coreSchema: zod_1.z.string().optional().default('__mj'),
17
+ cleanDisabled: zod_1.z.boolean().default(true),
18
+ });
19
+ const parsedConfig = mjConfigSchema.safeParse(result?.config);
20
+ exports.config = parsedConfig.success ? parsedConfig.data : undefined;
21
+ const createFlywayUrl = (mjConfig) => {
22
+ return `jdbc:sqlserver://${mjConfig.dbHost}:${mjConfig.dbPort}; databaseName=${mjConfig.dbDatabase}${mjConfig.dbTrustServerCertificate === 'Y' ? '; trustServerCertificate=true' : ''}`;
23
+ };
24
+ exports.createFlywayUrl = createFlywayUrl;
25
+ const getFlywayConfig = (mjConfig) => ({
26
+ url: (0, exports.createFlywayUrl)(mjConfig),
27
+ user: mjConfig.codeGenLogin,
28
+ password: mjConfig.codeGenPassword,
29
+ migrationLocations: [mjConfig.migrationsLocation],
30
+ advanced: { schemas: [mjConfig.coreSchema], cleanDisabled: mjConfig.cleanDisabled === false ? false : undefined },
31
+ });
32
+ exports.getFlywayConfig = getFlywayConfig;
@@ -0,0 +1,3 @@
1
+ import { Hook } from '@oclif/core';
2
+ declare const hook: Hook<'init'>;
3
+ export default hook;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const figlet_1 = __importDefault(require("figlet"));
7
+ const hook = async function (options) {
8
+ console.log(figlet_1.default.textSync('MemberJunction', {
9
+ font: 'Standard',
10
+ horizontalLayout: 'default',
11
+ verticalLayout: 'default',
12
+ width: 100,
13
+ whitespaceBreak: true,
14
+ }));
15
+ };
16
+ exports.default = hook;
@@ -1,5 +1,37 @@
1
1
  {
2
2
  "commands": {
3
+ "clean": {
4
+ "aliases": [],
5
+ "args": {},
6
+ "description": "Resets the MemberJunction database to a pre-installation state",
7
+ "examples": [
8
+ "<%= config.bin %> <%= command.id %>\n"
9
+ ],
10
+ "flags": {
11
+ "verbose": {
12
+ "char": "v",
13
+ "description": "Enable additional logging",
14
+ "name": "verbose",
15
+ "allowNo": false,
16
+ "type": "boolean"
17
+ }
18
+ },
19
+ "hasDynamicHelp": false,
20
+ "hiddenAliases": [],
21
+ "id": "clean",
22
+ "pluginAlias": "@memberjunction/cli",
23
+ "pluginName": "@memberjunction/cli",
24
+ "pluginType": "core",
25
+ "strict": true,
26
+ "enableJsonFlag": false,
27
+ "isESM": false,
28
+ "relativePath": [
29
+ "dist",
30
+ "commands",
31
+ "clean",
32
+ "index.js"
33
+ ]
34
+ },
3
35
  "install": {
4
36
  "aliases": [],
5
37
  "args": {},
@@ -31,7 +63,39 @@
31
63
  "install",
32
64
  "index.js"
33
65
  ]
66
+ },
67
+ "migrate": {
68
+ "aliases": [],
69
+ "args": {},
70
+ "description": "Migrate MemberJunction database to latest version",
71
+ "examples": [
72
+ "<%= config.bin %> <%= command.id %>\n"
73
+ ],
74
+ "flags": {
75
+ "verbose": {
76
+ "char": "v",
77
+ "description": "Enable additional logging",
78
+ "name": "verbose",
79
+ "allowNo": false,
80
+ "type": "boolean"
81
+ }
82
+ },
83
+ "hasDynamicHelp": false,
84
+ "hiddenAliases": [],
85
+ "id": "migrate",
86
+ "pluginAlias": "@memberjunction/cli",
87
+ "pluginName": "@memberjunction/cli",
88
+ "pluginType": "core",
89
+ "strict": true,
90
+ "enableJsonFlag": false,
91
+ "isESM": false,
92
+ "relativePath": [
93
+ "dist",
94
+ "commands",
95
+ "migrate",
96
+ "index.js"
97
+ ]
34
98
  }
35
99
  },
36
- "version": "1.8.1"
100
+ "version": "2.1.1"
37
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/cli",
3
- "version": "1.8.1",
3
+ "version": "2.1.1",
4
4
  "description": "MemberJunction command line tools",
5
5
  "keywords": [
6
6
  "oclif"
@@ -26,7 +26,7 @@
26
26
  "/oclif.manifest.json"
27
27
  ],
28
28
  "scripts": {
29
- "build": "rimraf dist && tsc -b",
29
+ "build": "tsc -b",
30
30
  "prepack": "npm run build && oclif manifest && oclif readme",
31
31
  "postpack": "rimraf oclif.manifest.json",
32
32
  "version": "oclif readme && git add README.md"
@@ -34,6 +34,9 @@
34
34
  "oclif": {
35
35
  "bin": "mj",
36
36
  "commands": "./dist/commands",
37
+ "hooks": {
38
+ "init": "./dist/hooks/init"
39
+ },
37
40
  "dirname": "mj",
38
41
  "plugins": [
39
42
  "@oclif/plugin-help",
@@ -50,11 +53,17 @@
50
53
  "@oclif/plugin-help": "^6",
51
54
  "@oclif/plugin-version": "^2.0.17",
52
55
  "@oclif/plugin-warn-if-update-available": "^3.0.16",
56
+ "cosmiconfig": "9.0.0",
57
+ "dotenv": "16.4.5",
58
+ "figlet": "^1.7.0",
53
59
  "fs-extra": "^11.2.0",
60
+ "node-flyway": "0.0.10",
61
+ "ora-classic": "^5.4.2",
54
62
  "zod": "^3.23.4"
55
63
  },
56
64
  "devDependencies": {
57
65
  "@oclif/prettier-config": "^0.2.1",
66
+ "@types/figlet": "^1.5.8",
58
67
  "@types/fs-extra": "^11.0.4",
59
68
  "oclif": "^4",
60
69
  "rimraf": "5.0.7",