typeorm 0.3.21-dev.981cf82 → 0.3.21-dev.988673c
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/browser/platform/BrowserPlatformTools.d.ts +1 -1
- package/browser/platform/BrowserPlatformTools.js +1 -1
- package/browser/platform/BrowserPlatformTools.js.map +1 -1
- package/browser/platform/PlatformTools.d.ts +1 -1
- package/browser/platform/PlatformTools.js +25 -13
- package/browser/platform/PlatformTools.js.map +1 -1
- package/commands/CacheClearCommand.d.ts +1 -1
- package/commands/CacheClearCommand.js +3 -3
- package/commands/CacheClearCommand.js.map +1 -1
- package/commands/EntityCreateCommand.d.ts +1 -1
- package/commands/EntityCreateCommand.js +7 -7
- package/commands/EntityCreateCommand.js.map +1 -1
- package/commands/InitCommand.d.ts +1 -1
- package/commands/InitCommand.js +8 -8
- package/commands/InitCommand.js.map +1 -1
- package/commands/MigrationCreateCommand.d.ts +1 -1
- package/commands/MigrationCreateCommand.js +5 -5
- package/commands/MigrationCreateCommand.js.map +1 -1
- package/commands/MigrationGenerateCommand.d.ts +1 -1
- package/commands/MigrationGenerateCommand.js +17 -17
- package/commands/MigrationGenerateCommand.js.map +1 -1
- package/commands/QueryCommand.d.ts +1 -1
- package/commands/QueryCommand.js +5 -6
- package/commands/QueryCommand.js.map +1 -1
- package/commands/SchemaDropCommand.d.ts +1 -1
- package/commands/SchemaDropCommand.js +3 -3
- package/commands/SchemaDropCommand.js.map +1 -1
- package/commands/SchemaLogCommand.d.ts +1 -1
- package/commands/SchemaLogCommand.js +11 -16
- package/commands/SchemaLogCommand.js.map +1 -1
- package/commands/SchemaSyncCommand.d.ts +1 -1
- package/commands/SchemaSyncCommand.js +3 -3
- package/commands/SchemaSyncCommand.js.map +1 -1
- package/commands/SubscriberCreateCommand.d.ts +1 -1
- package/commands/SubscriberCreateCommand.js +5 -5
- package/commands/SubscriberCreateCommand.js.map +1 -1
- package/package.json +1 -1
- package/platform/PlatformTools.d.ts +1 -1
- package/platform/PlatformTools.js +27 -15
- package/platform/PlatformTools.js.map +1 -1
|
@@ -41,7 +41,7 @@ export declare class PlatformTools {
|
|
|
41
41
|
*/
|
|
42
42
|
static highlightSql(sql: string): string;
|
|
43
43
|
/**
|
|
44
|
-
* Logging functions needed by AdvancedConsoleLogger (but here without
|
|
44
|
+
* Logging functions needed by AdvancedConsoleLogger (but here without ANSI colors)
|
|
45
45
|
*/
|
|
46
46
|
static logInfo(prefix: string, info: any): void;
|
|
47
47
|
static logError(prefix: string, error: any): void;
|
|
@@ -93,7 +93,7 @@ export class PlatformTools {
|
|
|
93
93
|
return sql;
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
|
-
* Logging functions needed by AdvancedConsoleLogger (but here without
|
|
96
|
+
* Logging functions needed by AdvancedConsoleLogger (but here without ANSI colors)
|
|
97
97
|
*/
|
|
98
98
|
static logInfo(prefix, info) {
|
|
99
99
|
console.info(prefix + " ", info);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/platform/BrowserPlatformTools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,OAAO,aAAa;IAOtB;;OAEG;IACH,MAAM,CAAC,iBAAiB;QACpB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAChC,OAAO,MAAM,CAAA;QACjB,CAAC;aAAM,CAAC;YACJ,uCAAuC;YACvC,OAAO,MAAM,CAAA;QACjB,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,IAAY;QACpB,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YACvB,MAAM,IAAI,KAAK,CAAC,gGAAgG,IAAI,KAAK,CAAC,CAAC;QAE/H,OAAO,EAAE,CAAC;IACd,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,OAAe;QAChC,IAAI,IAAI,CAAC,I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AAM,KAAK,WAAW,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;IAClE,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","file":"BrowserPlatformTools.js","sourcesContent":["/**\n * Browser's implementation of the platform-specific tools.\n *\n * This file gonna replace PlatformTools for browser environment.\n * For node.js environment this class is not getting packaged.\n * Don't use methods of this class in the code, use PlatformTools methods instead.\n */\nimport { Buffer } from \"buffer\";\n\nexport class PlatformTools {\n\n /**\n * Type of the currently running platform.\n */\n static type: \"browser\"|\"node\" = \"browser\";\n\n /**\n * Gets global variable where global stuff can be stored.\n */\n static getGlobalVariable(): any {\n if (typeof window !== \"undefined\") {\n return window\n } else {\n // NativeScript uses global, not window\n return global\n }\n }\n\n /**\n * Loads (\"require\"-s) given file or package.\n * This operation only supports on node platform\n */\n static load(name: string): any {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: require(\"${name}\").`);\n\n return \"\";\n }\n\n /**\n * Normalizes given path. Does \"path.normalize\".\n */\n static pathNormalize(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.normalize(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Gets file extension. Does \"path.extname\".\n */\n static pathExtname(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.extname(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Resolved given path. Does \"path.resolve\".\n */\n static pathResolve(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.resolve(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Synchronously checks if file exist. Does \"fs.existsSync\".\n */\n static fileExist(pathStr: string): boolean {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.existsSync(\"${pathStr}\").`);\n\n return false;\n }\n\n static dotenv(pathStr: string): void {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: dotenv.config({ path: \"${pathStr}\" }).`);\n }\n\n /**\n * Gets environment variable.\n */\n static getEnvVariable(name: string): any {\n // if (this.type === \"browser\")\n // throw new Error(`This option/function is not supported in the browser environment. Failed operation: process.env[\"${name}\"].`);\n return undefined;\n }\n\n static readFileSync(filename: string): any {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.readFileSync(\"${filename}\").`);\n return null;\n }\n\n static appendFileSync(filename: string, data: any) {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.appendFileSync(\"${filename}\").`);\n }\n\n static writeFile(path: string, data: any): Promise<void> {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.writeFile(\"${path}\").`);\n return Promise.reject(null);\n }\n\n /**\n * Highlights sql string to be printed in the console.\n */\n static highlightSql(sql: string) {\n return sql;\n }\n\n /**\n * Logging functions needed by AdvancedConsoleLogger (but here without
|
|
1
|
+
{"version":3,"sources":["../browser/src/platform/BrowserPlatformTools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,OAAO,aAAa;IAOtB;;OAEG;IACH,MAAM,CAAC,iBAAiB;QACpB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAChC,OAAO,MAAM,CAAA;QACjB,CAAC;aAAM,CAAC;YACJ,uCAAuC;YACvC,OAAO,MAAM,CAAA;QACjB,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,IAAY;QACpB,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YACvB,MAAM,IAAI,KAAK,CAAC,gGAAgG,IAAI,KAAK,CAAC,CAAC;QAE/H,OAAO,EAAE,CAAC;IACd,CAAC;IAED;;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M,GAAG,MAAM,CAAC;AAC3B,CAAC;AACD,uCAAuC;AACvC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;IAClE,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","file":"BrowserPlatformTools.js","sourcesContent":["/**\n * Browser's implementation of the platform-specific tools.\n *\n * This file gonna replace PlatformTools for browser environment.\n * For node.js environment this class is not getting packaged.\n * Don't use methods of this class in the code, use PlatformTools methods instead.\n */\nimport { Buffer } from \"buffer\";\n\nexport class PlatformTools {\n\n /**\n * Type of the currently running platform.\n */\n static type: \"browser\"|\"node\" = \"browser\";\n\n /**\n * Gets global variable where global stuff can be stored.\n */\n static getGlobalVariable(): any {\n if (typeof window !== \"undefined\") {\n return window\n } else {\n // NativeScript uses global, not window\n return global\n }\n }\n\n /**\n * Loads (\"require\"-s) given file or package.\n * This operation only supports on node platform\n */\n static load(name: string): any {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: require(\"${name}\").`);\n\n return \"\";\n }\n\n /**\n * Normalizes given path. Does \"path.normalize\".\n */\n static pathNormalize(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.normalize(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Gets file extension. Does \"path.extname\".\n */\n static pathExtname(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.extname(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Resolved given path. Does \"path.resolve\".\n */\n static pathResolve(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.resolve(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Synchronously checks if file exist. Does \"fs.existsSync\".\n */\n static fileExist(pathStr: string): boolean {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.existsSync(\"${pathStr}\").`);\n\n return false;\n }\n\n static dotenv(pathStr: string): void {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: dotenv.config({ path: \"${pathStr}\" }).`);\n }\n\n /**\n * Gets environment variable.\n */\n static getEnvVariable(name: string): any {\n // if (this.type === \"browser\")\n // throw new Error(`This option/function is not supported in the browser environment. Failed operation: process.env[\"${name}\"].`);\n return undefined;\n }\n\n static readFileSync(filename: string): any {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.readFileSync(\"${filename}\").`);\n return null;\n }\n\n static appendFileSync(filename: string, data: any) {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.appendFileSync(\"${filename}\").`);\n }\n\n static writeFile(path: string, data: any): Promise<void> {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.writeFile(\"${path}\").`);\n return Promise.reject(null);\n }\n\n /**\n * Highlights sql string to be printed in the console.\n */\n static highlightSql(sql: string) {\n return sql;\n }\n\n /**\n * Logging functions needed by AdvancedConsoleLogger (but here without ANSI colors)\n */\n static logInfo(prefix: string, info: any) {\n console.info(prefix + \" \", info);\n }\n\n static logError(prefix: string, error: any) {\n console.error(prefix + \" \", error);\n }\n\n static logWarn(prefix: string, warning: any) {\n console.warn(prefix + \" \", warning);\n }\n\n static log(message: string) {\n console.log(message);\n }\n\n static warn(message: string) {\n return message;\n }\n}\n\n/**\n * These classes are needed for stream operations or\n * in the mongodb driver. Both aren't supported in the browser.\n */\nexport class EventEmitter {}\n\nexport class Readable {}\n\nexport class Writable {}\n\nexport interface ReadStream {}\n\n/**\n * This loads a polyfill to enable Buffers in the browser.\n */\ninterface Window {\n Buffer: any;\n}\n\ndeclare var window: Window;\nif (typeof window !== \"undefined\") {\n window.Buffer = Buffer;\n}\n// NativeScript uses global, not window\nif (typeof global !== \"undefined\" && typeof require !== \"undefined\") {\n global.Buffer = require(\"buffer/\").Buffer;\n}\n"],"sourceRoot":".."}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import fs from "fs";
|
|
1
|
+
import ansi from "ansis";
|
|
3
2
|
import dotenv from "dotenv";
|
|
4
|
-
import
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
5
|
import { highlight } from "sql-highlight";
|
|
6
|
-
export { ReadStream } from "fs";
|
|
7
6
|
export { EventEmitter } from "events";
|
|
7
|
+
export { ReadStream } from "fs";
|
|
8
8
|
export { Readable, Writable } from "stream";
|
|
9
9
|
/**
|
|
10
10
|
* Platform-specific tools.
|
|
@@ -166,34 +166,46 @@ export class PlatformTools {
|
|
|
166
166
|
* Highlights sql string to be printed in the console.
|
|
167
167
|
*/
|
|
168
168
|
static highlightSql(sql) {
|
|
169
|
-
return highlight(sql
|
|
169
|
+
return highlight(sql, {
|
|
170
|
+
colors: {
|
|
171
|
+
keyword: ansi.blueBright.open,
|
|
172
|
+
function: ansi.magentaBright.open,
|
|
173
|
+
number: ansi.green.open,
|
|
174
|
+
string: ansi.white.open,
|
|
175
|
+
identifier: ansi.white.open,
|
|
176
|
+
special: ansi.white.open,
|
|
177
|
+
bracket: ansi.white.open,
|
|
178
|
+
comment: ansi.gray.open,
|
|
179
|
+
clear: ansi.reset.open,
|
|
180
|
+
},
|
|
181
|
+
});
|
|
170
182
|
}
|
|
171
183
|
/**
|
|
172
184
|
* Logging functions needed by AdvancedConsoleLogger
|
|
173
185
|
*/
|
|
174
186
|
static logInfo(prefix, info) {
|
|
175
|
-
console.log(
|
|
187
|
+
console.log(ansi.gray.underline(prefix), info);
|
|
176
188
|
}
|
|
177
189
|
static logError(prefix, error) {
|
|
178
|
-
console.log(
|
|
190
|
+
console.log(ansi.underline.red(prefix), error);
|
|
179
191
|
}
|
|
180
192
|
static logWarn(prefix, warning) {
|
|
181
|
-
console.log(
|
|
193
|
+
console.log(ansi.underline.yellow(prefix), warning);
|
|
182
194
|
}
|
|
183
195
|
static log(message) {
|
|
184
|
-
console.log(
|
|
196
|
+
console.log(ansi.underline(message));
|
|
185
197
|
}
|
|
186
198
|
static info(info) {
|
|
187
|
-
return
|
|
199
|
+
return ansi.gray(info);
|
|
188
200
|
}
|
|
189
201
|
static error(error) {
|
|
190
|
-
return
|
|
202
|
+
return ansi.red(error);
|
|
191
203
|
}
|
|
192
204
|
static warn(message) {
|
|
193
|
-
return
|
|
205
|
+
return ansi.yellow(message);
|
|
194
206
|
}
|
|
195
207
|
static logCmdErr(prefix, err) {
|
|
196
|
-
console.log(
|
|
208
|
+
console.log(ansi.black.bgRed(prefix));
|
|
197
209
|
if (err)
|
|
198
210
|
console.error(err);
|
|
199
211
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/platform/PlatformTools.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAE3C;;GAEG;AACH,MAAM,OAAO,aAAa;IAMtB;;OAEG;IACH,MAAM,CAAC,iBAAiB;QACpB,OAAO,MAAM,CAAA;IACjB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,IAAY;QACpB,2HAA2H;QAC3H,8FAA8F;QAC9F,kCAAkC;QAElC,IAAI,CAAC;YACD,wEAAwE;YACxE,QAAQ,IAAI,EAAE,CAAC;gBACX;;mBAEG;gBACH,KAAK,SAAS;o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K,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,KAAU;QACnB,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,OAAe;QACvB,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAChC,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,MAAc,EAAE,GAAS;QACtC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;QACtC,IAAI,GAAG;YAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC/B,CAAC;;AAtOD;;GAEG;AACI,kBAAI,GAAuB,MAAM,CAAA","file":"PlatformTools.js","sourcesContent":["import path from \"path\"\nimport fs from \"fs\"\nimport dotenv from \"dotenv\"\nimport chalk from \"chalk\"\nimport { highlight } from \"sql-highlight\"\n\nexport { ReadStream } from \"fs\"\nexport { EventEmitter } from \"events\"\nexport { Readable, Writable } from \"stream\"\n\n/**\n * Platform-specific tools.\n */\nexport class PlatformTools {\n /**\n * Type of the currently running platform.\n */\n static type: \"browser\" | \"node\" = \"node\"\n\n /**\n * Gets global variable where global stuff can be stored.\n */\n static getGlobalVariable(): any {\n return global\n }\n\n /**\n * Loads (\"require\"-s) given file or package.\n * This operation only supports on node platform\n */\n static load(name: string): any {\n // if name is not absolute or relative, then try to load package from the node_modules of the directory we are currently in\n // this is useful when we are using typeorm package globally installed and it accesses drivers\n // that are not installed globally\n\n try {\n // switch case to explicit require statements for webpack compatibility.\n switch (name) {\n /**\n * spanner\n */\n case \"spanner\":\n return require(\"@google-cloud/spanner\")\n\n /**\n * mongodb\n */\n case \"mongodb\":\n return require(\"mongodb\")\n\n /**\n * hana\n */\n case \"@sap/hana-client\":\n return require(\"@sap/hana-client\")\n\n case \"@sap/hana-client/extension/Stream\":\n return require(\"@sap/hana-client/extension/Stream\")\n\n case \"hdb-pool\":\n return require(\"hdb-pool\")\n\n /**\n * mysql\n */\n case \"mysql\":\n return require(\"mysql\")\n\n case \"mysql2\":\n return require(\"mysql2\")\n\n /**\n * oracle\n */\n case \"oracledb\":\n return require(\"oracledb\")\n\n /**\n * postgres\n */\n case \"pg\":\n return require(\"pg\")\n\n case \"pg-native\":\n return require(\"pg-native\")\n\n case \"pg-query-stream\":\n return require(\"pg-query-stream\")\n\n case \"typeorm-aurora-data-api-driver\":\n return require(\"typeorm-aurora-data-api-driver\")\n\n /**\n * redis\n */\n case \"redis\":\n return require(\"redis\")\n\n case \"ioredis\":\n return require(\"ioredis\")\n\n /**\n * better-sqlite3\n */\n case \"better-sqlite3\":\n return require(\"better-sqlite3\")\n\n /**\n * sqlite\n */\n case \"sqlite3\":\n return require(\"sqlite3\")\n\n /**\n * sql.js\n */\n case \"sql.js\":\n return require(\"sql.js\")\n\n /**\n * sqlserver\n */\n case \"mssql\":\n return require(\"mssql\")\n\n /**\n * react-native-sqlite\n */\n case \"react-native-sqlite-storage\":\n return require(\"react-native-sqlite-storage\")\n }\n } catch (err) {\n return require(path.resolve(\n process.cwd() + \"/node_modules/\" + name,\n ))\n }\n\n // If nothing above matched and we get here, the package was not listed within PlatformTools\n // and is an Invalid Package. To make it explicit that this is NOT the intended use case for\n // PlatformTools.load - it's not just a way to replace `require` all willy-nilly - let's throw\n // an error.\n throw new TypeError(`Invalid Package for PlatformTools.load: ${name}`)\n }\n\n /**\n * Normalizes given path. Does \"path.normalize\" and replaces backslashes with forward slashes on Windows.\n */\n static pathNormalize(pathStr: string): string {\n let normalizedPath = path.normalize(pathStr)\n if (process.platform === \"win32\")\n normalizedPath = normalizedPath.replace(/\\\\/g, \"/\")\n return normalizedPath\n }\n\n /**\n * Gets file extension. Does \"path.extname\".\n */\n static pathExtname(pathStr: string): string {\n return path.extname(pathStr)\n }\n\n /**\n * Resolved given path. Does \"path.resolve\".\n */\n static pathResolve(pathStr: string): string {\n return path.resolve(pathStr)\n }\n\n /**\n * Synchronously checks if file exist. Does \"fs.existsSync\".\n */\n static fileExist(pathStr: string): boolean {\n return fs.existsSync(pathStr)\n }\n\n static readFileSync(filename: string): Buffer {\n return fs.readFileSync(filename)\n }\n\n static appendFileSync(filename: string, data: any): void {\n fs.appendFileSync(filename, data)\n }\n\n static async writeFile(path: string, data: any): Promise<void> {\n return fs.promises.writeFile(path, data)\n }\n\n /**\n * Loads a dotenv file into the environment variables.\n *\n * @param path The file to load as a dotenv configuration\n */\n static dotenv(pathStr: string): void {\n dotenv.config({ path: pathStr })\n }\n\n /**\n * Gets environment variable.\n */\n static getEnvVariable(name: string): any {\n return process.env[name]\n }\n\n /**\n * Highlights sql string to be printed in the console.\n */\n static highlightSql(sql: string) {\n return highlight(sql)\n }\n\n /**\n * Logging functions needed by AdvancedConsoleLogger\n */\n static logInfo(prefix: string, info: any) {\n console.log(chalk.gray.underline(prefix), info)\n }\n\n static logError(prefix: string, error: any) {\n console.log(chalk.underline.red(prefix), error)\n }\n\n static logWarn(prefix: string, warning: any) {\n console.log(chalk.underline.yellow(prefix), warning)\n }\n\n static log(message: string) {\n console.log(chalk.underline(message))\n }\n\n static info(info: any) {\n return chalk.gray(info)\n }\n\n static error(error: any) {\n return chalk.red(error)\n }\n\n static warn(message: string) {\n return chalk.yellow(message)\n }\n\n static logCmdErr(prefix: string, err?: any) {\n console.log(chalk.black.bgRed(prefix))\n if (err) console.error(err)\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/platform/PlatformTools.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,OAAO,CAAA;AACxB,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM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C,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;QACrC,IAAI,GAAG;YAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC/B,CAAC;;AAlPD;;GAEG;AACI,kBAAI,GAAuB,MAAM,CAAA","file":"PlatformTools.js","sourcesContent":["import ansi from \"ansis\"\nimport dotenv from \"dotenv\"\nimport fs from \"fs\"\nimport path from \"path\"\nimport { highlight } from \"sql-highlight\"\n\nexport { EventEmitter } from \"events\"\nexport { ReadStream } from \"fs\"\nexport { Readable, Writable } from \"stream\"\n\n/**\n * Platform-specific tools.\n */\nexport class PlatformTools {\n /**\n * Type of the currently running platform.\n */\n static type: \"browser\" | \"node\" = \"node\"\n\n /**\n * Gets global variable where global stuff can be stored.\n */\n static getGlobalVariable(): any {\n return global\n }\n\n /**\n * Loads (\"require\"-s) given file or package.\n * This operation only supports on node platform\n */\n static load(name: string): any {\n // if name is not absolute or relative, then try to load package from the node_modules of the directory we are currently in\n // this is useful when we are using typeorm package globally installed and it accesses drivers\n // that are not installed globally\n\n try {\n // switch case to explicit require statements for webpack compatibility.\n switch (name) {\n /**\n * spanner\n */\n case \"spanner\":\n return require(\"@google-cloud/spanner\")\n\n /**\n * mongodb\n */\n case \"mongodb\":\n return require(\"mongodb\")\n\n /**\n * hana\n */\n case \"@sap/hana-client\":\n return require(\"@sap/hana-client\")\n\n case \"@sap/hana-client/extension/Stream\":\n return require(\"@sap/hana-client/extension/Stream\")\n\n case \"hdb-pool\":\n return require(\"hdb-pool\")\n\n /**\n * mysql\n */\n case \"mysql\":\n return require(\"mysql\")\n\n case \"mysql2\":\n return require(\"mysql2\")\n\n /**\n * oracle\n */\n case \"oracledb\":\n return require(\"oracledb\")\n\n /**\n * postgres\n */\n case \"pg\":\n return require(\"pg\")\n\n case \"pg-native\":\n return require(\"pg-native\")\n\n case \"pg-query-stream\":\n return require(\"pg-query-stream\")\n\n case \"typeorm-aurora-data-api-driver\":\n return require(\"typeorm-aurora-data-api-driver\")\n\n /**\n * redis\n */\n case \"redis\":\n return require(\"redis\")\n\n case \"ioredis\":\n return require(\"ioredis\")\n\n /**\n * better-sqlite3\n */\n case \"better-sqlite3\":\n return require(\"better-sqlite3\")\n\n /**\n * sqlite\n */\n case \"sqlite3\":\n return require(\"sqlite3\")\n\n /**\n * sql.js\n */\n case \"sql.js\":\n return require(\"sql.js\")\n\n /**\n * sqlserver\n */\n case \"mssql\":\n return require(\"mssql\")\n\n /**\n * react-native-sqlite\n */\n case \"react-native-sqlite-storage\":\n return require(\"react-native-sqlite-storage\")\n }\n } catch (err) {\n return require(path.resolve(\n process.cwd() + \"/node_modules/\" + name,\n ))\n }\n\n // If nothing above matched and we get here, the package was not listed within PlatformTools\n // and is an Invalid Package. To make it explicit that this is NOT the intended use case for\n // PlatformTools.load - it's not just a way to replace `require` all willy-nilly - let's throw\n // an error.\n throw new TypeError(`Invalid Package for PlatformTools.load: ${name}`)\n }\n\n /**\n * Normalizes given path. Does \"path.normalize\" and replaces backslashes with forward slashes on Windows.\n */\n static pathNormalize(pathStr: string): string {\n let normalizedPath = path.normalize(pathStr)\n if (process.platform === \"win32\")\n normalizedPath = normalizedPath.replace(/\\\\/g, \"/\")\n return normalizedPath\n }\n\n /**\n * Gets file extension. Does \"path.extname\".\n */\n static pathExtname(pathStr: string): string {\n return path.extname(pathStr)\n }\n\n /**\n * Resolved given path. Does \"path.resolve\".\n */\n static pathResolve(pathStr: string): string {\n return path.resolve(pathStr)\n }\n\n /**\n * Synchronously checks if file exist. Does \"fs.existsSync\".\n */\n static fileExist(pathStr: string): boolean {\n return fs.existsSync(pathStr)\n }\n\n static readFileSync(filename: string): Buffer {\n return fs.readFileSync(filename)\n }\n\n static appendFileSync(filename: string, data: any): void {\n fs.appendFileSync(filename, data)\n }\n\n static async writeFile(path: string, data: any): Promise<void> {\n return fs.promises.writeFile(path, data)\n }\n\n /**\n * Loads a dotenv file into the environment variables.\n *\n * @param path The file to load as a dotenv configuration\n */\n static dotenv(pathStr: string): void {\n dotenv.config({ path: pathStr })\n }\n\n /**\n * Gets environment variable.\n */\n static getEnvVariable(name: string): any {\n return process.env[name]\n }\n\n /**\n * Highlights sql string to be printed in the console.\n */\n static highlightSql(sql: string) {\n return highlight(sql, {\n colors: {\n keyword: ansi.blueBright.open,\n function: ansi.magentaBright.open,\n number: ansi.green.open,\n string: ansi.white.open,\n identifier: ansi.white.open,\n special: ansi.white.open,\n bracket: ansi.white.open,\n comment: ansi.gray.open,\n clear: ansi.reset.open,\n },\n })\n }\n\n /**\n * Logging functions needed by AdvancedConsoleLogger\n */\n static logInfo(prefix: string, info: any) {\n console.log(ansi.gray.underline(prefix), info)\n }\n\n static logError(prefix: string, error: any) {\n console.log(ansi.underline.red(prefix), error)\n }\n\n static logWarn(prefix: string, warning: any) {\n console.log(ansi.underline.yellow(prefix), warning)\n }\n\n static log(message: string) {\n console.log(ansi.underline(message))\n }\n\n static info(info: any) {\n return ansi.gray(info)\n }\n\n static error(error: any) {\n return ansi.red(error)\n }\n\n static warn(message: string) {\n return ansi.yellow(message)\n }\n\n static logCmdErr(prefix: string, err?: any) {\n console.log(ansi.black.bgRed(prefix))\n if (err) console.error(err)\n }\n}\n"],"sourceRoot":".."}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CacheClearCommand = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
6
|
-
const PlatformTools_1 = require("../platform/PlatformTools");
|
|
5
|
+
const ansis_1 = tslib_1.__importDefault(require("ansis"));
|
|
7
6
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
8
7
|
const process_1 = tslib_1.__importDefault(require("process"));
|
|
8
|
+
const PlatformTools_1 = require("../platform/PlatformTools");
|
|
9
9
|
const CommandUtils_1 = require("./CommandUtils");
|
|
10
10
|
/**
|
|
11
11
|
* Clear cache command.
|
|
@@ -39,7 +39,7 @@ class CacheClearCommand {
|
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
await dataSource.queryResultCache.clear();
|
|
42
|
-
console.log(
|
|
42
|
+
console.log(ansis_1.default.green `Cache was successfully cleared`);
|
|
43
43
|
await dataSource.destroy();
|
|
44
44
|
}
|
|
45
45
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/CacheClearCommand.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"sources":["../../src/commands/CacheClearCommand.ts"],"names":[],"mappings":";;;;AAAA,0DAAwB;AACxB,wDAAuB;AACvB,8DAA6B;AAG7B,6DAAyD;AACzD,iDAA6C;AAE7C;;GAEG;AACH,MAAa,iBAAiB;IAA9B;QACI,YAAO,GAAG,aAAa,CAAA;QACvB,aAAQ,GAAG,+CAA+C,CAAA;IA8C9D,CAAC;IA5CG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;YAC7B,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI,UAAU,GAA2B,SAAS,CAAA;QAClD,IAAI,CAAC;YACD,UAAU,GAAG,MAAM,2BAAY,CAAC,cAAc,CAC1C,cAAI,CAAC,OAAO,CAAC,iBAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAoB,CAAC,CACzD,CAAA;YACD,UAAU,CAAC,UAAU,CAAC;gBAClB,WAAW,EAAE,EAAE;gBACf,WAAW,EAAE,KAAK;gBAClB,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE,KAAK;gBACjB,OAAO,EAAE,CAAC,QAAQ,CAAC;aACtB,CAAC,CAAA;YACF,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;YAE7B,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC;gBAC/B,6BAAa,CAAC,SAAS,CACnB,2EAA2E,CAC9E,CAAA;gBACD,OAAM;YACV,CAAC;YAED,MAAM,UAAU,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAA;YACzC,OAAO,CAAC,GAAG,CAAC,eAAI,CAAC,KAAK,CAAA,gCAAgC,CAAC,CAAA;YAEvD,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;QAC9B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,6BAAa,CAAC,SAAS,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAA;YAEzD,IAAI,UAAU,IAAI,UAAU,CAAC,aAAa;gBACtC,MAAO,UAAyB,CAAC,OAAO,EAAE,CAAA;YAE9C,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,CAAC;IACL,CAAC;CACJ;AAhDD,8CAgDC","file":"CacheClearCommand.js","sourcesContent":["import ansi from \"ansis\"\nimport path from \"path\"\nimport process from \"process\"\nimport yargs from \"yargs\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Clear cache command.\n */\nexport class CacheClearCommand implements yargs.CommandModule {\n command = \"cache:clear\"\n describe = \"Clears all data stored in query runner cache.\"\n\n builder(args: yargs.Argv) {\n return args.option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"schema\"],\n })\n await dataSource.initialize()\n\n if (!dataSource.queryResultCache) {\n PlatformTools.logCmdErr(\n \"Cache is not enabled. To use cache enable it in connection configuration.\",\n )\n return\n }\n\n await dataSource.queryResultCache.clear()\n console.log(ansi.green`Cache was successfully cleared`)\n\n await dataSource.destroy()\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during cache clear.\", err)\n\n if (dataSource && dataSource.isInitialized)\n await (dataSource as DataSource).destroy()\n\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EntityCreateCommand = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
6
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
|
-
const PlatformTools_1 = require("../platform/PlatformTools");
|
|
5
|
+
const ansis_1 = tslib_1.__importDefault(require("ansis"));
|
|
8
6
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
+
const PlatformTools_1 = require("../platform/PlatformTools");
|
|
8
|
+
const CommandUtils_1 = require("./CommandUtils");
|
|
9
9
|
/**
|
|
10
10
|
* Generates a new entity.
|
|
11
11
|
*/
|
|
@@ -30,13 +30,13 @@ class EntityCreateCommand {
|
|
|
30
30
|
const fileContent = EntityCreateCommand.getTemplate(filename);
|
|
31
31
|
const fileExists = await CommandUtils_1.CommandUtils.fileExists(fullPath + ".ts");
|
|
32
32
|
if (fileExists) {
|
|
33
|
-
throw `File ${
|
|
33
|
+
throw new Error(`File "${fullPath}.ts" already exists`);
|
|
34
34
|
}
|
|
35
35
|
await CommandUtils_1.CommandUtils.createFile(fullPath + ".ts", fileContent);
|
|
36
|
-
console.log(
|
|
36
|
+
console.log(ansis_1.default.green `Entity ${ansis_1.default.blue `${fullPath}.ts`} has been created successfully.`);
|
|
37
37
|
}
|
|
38
|
-
catch (
|
|
39
|
-
PlatformTools_1.PlatformTools.logCmdErr("Error during entity creation:",
|
|
38
|
+
catch (error) {
|
|
39
|
+
PlatformTools_1.PlatformTools.logCmdErr("Error during entity creation:", error);
|
|
40
40
|
process.exit(1);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/EntityCreateCommand.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/commands/EntityCreateCommand.ts"],"names":[],"mappings":";;;;AAAA,0DAAwB;AACxB,wDAAuB;AAEvB,6DAAyD;AACzD,iDAA6C;AAE7C;;GAEG;AACH,MAAa,mBAAmB;IAAhC;QACI,YAAO,GAAG,sBAAsB,CAAA;QAChC,aAAQ,GAAG,yBAAyB,CAAA;IA+CxC,CAAC;IA7CG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;YAC3B,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,yBAAyB;YACnC,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI,CAAC;YACD,MAAM,QAAQ,GAAI,IAAI,CAAC,IAAe,CAAC,UAAU,CAAC,GAAG,CAAC;gBAClD,CAAC,CAAE,IAAI,CAAC,IAAe;gBACvB,CAAC,CAAC,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,IAAc,CAAC,CAAA;YACtD,MAAM,QAAQ,GAAG,cAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;YACxC,MAAM,WAAW,GAAG,mBAAmB,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;YAC7D,MAAM,UAAU,GAAG,MAAM,2BAAY,CAAC,UAAU,CAAC,QAAQ,GAAG,KAAK,CAAC,CAAA;YAClE,IAAI,UAAU,EAAE,CAAC;gBACb,MAAM,IAAI,KAAK,CAAC,SAAS,QAAQ,qBAAqB,CAAC,CAAA;YAC3D,CAAC;YACD,MAAM,2BAAY,CAAC,UAAU,CAAC,QAAQ,GAAG,KAAK,EAAE,WAAW,CAAC,CAAA;YAC5D,OAAO,CAAC,GAAG,CACP,eAAI,CAAC,KAAK,CAAA,UAAU,eAAI,CAAC,IAAI,CAAA,GAAG,QAAQ,KAAK,iCAAiC,CACjF,CAAA;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,6BAAa,CAAC,SAAS,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAA;YAC/D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,CAAC;IACL,CAAC;IAED,4EAA4E;IAC5E,2BAA2B;IAC3B,4EAA4E;IAE5E;;OAEG;IACO,MAAM,CAAC,WAAW,CAAC,IAAY;QACrC,OAAO;;;eAGA,IAAI;;;CAGlB,CAAA;IACG,CAAC;CACJ;AAjDD,kDAiDC","file":"EntityCreateCommand.js","sourcesContent":["import ansi from \"ansis\"\nimport path from \"path\"\nimport yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Generates a new entity.\n */\nexport class EntityCreateCommand implements yargs.CommandModule {\n command = \"entity:create <path>\"\n describe = \"Generates a new entity.\"\n\n builder(args: yargs.Argv) {\n return args.positional(\"path\", {\n type: \"string\",\n describe: \"Path of the entity file\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const fullPath = (args.path as string).startsWith(\"/\")\n ? (args.path as string)\n : path.resolve(process.cwd(), args.path as string)\n const filename = path.basename(fullPath)\n const fileContent = EntityCreateCommand.getTemplate(filename)\n const fileExists = await CommandUtils.fileExists(fullPath + \".ts\")\n if (fileExists) {\n throw new Error(`File \"${fullPath}.ts\" already exists`)\n }\n await CommandUtils.createFile(fullPath + \".ts\", fileContent)\n console.log(\n ansi.green`Entity ${ansi.blue`${fullPath}.ts`} has been created successfully.`,\n )\n } catch (error) {\n PlatformTools.logCmdErr(\"Error during entity creation:\", error)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets contents of the entity file.\n */\n protected static getTemplate(name: string): string {\n return `import { Entity } from \"typeorm\"\n\n@Entity()\nexport class ${name} {\n\n}\n`\n }\n}\n"],"sourceRoot":".."}
|
package/commands/InitCommand.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InitCommand = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
6
|
-
const path = tslib_1.__importStar(require("path"));
|
|
7
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
5
|
+
const ansis_1 = tslib_1.__importDefault(require("ansis"));
|
|
8
6
|
const child_process_1 = require("child_process");
|
|
7
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
8
|
const error_1 = require("../error");
|
|
10
9
|
const PlatformTools_1 = require("../platform/PlatformTools");
|
|
10
|
+
const CommandUtils_1 = require("./CommandUtils");
|
|
11
11
|
/**
|
|
12
12
|
* Generates a new project with TypeORM.
|
|
13
13
|
*/
|
|
@@ -54,7 +54,7 @@ class InitCommand {
|
|
|
54
54
|
const isDocker = args.docker !== undefined ? true : false;
|
|
55
55
|
const basePath = process.cwd() + (args.name ? "/" + args.name : "");
|
|
56
56
|
const projectName = args.name
|
|
57
|
-
?
|
|
57
|
+
? path_1.default.basename(args.name)
|
|
58
58
|
: undefined;
|
|
59
59
|
const installNpm = args.pm === "yarn" ? false : true;
|
|
60
60
|
const projectIsEsm = args.ms === "esm";
|
|
@@ -76,19 +76,19 @@ class InitCommand {
|
|
|
76
76
|
const packageJsonContents = await CommandUtils_1.CommandUtils.readFile(basePath + "/package.json");
|
|
77
77
|
await CommandUtils_1.CommandUtils.createFile(basePath + "/package.json", InitCommand.appendPackageJson(packageJsonContents, database, isExpress, projectIsEsm));
|
|
78
78
|
if (args.name) {
|
|
79
|
-
console.log(
|
|
79
|
+
console.log(ansis_1.default.green `Project created inside ${ansis_1.default.blue(basePath)} directory.`);
|
|
80
80
|
}
|
|
81
81
|
else {
|
|
82
|
-
console.log(
|
|
82
|
+
console.log(ansis_1.default.green `Project created inside current directory.`);
|
|
83
83
|
}
|
|
84
|
-
console.log(
|
|
84
|
+
console.log(ansis_1.default.green `Please wait, installing dependencies...`);
|
|
85
85
|
if (args.pm && installNpm) {
|
|
86
86
|
await InitCommand.executeCommand("npm install", basePath);
|
|
87
87
|
}
|
|
88
88
|
else {
|
|
89
89
|
await InitCommand.executeCommand("yarn install", basePath);
|
|
90
90
|
}
|
|
91
|
-
console.log(
|
|
91
|
+
console.log(ansis_1.default.green `Done! Start playing with a new project!`);
|
|
92
92
|
}
|
|
93
93
|
catch (err) {
|
|
94
94
|
PlatformTools_1.PlatformTools.logCmdErr("Error during project initialization:", err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/InitCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAC7C,mDAA4B;AAE5B,0DAAyB;AACzB,iDAAoC;AACpC,oCAAuC;AACvC,6DAAyD;AAEzD;;GAEG;AACH,MAAa,WAAW;IAAxB;QACI,YAAO,GAAG,MAAM,CAAA;QAChB,aAAQ,GACJ,+CAA+C;YAC/C,wEAAwE;YACxE,mEAAmE,CAAA;IAmuB3E,CAAC;IAjuBG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,gCAAgC;SAC7C,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,2CAA2C;SACxD,CAAC;aACD,MAAM,CAAC,SAAS,EAAE;YACf,QAAQ,EACJ,8FAA8F;SACrG,CAAC;aACD,MAAM,CAAC,QAAQ,EAAE;YACd,QAAQ,EACJ,4EAA4E;SACnF,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,SAAS;YACh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AgB;gBACjB,WAAW,CAAC,YAAY,CAAC,gBAAgB,CAAC,GAAG,QAAQ,CAAA;gBACrD,MAAK;YACT,KAAK,QAAQ;gBACT,WAAW,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAA;gBAC/C,MAAK;YACT,KAAK,OAAO;gBACR,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAA;gBAC5C,MAAK;YACT,KAAK,SAAS;gBACV,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAA;gBAC9C,MAAK;YACT,KAAK,SAAS;gBACV,WAAW,CAAC,YAAY,CAAC,uBAAuB,CAAC,GAAG,SAAS,CAAA;gBAC7D,MAAK;QACb,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACV,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,SAAS,CAAA;YAC/C,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC,GAAG,SAAS,CAAA;QACvD,CAAC;QAED,IAAI,CAAC,WAAW,CAAC,OAAO;YAAE,WAAW,CAAC,OAAO,GAAG,EAAE,CAAA;QAElD,IAAI,YAAY;YACZ,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,wCAAwC;gBAC9F,OAAO,EAAE,qBAAqB;aACjC,CAAC,CAAA;;YAEF,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,sBAAsB;gBAC5E,OAAO,EAAE,0BAA0B;aACtC,CAAC,CAAA;QAEN,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;IACpD,CAAC;CACJ;AAxuBD,kCAwuBC","file":"InitCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport * as path from \"path\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { exec } from \"child_process\"\nimport { TypeORMError } from \"../error\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\n\n/**\n * Generates a new project with TypeORM.\n */\nexport class InitCommand implements yargs.CommandModule {\n command = \"init\"\n describe =\n \"Generates initial TypeORM project structure. \" +\n \"If name specified then creates files inside directory called as name. \" +\n \"If its not specified then creates files inside current directory.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the project directory.\",\n })\n .option(\"db\", {\n alias: \"database\",\n describe: \"Database type you'll use in your project.\",\n })\n .option(\"express\", {\n describe:\n \"Indicates if express server sample code should be included in the project. False by default.\",\n })\n .option(\"docker\", {\n describe:\n \"Set to true if docker-compose must be generated as well. False by default.\",\n })\n .option(\"pm\", {\n alias: \"manager\",\n choices: [\"npm\", \"yarn\"],\n default: \"npm\",\n describe: \"Install packages, expected values are npm or yarn.\",\n })\n .option(\"ms\", {\n alias: \"module\",\n choices: [\"commonjs\", \"esm\"],\n default: \"commonjs\",\n describe:\n \"Module system to use for project, expected values are commonjs or esm.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const database: string = (args.database as any) || \"postgres\"\n const isExpress = args.express !== undefined ? true : false\n const isDocker = args.docker !== undefined ? true : false\n const basePath = process.cwd() + (args.name ? \"/\" + args.name : \"\")\n const projectName = args.name\n ? path.basename(args.name as any)\n : undefined\n const installNpm = args.pm === \"yarn\" ? false : true\n const projectIsEsm = args.ms === \"esm\"\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.getPackageJsonTemplate(projectName, projectIsEsm),\n false,\n )\n if (isDocker)\n await CommandUtils.createFile(\n basePath + \"/docker-compose.yml\",\n InitCommand.getDockerComposeTemplate(database),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/.gitignore\",\n InitCommand.getGitIgnoreFile(),\n )\n await CommandUtils.createFile(\n basePath + \"/README.md\",\n InitCommand.getReadmeTemplate({ docker: isDocker }),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/tsconfig.json\",\n InitCommand.getTsConfigTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/entity/User.ts\",\n InitCommand.getUserEntityTemplate(database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/data-source.ts\",\n InitCommand.getAppDataSourceTemplate(projectIsEsm, database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/index.ts\",\n InitCommand.getAppIndexTemplate(isExpress, projectIsEsm),\n )\n await CommandUtils.createDirectories(basePath + \"/src/migration\")\n\n // generate extra files for express application\n if (isExpress) {\n await CommandUtils.createFile(\n basePath + \"/src/routes.ts\",\n InitCommand.getRoutesTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/controller/UserController.ts\",\n InitCommand.getControllerTemplate(projectIsEsm),\n )\n }\n\n const packageJsonContents = await CommandUtils.readFile(\n basePath + \"/package.json\",\n )\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.appendPackageJson(\n packageJsonContents,\n database,\n isExpress,\n projectIsEsm,\n ),\n )\n\n if (args.name) {\n console.log(\n chalk.green(\n `Project created inside ${chalk.blue(\n basePath,\n )} directory.`,\n ),\n )\n } else {\n console.log(\n chalk.green(`Project created inside current directory.`),\n )\n }\n\n console.log(chalk.green(`Please wait, installing dependencies...`))\n if (args.pm && installNpm) {\n await InitCommand.executeCommand(\"npm install\", basePath)\n } else {\n await InitCommand.executeCommand(\"yarn install\", basePath)\n }\n\n console.log(chalk.green(`Done! Start playing with a new project!`))\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during project initialization:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n protected static executeCommand(command: string, cwd: string) {\n return new Promise<string>((ok, fail) => {\n exec(command, { cwd }, (error: any, stdout: any, stderr: any) => {\n if (stdout) return ok(stdout)\n if (stderr) return fail(stderr)\n if (error) return fail(error)\n ok(\"\")\n })\n })\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getAppDataSourceTemplate(\n isEsm: boolean,\n database: string,\n ): string {\n let dbSettings = \"\"\n switch (database) {\n case \"mysql\":\n dbSettings = `type: \"mysql\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"mariadb\":\n dbSettings = `type: \"mariadb\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"sqlite\":\n dbSettings = `type: \"sqlite\",\n database: \"database.sqlite\",`\n break\n case \"better-sqlite3\":\n dbSettings = `type: \"better-sqlite3\",\n database: \"database.sqlite\",`\n break\n case \"postgres\":\n dbSettings = `type: \"postgres\",\n host: \"localhost\",\n port: 5432,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"cockroachdb\":\n dbSettings = `type: \"cockroachdb\",\n host: \"localhost\",\n port: 26257,\n username: \"root\",\n password: \"\",\n database: \"defaultdb\",`\n break\n case \"mssql\":\n dbSettings = `type: \"mssql\",\n host: \"localhost\",\n username: \"sa\",\n password: \"Admin12345\",\n database: \"tempdb\",`\n break\n case \"oracle\":\n dbSettings = `type: \"oracle\",\nhost: \"localhost\",\nusername: \"system\",\npassword: \"oracle\",\nport: 1521,\nsid: \"xe.oracle.docker\",`\n break\n case \"mongodb\":\n dbSettings = `type: \"mongodb\",\n database: \"test\",`\n break\n case \"spanner\":\n dbSettings = `type: \"spanner\",\n projectId: \"test\",\n instanceId: \"test\",\n databaseId: \"test\",`\n break\n }\n return `import \"reflect-metadata\"\nimport { DataSource } from \"typeorm\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport const AppDataSource = new DataSource({\n ${dbSettings}\n synchronize: true,\n logging: false,\n entities: [User],\n migrations: [],\n subscribers: [],\n})\n`\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getTsConfigTemplate(esmModule: boolean): string {\n if (esmModule)\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es2021\"],\n target: \"es2021\",\n module: \"es2022\",\n moduleResolution: \"node\",\n allowSyntheticDefaultImports: true,\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n else\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es5\", \"es6\"],\n target: \"es5\",\n module: \"commonjs\",\n moduleResolution: \"node\",\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the .gitignore file.\n */\n protected static getGitIgnoreFile(): string {\n return `.idea/\n.vscode/\nnode_modules/\nbuild/\ntmp/\ntemp/`\n }\n\n /**\n * Gets contents of the user entity.\n */\n protected static getUserEntityTemplate(database: string): string {\n return `import { Entity, ${\n database === \"mongodb\"\n ? \"ObjectIdColumn, ObjectId\"\n : \"PrimaryGeneratedColumn\"\n }, Column } from \"typeorm\"\n\n@Entity()\nexport class User {\n\n ${\n database === \"mongodb\"\n ? \"@ObjectIdColumn()\"\n : \"@PrimaryGeneratedColumn()\"\n }\n id: ${database === \"mongodb\" ? \"ObjectId\" : \"number\"}\n\n @Column()\n firstName: string\n\n @Column()\n lastName: string\n\n @Column()\n age: number\n\n}\n`\n }\n\n /**\n * Gets contents of the route file (used when express is enabled).\n */\n protected static getRoutesTemplate(isEsm: boolean): string {\n return `import { UserController } from \"./controller/UserController${\n isEsm ? \".js\" : \"\"\n }\"\n\nexport const Routes = [{\n method: \"get\",\n route: \"/users\",\n controller: UserController,\n action: \"all\"\n}, {\n method: \"get\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"one\"\n}, {\n method: \"post\",\n route: \"/users\",\n controller: UserController,\n action: \"save\"\n}, {\n method: \"delete\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"remove\"\n}]`\n }\n\n /**\n * Gets contents of the user controller file (used when express is enabled).\n */\n protected static getControllerTemplate(isEsm: boolean): string {\n return `import { AppDataSource } from \"../data-source${\n isEsm ? \".js\" : \"\"\n }\"\nimport { NextFunction, Request, Response } from \"express\"\nimport { User } from \"../entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport class UserController {\n\n private userRepository = AppDataSource.getRepository(User)\n\n async all(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.find()\n }\n\n async one(request: Request, response: Response, next: NextFunction) {\n const id = parseInt(request.params.id)\n\n\n const user = await this.userRepository.findOne({\n where: { id }\n })\n\n if (!user) {\n return \"unregistered user\"\n }\n return user\n }\n\n async save(request: Request, response: Response, next: NextFunction) {\n const { firstName, lastName, age } = request.body;\n\n const user = Object.assign(new User(), {\n firstName,\n lastName,\n age\n })\n\n return this.userRepository.save(user)\n }\n\n async remove(request: Request, response: Response, next: NextFunction) {\n const id = parseInt(request.params.id)\n\n let userToRemove = await this.userRepository.findOneBy({ id })\n\n if (!userToRemove) {\n return \"this user not exist\"\n }\n\n await this.userRepository.remove(userToRemove)\n\n return \"user has been removed\"\n }\n\n}`\n }\n\n /**\n * Gets contents of the main (index) application file.\n */\n protected static getAppIndexTemplate(\n express: boolean,\n isEsm: boolean,\n ): string {\n if (express) {\n return `import ${!isEsm ? \"* as \" : \"\"}express from \"express\"\nimport ${!isEsm ? \"* as \" : \"\"}bodyParser from \"body-parser\"\nimport { Request, Response } from \"express\"\nimport { AppDataSource } from \"./data-source${isEsm ? \".js\" : \"\"}\"\nimport { Routes } from \"./routes${isEsm ? \".js\" : \"\"}\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n // create express app\n const app = express()\n app.use(bodyParser.json())\n\n // register express routes from defined application routes\n Routes.forEach(route => {\n (app as any)[route.method](route.route, (req: Request, res: Response, next: Function) => {\n const result = (new (route.controller as any))[route.action](req, res, next)\n if (result instanceof Promise) {\n result.then(result => result !== null && result !== undefined ? res.send(result) : undefined)\n\n } else if (result !== null && result !== undefined) {\n res.json(result)\n }\n })\n })\n\n // setup express app here\n // ...\n\n // start express server\n app.listen(3000)\n\n // insert new users for test\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Timber\",\n lastName: \"Saw\",\n age: 27\n })\n )\n\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Phantom\",\n lastName: \"Assassin\",\n age: 24\n })\n )\n\n console.log(\"Express server has started on port 3000. Open http://localhost:3000/users to see results\")\n\n}).catch(error => console.log(error))\n`\n } else {\n return `import { AppDataSource } from \"./data-source${\n isEsm ? \".js\" : \"\"\n }\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n console.log(\"Inserting a new user into the database...\")\n const user = new User()\n user.firstName = \"Timber\"\n user.lastName = \"Saw\"\n user.age = 25\n await AppDataSource.manager.save(user)\n console.log(\"Saved a new user with id: \" + user.id)\n\n console.log(\"Loading users from the database...\")\n const users = await AppDataSource.manager.find(User)\n console.log(\"Loaded users: \", users)\n\n console.log(\"Here you can setup and run express / fastify / any other framework.\")\n\n}).catch(error => console.log(error))\n`\n }\n }\n\n /**\n * Gets contents of the new package.json file.\n */\n protected static getPackageJsonTemplate(\n projectName?: string,\n projectIsEsm?: boolean,\n ): string {\n return JSON.stringify(\n {\n name: projectName || \"typeorm-sample\",\n version: \"0.0.1\",\n description: \"Awesome project developed with TypeORM.\",\n type: projectIsEsm ? \"module\" : \"commonjs\",\n devDependencies: {},\n dependencies: {},\n scripts: {},\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the new docker-compose.yml file.\n */\n protected static getDockerComposeTemplate(database: string): string {\n switch (database) {\n case \"mysql\":\n return `version: '3'\nservices:\n\n mysql:\n image: \"mysql:8.0.30\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"mariadb\":\n return `version: '3'\nservices:\n\n mariadb:\n image: \"mariadb:10.8.4\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"postgres\":\n return `version: '3'\nservices:\n\n postgres:\n image: \"postgres:14.5\"\n ports:\n - \"5432:5432\"\n environment:\n POSTGRES_USER: \"test\"\n POSTGRES_PASSWORD: \"test\"\n POSTGRES_DB: \"test\"\n\n`\n case \"cockroachdb\":\n return `version: '3'\nservices:\n\n cockroachdb:\n image: \"cockroachdb/cockroach:v22.1.6\"\n command: start --insecure\n ports:\n - \"26257:26257\"\n\n`\n case \"sqlite\":\n case \"better-sqlite3\":\n return `version: '3'\nservices:\n`\n case \"oracle\":\n throw new TypeORMError(\n `You cannot initialize a project with docker for Oracle driver yet.`,\n ) // todo: implement for oracle as well\n\n case \"mssql\":\n return `version: '3'\nservices:\n\n mssql:\n image: \"microsoft/mssql-server-linux:rc2\"\n ports:\n - \"1433:1433\"\n environment:\n SA_PASSWORD: \"Admin12345\"\n ACCEPT_EULA: \"Y\"\n\n`\n case \"mongodb\":\n return `version: '3'\nservices:\n\n mongodb:\n image: \"mongo:5.0.12\"\n container_name: \"typeorm-mongodb\"\n ports:\n - \"27017:27017\"\n\n`\n case \"spanner\":\n return `version: '3'\nservices:\n\n spanner:\n image: gcr.io/cloud-spanner-emulator/emulator:1.4.1\n ports:\n - \"9010:9010\"\n - \"9020:9020\"\n\n`\n }\n return \"\"\n }\n\n /**\n * Gets contents of the new readme.md file.\n */\n protected static getReadmeTemplate(options: { docker: boolean }): string {\n let template = `# Awesome Project Build with TypeORM\n\nSteps to run this project:\n\n1. Run \\`npm i\\` command\n`\n\n if (options.docker) {\n template += `2. Run \\`docker-compose up\\` command\n`\n } else {\n template += `2. Setup database settings inside \\`data-source.ts\\` file\n`\n }\n\n template += `3. Run \\`npm start\\` command\n`\n return template\n }\n\n /**\n * Appends to a given package.json template everything needed.\n */\n protected static appendPackageJson(\n packageJsonContents: string,\n database: string,\n express: boolean,\n projectIsEsm: boolean /*, docker: boolean*/,\n ): string {\n const packageJson = JSON.parse(packageJsonContents)\n\n if (!packageJson.devDependencies) packageJson.devDependencies = {}\n Object.assign(packageJson.devDependencies, {\n \"ts-node\": \"10.9.1\",\n \"@types/node\": \"^16.11.10\",\n typescript: \"4.5.2\",\n })\n\n if (!packageJson.dependencies) packageJson.dependencies = {}\n Object.assign(packageJson.dependencies, {\n typeorm:\n require(\"../package.json\").version !== \"0.0.0\"\n ? require(\"../package.json\").version // install version from package.json if present\n : require(\"../package.json\").installFrom, // else use custom source\n \"reflect-metadata\": \"^0.1.13\",\n })\n\n switch (database) {\n case \"mysql\":\n case \"mariadb\":\n packageJson.dependencies[\"mysql\"] = \"^2.14.1\"\n break\n case \"postgres\":\n case \"cockroachdb\":\n packageJson.dependencies[\"pg\"] = \"^8.4.0\"\n break\n case \"sqlite\":\n packageJson.dependencies[\"sqlite3\"] = \"^5.0.2\"\n break\n case \"better-sqlite3\":\n packageJson.dependencies[\"better-sqlite3\"] = \"^8.0.0\"\n break\n case \"oracle\":\n packageJson.dependencies[\"oracledb\"] = \"^5.1.0\"\n break\n case \"mssql\":\n packageJson.dependencies[\"mssql\"] = \"^9.1.1\"\n break\n case \"mongodb\":\n packageJson.dependencies[\"mongodb\"] = \"^5.2.0\"\n break\n case \"spanner\":\n packageJson.dependencies[\"@google-cloud/spanner\"] = \"^5.18.0\"\n break\n }\n\n if (express) {\n packageJson.dependencies[\"express\"] = \"^4.17.2\"\n packageJson.dependencies[\"body-parser\"] = \"^1.19.1\"\n }\n\n if (!packageJson.scripts) packageJson.scripts = {}\n\n if (projectIsEsm)\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"node --loader ts-node/esm src/index.ts\",\n typeorm: \"typeorm-ts-node-esm\",\n })\n else\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"ts-node src/index.ts\",\n typeorm: \"typeorm-ts-node-commonjs\",\n })\n\n return JSON.stringify(packageJson, undefined, 3)\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../../src/commands/InitCommand.ts"],"names":[],"mappings":";;;;AAAA,0DAAwB;AACxB,iDAAoC;AACpC,wDAAuB;AAEvB,oCAAuC;AACvC,6DAAyD;AACzD,iDAA6C;AAE7C;;GAEG;AACH,MAAa,WAAW;IAAxB;QACI,YAAO,GAAG,MAAM,CAAA;QAChB,aAAQ,GACJ,+CAA+C;YAC/C,wEAAwE;YACxE,mEAAmE,CAAA;IAiuB3E,CAAC;IA/tBG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,gCAAgC;SAC7C,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,2CAA2C;SACxD,CAAC;aACD,MAAM,CAAC,SAAS,EAAE;YACf,QAAQ,EACJ,8FAA8F;SACrG,CAAC;aACD,MAAM,CAAC,QAAQ,EAAE;YACd,QAAQ,EACJ,4EAA4E;SACnF,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,SAAS;YAChB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;YACxB,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,oDAAoD;SACjE,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,QAAQ;YACf,OAAO,EAAE,CAAC,UAAU,EAAE,KAAK,CAAC;YAC5B,OAAO,EAAE,UAAU;YACnB,QAAQ,EACJ,wEAAwE;SAC/E,CAAC,CAAA;IACV,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI,CAAC;YACD,MAAM,QAAQ,GAAY,IAAI,C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Y,CAAC,uBAAuB,CAAC,GAAG,SAAS,CAAA;gBAC7D,MAAK;QACb,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACV,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,SAAS,CAAA;YAC/C,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC,GAAG,SAAS,CAAA;QACvD,CAAC;QAED,IAAI,CAAC,WAAW,CAAC,OAAO;YAAE,WAAW,CAAC,OAAO,GAAG,EAAE,CAAA;QAElD,IAAI,YAAY;YACZ,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,wCAAwC;gBAC9F,OAAO,EAAE,qBAAqB;aACjC,CAAC,CAAA;;YAEF,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,sBAAsB;gBAC5E,OAAO,EAAE,0BAA0B;aACtC,CAAC,CAAA;QAEN,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;IACpD,CAAC;CACJ;AAtuBD,kCAsuBC","file":"InitCommand.js","sourcesContent":["import ansi from \"ansis\"\nimport { exec } from \"child_process\"\nimport path from \"path\"\nimport yargs from \"yargs\"\nimport { TypeORMError } from \"../error\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Generates a new project with TypeORM.\n */\nexport class InitCommand implements yargs.CommandModule {\n command = \"init\"\n describe =\n \"Generates initial TypeORM project structure. \" +\n \"If name specified then creates files inside directory called as name. \" +\n \"If its not specified then creates files inside current directory.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the project directory.\",\n })\n .option(\"db\", {\n alias: \"database\",\n describe: \"Database type you'll use in your project.\",\n })\n .option(\"express\", {\n describe:\n \"Indicates if express server sample code should be included in the project. False by default.\",\n })\n .option(\"docker\", {\n describe:\n \"Set to true if docker-compose must be generated as well. False by default.\",\n })\n .option(\"pm\", {\n alias: \"manager\",\n choices: [\"npm\", \"yarn\"],\n default: \"npm\",\n describe: \"Install packages, expected values are npm or yarn.\",\n })\n .option(\"ms\", {\n alias: \"module\",\n choices: [\"commonjs\", \"esm\"],\n default: \"commonjs\",\n describe:\n \"Module system to use for project, expected values are commonjs or esm.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const database: string = (args.database as any) || \"postgres\"\n const isExpress = args.express !== undefined ? true : false\n const isDocker = args.docker !== undefined ? true : false\n const basePath = process.cwd() + (args.name ? \"/\" + args.name : \"\")\n const projectName = args.name\n ? path.basename(args.name as any)\n : undefined\n const installNpm = args.pm === \"yarn\" ? false : true\n const projectIsEsm = args.ms === \"esm\"\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.getPackageJsonTemplate(projectName, projectIsEsm),\n false,\n )\n if (isDocker)\n await CommandUtils.createFile(\n basePath + \"/docker-compose.yml\",\n InitCommand.getDockerComposeTemplate(database),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/.gitignore\",\n InitCommand.getGitIgnoreFile(),\n )\n await CommandUtils.createFile(\n basePath + \"/README.md\",\n InitCommand.getReadmeTemplate({ docker: isDocker }),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/tsconfig.json\",\n InitCommand.getTsConfigTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/entity/User.ts\",\n InitCommand.getUserEntityTemplate(database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/data-source.ts\",\n InitCommand.getAppDataSourceTemplate(projectIsEsm, database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/index.ts\",\n InitCommand.getAppIndexTemplate(isExpress, projectIsEsm),\n )\n await CommandUtils.createDirectories(basePath + \"/src/migration\")\n\n // generate extra files for express application\n if (isExpress) {\n await CommandUtils.createFile(\n basePath + \"/src/routes.ts\",\n InitCommand.getRoutesTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/controller/UserController.ts\",\n InitCommand.getControllerTemplate(projectIsEsm),\n )\n }\n\n const packageJsonContents = await CommandUtils.readFile(\n basePath + \"/package.json\",\n )\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.appendPackageJson(\n packageJsonContents,\n database,\n isExpress,\n projectIsEsm,\n ),\n )\n\n if (args.name) {\n console.log(\n ansi.green`Project created inside ${ansi.blue(\n basePath,\n )} directory.`,\n )\n } else {\n console.log(\n ansi.green`Project created inside current directory.`,\n )\n }\n\n console.log(ansi.green`Please wait, installing dependencies...`)\n if (args.pm && installNpm) {\n await InitCommand.executeCommand(\"npm install\", basePath)\n } else {\n await InitCommand.executeCommand(\"yarn install\", basePath)\n }\n\n console.log(ansi.green`Done! Start playing with a new project!`)\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during project initialization:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n protected static executeCommand(command: string, cwd: string) {\n return new Promise<string>((ok, fail) => {\n exec(command, { cwd }, (error: any, stdout: any, stderr: any) => {\n if (stdout) return ok(stdout)\n if (stderr) return fail(stderr)\n if (error) return fail(error)\n ok(\"\")\n })\n })\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getAppDataSourceTemplate(\n isEsm: boolean,\n database: string,\n ): string {\n let dbSettings = \"\"\n switch (database) {\n case \"mysql\":\n dbSettings = `type: \"mysql\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"mariadb\":\n dbSettings = `type: \"mariadb\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"sqlite\":\n dbSettings = `type: \"sqlite\",\n database: \"database.sqlite\",`\n break\n case \"better-sqlite3\":\n dbSettings = `type: \"better-sqlite3\",\n database: \"database.sqlite\",`\n break\n case \"postgres\":\n dbSettings = `type: \"postgres\",\n host: \"localhost\",\n port: 5432,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"cockroachdb\":\n dbSettings = `type: \"cockroachdb\",\n host: \"localhost\",\n port: 26257,\n username: \"root\",\n password: \"\",\n database: \"defaultdb\",`\n break\n case \"mssql\":\n dbSettings = `type: \"mssql\",\n host: \"localhost\",\n username: \"sa\",\n password: \"Admin12345\",\n database: \"tempdb\",`\n break\n case \"oracle\":\n dbSettings = `type: \"oracle\",\nhost: \"localhost\",\nusername: \"system\",\npassword: \"oracle\",\nport: 1521,\nsid: \"xe.oracle.docker\",`\n break\n case \"mongodb\":\n dbSettings = `type: \"mongodb\",\n database: \"test\",`\n break\n case \"spanner\":\n dbSettings = `type: \"spanner\",\n projectId: \"test\",\n instanceId: \"test\",\n databaseId: \"test\",`\n break\n }\n return `import \"reflect-metadata\"\nimport { DataSource } from \"typeorm\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport const AppDataSource = new DataSource({\n ${dbSettings}\n synchronize: true,\n logging: false,\n entities: [User],\n migrations: [],\n subscribers: [],\n})\n`\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getTsConfigTemplate(esmModule: boolean): string {\n if (esmModule)\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es2021\"],\n target: \"es2021\",\n module: \"es2022\",\n moduleResolution: \"node\",\n allowSyntheticDefaultImports: true,\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n else\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es5\", \"es6\"],\n target: \"es5\",\n module: \"commonjs\",\n moduleResolution: \"node\",\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the .gitignore file.\n */\n protected static getGitIgnoreFile(): string {\n return `.idea/\n.vscode/\nnode_modules/\nbuild/\ntmp/\ntemp/`\n }\n\n /**\n * Gets contents of the user entity.\n */\n protected static getUserEntityTemplate(database: string): string {\n return `import { Entity, ${\n database === \"mongodb\"\n ? \"ObjectIdColumn, ObjectId\"\n : \"PrimaryGeneratedColumn\"\n }, Column } from \"typeorm\"\n\n@Entity()\nexport class User {\n\n ${\n database === \"mongodb\"\n ? \"@ObjectIdColumn()\"\n : \"@PrimaryGeneratedColumn()\"\n }\n id: ${database === \"mongodb\" ? \"ObjectId\" : \"number\"}\n\n @Column()\n firstName: string\n\n @Column()\n lastName: string\n\n @Column()\n age: number\n\n}\n`\n }\n\n /**\n * Gets contents of the route file (used when express is enabled).\n */\n protected static getRoutesTemplate(isEsm: boolean): string {\n return `import { UserController } from \"./controller/UserController${\n isEsm ? \".js\" : \"\"\n }\"\n\nexport const Routes = [{\n method: \"get\",\n route: \"/users\",\n controller: UserController,\n action: \"all\"\n}, {\n method: \"get\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"one\"\n}, {\n method: \"post\",\n route: \"/users\",\n controller: UserController,\n action: \"save\"\n}, {\n method: \"delete\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"remove\"\n}]`\n }\n\n /**\n * Gets contents of the user controller file (used when express is enabled).\n */\n protected static getControllerTemplate(isEsm: boolean): string {\n return `import { AppDataSource } from \"../data-source${\n isEsm ? \".js\" : \"\"\n }\"\nimport { NextFunction, Request, Response } from \"express\"\nimport { User } from \"../entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport class UserController {\n\n private userRepository = AppDataSource.getRepository(User)\n\n async all(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.find()\n }\n\n async one(request: Request, response: Response, next: NextFunction) {\n const id = parseInt(request.params.id)\n\n\n const user = await this.userRepository.findOne({\n where: { id }\n })\n\n if (!user) {\n return \"unregistered user\"\n }\n return user\n }\n\n async save(request: Request, response: Response, next: NextFunction) {\n const { firstName, lastName, age } = request.body;\n\n const user = Object.assign(new User(), {\n firstName,\n lastName,\n age\n })\n\n return this.userRepository.save(user)\n }\n\n async remove(request: Request, response: Response, next: NextFunction) {\n const id = parseInt(request.params.id)\n\n let userToRemove = await this.userRepository.findOneBy({ id })\n\n if (!userToRemove) {\n return \"this user not exist\"\n }\n\n await this.userRepository.remove(userToRemove)\n\n return \"user has been removed\"\n }\n\n}`\n }\n\n /**\n * Gets contents of the main (index) application file.\n */\n protected static getAppIndexTemplate(\n express: boolean,\n isEsm: boolean,\n ): string {\n if (express) {\n return `import ${!isEsm ? \"* as \" : \"\"}express from \"express\"\nimport ${!isEsm ? \"* as \" : \"\"}bodyParser from \"body-parser\"\nimport { Request, Response } from \"express\"\nimport { AppDataSource } from \"./data-source${isEsm ? \".js\" : \"\"}\"\nimport { Routes } from \"./routes${isEsm ? \".js\" : \"\"}\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n // create express app\n const app = express()\n app.use(bodyParser.json())\n\n // register express routes from defined application routes\n Routes.forEach(route => {\n (app as any)[route.method](route.route, (req: Request, res: Response, next: Function) => {\n const result = (new (route.controller as any))[route.action](req, res, next)\n if (result instanceof Promise) {\n result.then(result => result !== null && result !== undefined ? res.send(result) : undefined)\n\n } else if (result !== null && result !== undefined) {\n res.json(result)\n }\n })\n })\n\n // setup express app here\n // ...\n\n // start express server\n app.listen(3000)\n\n // insert new users for test\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Timber\",\n lastName: \"Saw\",\n age: 27\n })\n )\n\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Phantom\",\n lastName: \"Assassin\",\n age: 24\n })\n )\n\n console.log(\"Express server has started on port 3000. Open http://localhost:3000/users to see results\")\n\n}).catch(error => console.log(error))\n`\n } else {\n return `import { AppDataSource } from \"./data-source${\n isEsm ? \".js\" : \"\"\n }\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n console.log(\"Inserting a new user into the database...\")\n const user = new User()\n user.firstName = \"Timber\"\n user.lastName = \"Saw\"\n user.age = 25\n await AppDataSource.manager.save(user)\n console.log(\"Saved a new user with id: \" + user.id)\n\n console.log(\"Loading users from the database...\")\n const users = await AppDataSource.manager.find(User)\n console.log(\"Loaded users: \", users)\n\n console.log(\"Here you can setup and run express / fastify / any other framework.\")\n\n}).catch(error => console.log(error))\n`\n }\n }\n\n /**\n * Gets contents of the new package.json file.\n */\n protected static getPackageJsonTemplate(\n projectName?: string,\n projectIsEsm?: boolean,\n ): string {\n return JSON.stringify(\n {\n name: projectName || \"typeorm-sample\",\n version: \"0.0.1\",\n description: \"Awesome project developed with TypeORM.\",\n type: projectIsEsm ? \"module\" : \"commonjs\",\n devDependencies: {},\n dependencies: {},\n scripts: {},\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the new docker-compose.yml file.\n */\n protected static getDockerComposeTemplate(database: string): string {\n switch (database) {\n case \"mysql\":\n return `version: '3'\nservices:\n\n mysql:\n image: \"mysql:8.0.30\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"mariadb\":\n return `version: '3'\nservices:\n\n mariadb:\n image: \"mariadb:10.8.4\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"postgres\":\n return `version: '3'\nservices:\n\n postgres:\n image: \"postgres:14.5\"\n ports:\n - \"5432:5432\"\n environment:\n POSTGRES_USER: \"test\"\n POSTGRES_PASSWORD: \"test\"\n POSTGRES_DB: \"test\"\n\n`\n case \"cockroachdb\":\n return `version: '3'\nservices:\n\n cockroachdb:\n image: \"cockroachdb/cockroach:v22.1.6\"\n command: start --insecure\n ports:\n - \"26257:26257\"\n\n`\n case \"sqlite\":\n case \"better-sqlite3\":\n return `version: '3'\nservices:\n`\n case \"oracle\":\n throw new TypeORMError(\n `You cannot initialize a project with docker for Oracle driver yet.`,\n ) // todo: implement for oracle as well\n\n case \"mssql\":\n return `version: '3'\nservices:\n\n mssql:\n image: \"microsoft/mssql-server-linux:rc2\"\n ports:\n - \"1433:1433\"\n environment:\n SA_PASSWORD: \"Admin12345\"\n ACCEPT_EULA: \"Y\"\n\n`\n case \"mongodb\":\n return `version: '3'\nservices:\n\n mongodb:\n image: \"mongo:5.0.12\"\n container_name: \"typeorm-mongodb\"\n ports:\n - \"27017:27017\"\n\n`\n case \"spanner\":\n return `version: '3'\nservices:\n\n spanner:\n image: gcr.io/cloud-spanner-emulator/emulator:1.4.1\n ports:\n - \"9010:9010\"\n - \"9020:9020\"\n\n`\n }\n return \"\"\n }\n\n /**\n * Gets contents of the new readme.md file.\n */\n protected static getReadmeTemplate(options: { docker: boolean }): string {\n let template = `# Awesome Project Build with TypeORM\n\nSteps to run this project:\n\n1. Run \\`npm i\\` command\n`\n\n if (options.docker) {\n template += `2. Run \\`docker-compose up\\` command\n`\n } else {\n template += `2. Setup database settings inside \\`data-source.ts\\` file\n`\n }\n\n template += `3. Run \\`npm start\\` command\n`\n return template\n }\n\n /**\n * Appends to a given package.json template everything needed.\n */\n protected static appendPackageJson(\n packageJsonContents: string,\n database: string,\n express: boolean,\n projectIsEsm: boolean /*, docker: boolean*/,\n ): string {\n const packageJson = JSON.parse(packageJsonContents)\n\n if (!packageJson.devDependencies) packageJson.devDependencies = {}\n Object.assign(packageJson.devDependencies, {\n \"ts-node\": \"10.9.1\",\n \"@types/node\": \"^16.11.10\",\n typescript: \"4.5.2\",\n })\n\n if (!packageJson.dependencies) packageJson.dependencies = {}\n Object.assign(packageJson.dependencies, {\n typeorm:\n require(\"../package.json\").version !== \"0.0.0\"\n ? require(\"../package.json\").version // install version from package.json if present\n : require(\"../package.json\").installFrom, // else use custom source\n \"reflect-metadata\": \"^0.1.13\",\n })\n\n switch (database) {\n case \"mysql\":\n case \"mariadb\":\n packageJson.dependencies[\"mysql\"] = \"^2.14.1\"\n break\n case \"postgres\":\n case \"cockroachdb\":\n packageJson.dependencies[\"pg\"] = \"^8.4.0\"\n break\n case \"sqlite\":\n packageJson.dependencies[\"sqlite3\"] = \"^5.0.2\"\n break\n case \"better-sqlite3\":\n packageJson.dependencies[\"better-sqlite3\"] = \"^8.0.0\"\n break\n case \"oracle\":\n packageJson.dependencies[\"oracledb\"] = \"^5.1.0\"\n break\n case \"mssql\":\n packageJson.dependencies[\"mssql\"] = \"^9.1.1\"\n break\n case \"mongodb\":\n packageJson.dependencies[\"mongodb\"] = \"^5.2.0\"\n break\n case \"spanner\":\n packageJson.dependencies[\"@google-cloud/spanner\"] = \"^5.18.0\"\n break\n }\n\n if (express) {\n packageJson.dependencies[\"express\"] = \"^4.17.2\"\n packageJson.dependencies[\"body-parser\"] = \"^1.19.1\"\n }\n\n if (!packageJson.scripts) packageJson.scripts = {}\n\n if (projectIsEsm)\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"node --loader ts-node/esm src/index.ts\",\n typeorm: \"typeorm-ts-node-esm\",\n })\n else\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"ts-node src/index.ts\",\n typeorm: \"typeorm-ts-node-commonjs\",\n })\n\n return JSON.stringify(packageJson, undefined, 3)\n }\n}\n"],"sourceRoot":".."}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MigrationCreateCommand = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
6
|
-
const StringUtils_1 = require("../util/StringUtils");
|
|
7
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
8
|
-
const PlatformTools_1 = require("../platform/PlatformTools");
|
|
5
|
+
const ansis_1 = tslib_1.__importDefault(require("ansis"));
|
|
9
6
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
+
const PlatformTools_1 = require("../platform/PlatformTools");
|
|
8
|
+
const StringUtils_1 = require("../util/StringUtils");
|
|
9
|
+
const CommandUtils_1 = require("./CommandUtils");
|
|
10
10
|
/**
|
|
11
11
|
* Creates a new migration file.
|
|
12
12
|
*/
|
|
@@ -47,7 +47,7 @@ class MigrationCreateCommand {
|
|
|
47
47
|
? MigrationCreateCommand.getJavascriptTemplate(filename, timestamp)
|
|
48
48
|
: MigrationCreateCommand.getTemplate(filename, timestamp);
|
|
49
49
|
await CommandUtils_1.CommandUtils.createFile(fullPath + (args.outputJs ? ".js" : ".ts"), fileContent);
|
|
50
|
-
console.log(`Migration ${
|
|
50
|
+
console.log(`Migration ${ansis_1.default.blue(fullPath + (args.outputJs ? ".js" : ".ts"))} has been generated successfully.`);
|
|
51
51
|
}
|
|
52
52
|
catch (err) {
|
|
53
53
|
PlatformTools_1.PlatformTools.logCmdErr("Error during migration creation:", err);
|