Skip to content

Commit

Permalink
finalizando criacao dos arquivos de configuracao na raiz do projeto e…
Browse files Browse the repository at this point in the history
… criacao do diretorio @types #3
  • Loading branch information
filipeas committed Apr 8, 2022
1 parent 6d3ea49 commit b9d0189
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 4 deletions.
1 change: 0 additions & 1 deletion bin/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function createStructure(entity) {
console.log("criando estrutura");

// caminhos
const directoryEntity = path.join(__dirname, "entity");
const destination = path.join(__dirname, "..", "..", "..", "..", "src");
const dirDomain = path.join(__dirname, "..", "..", "..", "..", "src", "domain");
const dirEntity = path.join(__dirname, "..", "..", "..", "..", "src", "domain", entity);
Expand Down
26 changes: 23 additions & 3 deletions bin/init.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
module.exports = { initStructure: initStructure };

function initStructure(){
console.log("Iniciando criação da estrutura");
}
const fs = require("fs");
const path = require("path");
const createRoot = require("./root/createRoot.js");
const createTypes = require("./root/createTypes.js");

function initStructure() {
console.log("Iniciando criação da estrutura.");

// caminhos
const destinationRaiz = path.join(__dirname, "..", "..");// "..", ".."
const destinationTypes = path.join(__dirname, "..", "..", "@types");// "..", ".."
const destinationTypesExpress = path.join(__dirname, "..", "..", "@types", "express");//"..", ".."

// criar .env.example
createRoot.createFile(destinationRaiz);

// cria diretorios para @types
if (!fs.existsSync(destinationTypes)) fs.mkdirSync(destinationTypes);
if (!fs.existsSync(destinationTypesExpress)) fs.mkdirSync(destinationTypesExpress);

// criar diretorio e arquivo @types
createTypes.createFile(destinationTypesExpress);
}
188 changes: 188 additions & 0 deletions bin/root/createRoot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
module.exports = { createFile: createFile };

const fs = require("fs");
const path = require("path");

function createFile(destinationRaiz) {
// criando .env.example
fs.appendFile(
path.join(destinationRaiz, ".env.example"),
`
# App configuration
APP_PORT=
APP_URL=
# Database configuration
DB_TYPE=
DB_HOST=
DB_PORT=
DB_USER=
DB_PASSWORD=
DB_DATABASE=
# ORM configuration
DB_MIGRATIONS_PATH=./src/infra/typeorm/migrations/*.ts
DB_ENTITIES=./src/domain/**/entities/*.ts
DB_MIGRATIONS_DIR=./src/infra/typeorm/migrations
#key authentication
KEY_AUTH=
`, function (err) {
if (err) throw err;
console.log("Arquivo .env.example criado com sucesso.");
});

// criando .editorconfig
fs.appendFile(
path.join(destinationRaiz, ".editorconfig"),
`
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
`, function (err) {
if (err) throw err;
console.log("Arquivo .editorconfig criado com sucesso.");
});

// criando .eslintignore
fs.appendFile(
path.join(destinationRaiz, ".eslintignore"),
`
/*.js
node_modules
dist
`, function (err) {
if (err) throw err;
console.log("Arquivo .eslintignore criado com sucesso.");
});

// criando .eslintrc.json
fs.appendFile(
path.join(destinationRaiz, ".eslintrc.json"),
`
{
"env": {
"es2021": true,
"node": true
},
"extends": [
"airbnb-base",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"prettier"
],
"rules": {
"class-methods-use-this": "off",
"no-useless-constructor": "off",
"import/prefer-default-export": "off",
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": [
"error"
],
"import/extensions": [
"error",
"ignorePackages",
{
"ts": "never"
}
],
"prettier/prettier": "error"
},
"settings": {
"import/resolver": {
"typescript": {}
}
}
}
`, function (err) {
if (err) throw err;
console.log("Arquivo .eslintrc.json criado com sucesso.");
});

// criando ormconfig.js
fs.appendFile(
path.join(destinationRaiz, "ormconfig.js"),
`
require('dotenv/config');
module.exports = {
name: 'default',
type: process.env.DB_TYPE,
host: process.env.DB_HOST,
port: process.env.DB_PORT,
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
migrations: [process.env.DB_MIGRATIONS_PATH],
entities: [process.env.DB_ENTITIES],
cli: {
migrationsDir: process.env.DB_MIGRATIONS_DIR
}
}
`, function (err) {
if (err) throw err;
console.log("Arquivo ormconfig.js criado com sucesso.");
});

// criando prettier.config.js
fs.appendFile(
path.join(destinationRaiz, "prettier.config.js"),
`
module.exports = {
singleQuote: true,
trailingComma: 'all',
arrowParens: 'avoid',
}
`, function (err) {
if (err) throw err;
console.log("Arquivo prettier.config.js criado com sucesso.");
});

// criando tsconfig.json
fs.appendFile(
path.join(destinationRaiz, "tsconfig.json"),
`
{
"compilerOptions": {
"target": "es2021",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"@domain/*": [
"./src/domain/*"
],
"@infra/*": [
"./src/infra/*"
]
}
}
}
`, function (err) {
if (err) throw err;
console.log("Arquivo tsconfig.json criado com sucesso.");
});
}
20 changes: 20 additions & 0 deletions bin/root/createTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = { createFile: createFile };

const fs = require("fs");
const path = require("path");

function createFile(destinationTypesExpress) {
fs.appendFile(
path.join(destinationTypesExpress, "index.js"),
`declare namespace Express {
export interface Request {
user: {
id: string;
};
}
}
`, function (err) {
if (err) throw err;
console.log("Arquivo index.js criado com sucesso.");
});
}

0 comments on commit b9d0189

Please sign in to comment.