mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fixed small issues in commands
This commit is contained in:
parent
31c3b70eb2
commit
d91531deaa
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "typeorm",
|
||||
"private": true,
|
||||
"version": "0.1.0-alpha.4",
|
||||
"version": "0.1.0-alpha.8",
|
||||
"description": "Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, WebSQL, MongoDB databases.",
|
||||
"license": "MIT",
|
||||
"readmeFilename": "README.md",
|
||||
@ -78,10 +78,11 @@
|
||||
"dotenv": "^4.0.0",
|
||||
"glob": "^7.1.1",
|
||||
"js-yaml": "^3.8.4",
|
||||
"mkdirp": "^0.5.1",
|
||||
"reflect-metadata": "^0.1.10",
|
||||
"xml2js": "^0.4.17",
|
||||
"yargonaut": "^1.1.2",
|
||||
"yargs": "^8.0.1",
|
||||
"xml2js": "^0.4.17"
|
||||
"yargs": "^8.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node_modules/.bin/gulp tests"
|
||||
@ -89,4 +90,4 @@
|
||||
"bin": {
|
||||
"typeorm": "./cli.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
27
src/commands/CommandUtils.ts
Normal file
27
src/commands/CommandUtils.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
const mkdirp = require("mkdirp");
|
||||
|
||||
/**
|
||||
* Command line utils functions.
|
||||
*/
|
||||
export class CommandUtils {
|
||||
|
||||
/**
|
||||
* Creates directories recursively.
|
||||
*/
|
||||
static createDirectories(directory: string) {
|
||||
return new Promise((ok, fail) => mkdirp(directory, (err: any) => err ? fail(err) : ok()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file with the given content in the given path.
|
||||
*/
|
||||
static async createFile(filePath: string, content: string): Promise<void> {
|
||||
await CommandUtils.createDirectories(path.dirname(filePath));
|
||||
return new Promise<void>((ok, fail) => {
|
||||
fs.writeFile(filePath, content, err => err ? fail(err) : ok());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
import * as fs from "fs";
|
||||
import {ConnectionOptionsReader} from "../connection/ConnectionOptionsReader";
|
||||
import {CommandUtils} from "./CommandUtils";
|
||||
|
||||
/**
|
||||
* Generates a new entity.
|
||||
@ -45,22 +45,13 @@ export class EntityCreateCommand {
|
||||
} catch (err) { }
|
||||
}
|
||||
|
||||
await EntityCreateCommand.createFile(process.cwd() + "/" + (directory ? (directory + "/") : "") + filename, fileContent);
|
||||
await CommandUtils.createFile(process.cwd() + "/" + (directory ? (directory + "/") : "") + filename, fileContent);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Protected Static Methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates a file with the given content in the given path.
|
||||
*/
|
||||
protected static createFile(path: string, content: string): Promise<void> {
|
||||
return new Promise<void>((ok, fail) => {
|
||||
fs.writeFile(path, content, err => err ? fail(err) : ok());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets contents of the entity file.
|
||||
*/
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import * as fs from "fs";
|
||||
import {ConnectionOptions} from "../connection/ConnectionOptions";
|
||||
import {ConnectionOptionsReader} from "../connection/ConnectionOptionsReader";
|
||||
import {CommandUtils} from "./CommandUtils";
|
||||
const mkdirp = require("mkdirp");
|
||||
|
||||
/**
|
||||
* Creates a new migration file.
|
||||
@ -48,22 +49,13 @@ export class MigrationCreateCommand {
|
||||
} catch (err) { }
|
||||
}
|
||||
|
||||
await MigrationCreateCommand.createFile(process.cwd() + "/" + (directory ? (directory + "/") : "") + filename, fileContent);
|
||||
await CommandUtils.createFile(process.cwd() + "/" + (directory ? (directory + "/") : "") + filename, fileContent);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Protected Static Methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates a file with the given content in the given path.
|
||||
*/
|
||||
protected static createFile(path: string, content: string): Promise<void> {
|
||||
return new Promise<void>((ok, fail) => {
|
||||
fs.writeFile(path, content, err => err ? fail(err) : ok());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets contents of the migration file.
|
||||
*/
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import * as fs from "fs";
|
||||
import {ConnectionOptions} from "../connection/ConnectionOptions";
|
||||
import {ConnectionOptionsReader} from "../connection/ConnectionOptionsReader";
|
||||
import {CommandUtils} from "./CommandUtils";
|
||||
const mkdirp = require("mkdirp");
|
||||
|
||||
/**
|
||||
* Generates a new subscriber.
|
||||
@ -46,22 +47,13 @@ export class SubscriberCreateCommand {
|
||||
} catch (err) { }
|
||||
}
|
||||
|
||||
await SubscriberCreateCommand.createFile(process.cwd() + "/" + (directory ? (directory + "/") : "") + filename, fileContent);
|
||||
await CommandUtils.createFile(process.cwd() + "/" + (directory ? (directory + "/") : "") + filename, fileContent);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Protected Static Methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates a file with the given content in the given path.
|
||||
*/
|
||||
protected static createFile(path: string, content: string): Promise<void> {
|
||||
return new Promise<void>((ok, fail) => {
|
||||
fs.writeFile(path, content, err => err ? fail(err) : ok());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets contents of the entity file.
|
||||
*/
|
||||
|
||||
@ -35,6 +35,11 @@ export class ConnectionOptionsEnvReader {
|
||||
logQueries: OrmUtils.toBoolean(PlatformTools.getEnvVariable("TYPEORM_LOGGING_QUERIES")),
|
||||
logFailedQueryError: OrmUtils.toBoolean(PlatformTools.getEnvVariable("TYPEORM_LOGGING_FAILED_QUERIES")),
|
||||
logOnlyFailedQueries: OrmUtils.toBoolean(PlatformTools.getEnvVariable("TYPEORM_LOGGING_ONLY_FAILED_QUERIES")),
|
||||
},
|
||||
cli: {
|
||||
entitiesDir: PlatformTools.getEnvVariable("TYPEORM_ENTITIES_DIR"),
|
||||
migrationsDir: PlatformTools.getEnvVariable("TYPEORM_MIGRATIONS_DIR"),
|
||||
subscribersDir: PlatformTools.getEnvVariable("TYPEORM_SUBSCRIBERS_DIR"),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user