Skip to content

Commit

Permalink
Feat/v1.3.1 (#9)
Browse files Browse the repository at this point in the history
update/deps

fix/ignore-camel-case-for-uppercase-fields

feat/tests-and-fix-enum-mapping

feat/coverage-check

feat/custom-generators-print
  • Loading branch information
RaresAil authored Nov 25, 2022
1 parent 008746b commit b8980e7
Show file tree
Hide file tree
Showing 20 changed files with 2,505 additions and 602 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
Expand All @@ -11,6 +8,7 @@ on:

jobs:
build:
name: Build
runs-on: ubuntu-latest

strategy:
Expand All @@ -23,7 +21,12 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm install -g yarn
- run: yarn install
- run: yarn build
cache: 'yarn'
- name: Install Dependencies
run: yarn install --frozen-lockfile
- name: Audit
run: yarn audit
- name: Tests
run: yarn test
- name: Build
run: yarn build
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,5 @@ bin
.vscode
prisma
prisma-mapper.json
.DS_Store
.DS_Store
out.prisma
114 changes: 114 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

bin
.vscode
prisma
prisma-mapper.json
.DS_Store

__tests__
jest
.github
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# prisma-mapper

[![CodeQL](https://github.com/RaresAil/prisma-mapper/actions/workflows/codeql.yml/badge.svg?branch=master)](https://github.com/RaresAil/prisma-mapper/actions/workflows/codeql.yml)
[![Node.js CI](https://github.com/RaresAil/prisma-mapper/actions/workflows/node.js.yml/badge.svg)](https://github.com/RaresAil/prisma-mapper/actions/workflows/node.js.yml)

![NPM Package Downloads](https://badgen.net/npm/dm/prisma-mapper)
![Snyk Vulnerabilities for NPM Package](https://img.shields.io/snyk/vulnerabilities/npm/prisma-mapper)
Expand All @@ -9,11 +10,11 @@ A CLI that adds @map and @@map based on a json

### Features

- Adds @map and @@map
- Keeps the @db. attributes for fields
- Adds the @updatedAt for fields with the name `updated_at` or `updatedAt`
- Adds `@map` and `@@map`
- Keeps the `@db.` attributes for fields
- Adds the `@updatedAt` for fields with the name `updated_at` or `updatedAt`
- The prisma schema is formatted by the `@prisma/internals` after generation
- The cli does not modify the current schema and generates a new one with the info from the current one
- The cli does not modify the current schema and generates a new one with the information from the current one

### Getting Started

Expand All @@ -26,11 +27,19 @@ yarn prisma db pull --force
&& yarn prisma generate
```

or for `camelCase` by default

```bash
yarn prisma db pull --force
&& yarn prisma-mapper map --camel
&& yarn prisma generate
```

With db pull force you get the latest schema updates and
force overwrites the file.

The generate command creates a json called `prisma-mapper.json` in the root,
if the json already exists it adds in it any new fields/models.
if the json already exists it adds in it any new fields/models. **`(NOT FOR --camel option)`**

```bash
yarn prisma-mapper generate
Expand All @@ -39,8 +48,8 @@ yarn prisma-mapper generate
The json looks like the following:

- The hasMap is added by generate if the prisma model has already a `@@map`
- The name is to add @@map for a model name
- In the fields object is to add @map for each field
- The name is to add `@@map` for a model name
- In the fields object is to add `@map` for each field

```json
{
Expand Down
15 changes: 15 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
clearMocks: true,
collectCoverage: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',
coveragePathIgnorePatterns: [
'/node_modules/',
'/src/CLIError.ts',
'/src/Utils.ts',
'/src/index.ts'
]
};
49 changes: 33 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "prisma-mapper",
"version": "1.3.0",
"description": "A CLI that adds @Map and @@Map based on a json or camel case for the prisma schema",
"version": "1.3.1",
"description": "A CLI that adds @Map, @@Map, @updatedAt based on a json or camel case for the prisma schema",
"main": "bin/index.js",
"preferGlobal": true,
"bin": {
Expand All @@ -11,35 +11,52 @@
"files": [
"bin/*"
],
"keywords": [
"nodejs",
"mapper",
"prisma",
"cli",
"typescript",
"camel",
"camel-case",
"json",
"schema",
"map",
"generate"
],
"homepage": "https://github.com/RaresAil/prisma-mapper",
"repository": "https://github.com/RaresAil/prisma-mapper.git",
"author": "RaresAil <[email protected]>",
"license": "MIT",
"private": false,
"scripts": {
"dev:bin": "yarn build && NODE_ENV=dev node bin/commands.js",
"dev": "NODE_ENV=dev nodemon src/commands.ts",
"dev": "NODE_ENV=dev ts-node src/commands.ts",
"build": "yarn lint && rm -rf ./bin/ && tsc -p .",
"lint": "eslint src/**/*.ts"
"lint": "eslint src/**/*.ts",
"test": "jest"
},
"dependencies": {
"@prisma/internals": "^4.3.1",
"@prisma/internals": "^4.6.1",
"colors": "^1.4.0",
"commander": "^9.4.0",
"inquirer": "^9.1.2"
"commander": "^9.4.1",
"inquirer": "^9.1.4"
},
"devDependencies": {
"@types/inquirer": "^9.0.1",
"@types/node": "^18.7.18",
"@typescript-eslint/eslint-plugin": "^5.38.0",
"@typescript-eslint/parser": "^5.38.0",
"eslint": "^8.23.1",
"@types/inquirer": "^9.0.3",
"@types/jest": "^29.2.3",
"@types/node": "^18.11.9",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0",
"eslint": "^8.28.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.2.5",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-n": "^15.5.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-security": "^1.5.0",
"nodemon": "^2.0.20",
"jest": "^29.3.1",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"typescript": "4.8.3"
"typescript": "4.9.3"
}
}
7 changes: 7 additions & 0 deletions src/CLIError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default class CLIError extends Error {
constructor(message: string) {
super(message);
this.name = 'CLIError';
this.stack = '';
}
}
8 changes: 4 additions & 4 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import os from 'os';
import fs from 'fs';

export default abstract class Utils {
public static getUserDic(): string | undefined {
public static getUserDic(): string {
let findCommand;
const platform = os.platform();
const linuxPlatforms = [
Expand All @@ -21,7 +21,7 @@ export default abstract class Utils {
} else if (platform === 'win32') {
findCommand = 'cd';
} else {
return undefined;
return '';
}

let dir: string | undefined;
Expand All @@ -31,11 +31,11 @@ export default abstract class Utils {
.trim()
.replace(/\r?\n|\r/g, '');
} catch {
return undefined;
return '';
}

if (!fs.existsSync(nodePath.normalize(dir))) {
return undefined;
return '';
}

return dir;
Expand Down
Loading

0 comments on commit b8980e7

Please sign in to comment.