Skip to content

Commit b8980e7

Browse files
authored
Feat/v1.3.1 (#9)
update/deps fix/ignore-camel-case-for-uppercase-fields feat/tests-and-fix-enum-mapping feat/coverage-check feat/custom-generators-print
1 parent 008746b commit b8980e7

20 files changed

+2505
-602
lines changed

.github/workflows/node.js.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# 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
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3-
41
name: Node.js CI
52

63
on:
@@ -11,6 +8,7 @@ on:
118

129
jobs:
1310
build:
11+
name: Build
1412
runs-on: ubuntu-latest
1513

1614
strategy:
@@ -23,7 +21,12 @@ jobs:
2321
uses: actions/setup-node@v3
2422
with:
2523
node-version: ${{ matrix.node-version }}
26-
cache: 'npm'
27-
- run: npm install -g yarn
28-
- run: yarn install
29-
- run: yarn build
24+
cache: 'yarn'
25+
- name: Install Dependencies
26+
run: yarn install --frozen-lockfile
27+
- name: Audit
28+
run: yarn audit
29+
- name: Tests
30+
run: yarn test
31+
- name: Build
32+
run: yarn build

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,5 @@ bin
107107
.vscode
108108
prisma
109109
prisma-mapper.json
110-
.DS_Store
110+
.DS_Store
111+
out.prisma

.npmignore

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port
105+
106+
bin
107+
.vscode
108+
prisma
109+
prisma-mapper.json
110+
.DS_Store
111+
112+
__tests__
113+
jest
114+
.github

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# prisma-mapper
22

33
[![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)
4+
[![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)
45

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

1011
### Features
1112

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

1819
### Getting Started
1920

@@ -26,11 +27,19 @@ yarn prisma db pull --force
2627
&& yarn prisma generate
2728
```
2829

30+
or for `camelCase` by default
31+
32+
```bash
33+
yarn prisma db pull --force
34+
&& yarn prisma-mapper map --camel
35+
&& yarn prisma generate
36+
```
37+
2938
With db pull force you get the latest schema updates and
3039
force overwrites the file.
3140

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

3544
```bash
3645
yarn prisma-mapper generate
@@ -39,8 +48,8 @@ yarn prisma-mapper generate
3948
The json looks like the following:
4049

4150
- The hasMap is added by generate if the prisma model has already a `@@map`
42-
- The name is to add @@map for a model name
43-
- In the fields object is to add @map for each field
51+
- The name is to add `@@map` for a model name
52+
- In the fields object is to add `@map` for each field
4453

4554
```json
4655
{

jest.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
clearMocks: true,
6+
collectCoverage: true,
7+
coverageDirectory: 'coverage',
8+
coverageProvider: 'v8',
9+
coveragePathIgnorePatterns: [
10+
'/node_modules/',
11+
'/src/CLIError.ts',
12+
'/src/Utils.ts',
13+
'/src/index.ts'
14+
]
15+
};

package.json

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "prisma-mapper",
3-
"version": "1.3.0",
4-
"description": "A CLI that adds @Map and @@Map based on a json or camel case for the prisma schema",
3+
"version": "1.3.1",
4+
"description": "A CLI that adds @Map, @@Map, @updatedAt based on a json or camel case for the prisma schema",
55
"main": "bin/index.js",
66
"preferGlobal": true,
77
"bin": {
@@ -11,35 +11,52 @@
1111
"files": [
1212
"bin/*"
1313
],
14+
"keywords": [
15+
"nodejs",
16+
"mapper",
17+
"prisma",
18+
"cli",
19+
"typescript",
20+
"camel",
21+
"camel-case",
22+
"json",
23+
"schema",
24+
"map",
25+
"generate"
26+
],
27+
"homepage": "https://github.com/RaresAil/prisma-mapper",
1428
"repository": "https://github.com/RaresAil/prisma-mapper.git",
1529
"author": "RaresAil <[email protected]>",
1630
"license": "MIT",
1731
"private": false,
1832
"scripts": {
1933
"dev:bin": "yarn build && NODE_ENV=dev node bin/commands.js",
20-
"dev": "NODE_ENV=dev nodemon src/commands.ts",
34+
"dev": "NODE_ENV=dev ts-node src/commands.ts",
2135
"build": "yarn lint && rm -rf ./bin/ && tsc -p .",
22-
"lint": "eslint src/**/*.ts"
36+
"lint": "eslint src/**/*.ts",
37+
"test": "jest"
2338
},
2439
"dependencies": {
25-
"@prisma/internals": "^4.3.1",
40+
"@prisma/internals": "^4.6.1",
2641
"colors": "^1.4.0",
27-
"commander": "^9.4.0",
28-
"inquirer": "^9.1.2"
42+
"commander": "^9.4.1",
43+
"inquirer": "^9.1.4"
2944
},
3045
"devDependencies": {
31-
"@types/inquirer": "^9.0.1",
32-
"@types/node": "^18.7.18",
33-
"@typescript-eslint/eslint-plugin": "^5.38.0",
34-
"@typescript-eslint/parser": "^5.38.0",
35-
"eslint": "^8.23.1",
46+
"@types/inquirer": "^9.0.3",
47+
"@types/jest": "^29.2.3",
48+
"@types/node": "^18.11.9",
49+
"@typescript-eslint/eslint-plugin": "^5.44.0",
50+
"@typescript-eslint/parser": "^5.44.0",
51+
"eslint": "^8.28.0",
3652
"eslint-config-standard": "^17.0.0",
3753
"eslint-plugin-import": "^2.25.2",
38-
"eslint-plugin-n": "^15.2.5",
39-
"eslint-plugin-promise": "^6.0.0",
54+
"eslint-plugin-n": "^15.5.1",
55+
"eslint-plugin-promise": "^6.1.1",
4056
"eslint-plugin-security": "^1.5.0",
41-
"nodemon": "^2.0.20",
57+
"jest": "^29.3.1",
58+
"ts-jest": "^29.0.3",
4259
"ts-node": "^10.9.1",
43-
"typescript": "4.8.3"
60+
"typescript": "4.9.3"
4461
}
4562
}

src/CLIError.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default class CLIError extends Error {
2+
constructor(message: string) {
3+
super(message);
4+
this.name = 'CLIError';
5+
this.stack = '';
6+
}
7+
}

src/Utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import os from 'os';
44
import fs from 'fs';
55

66
export default abstract class Utils {
7-
public static getUserDic(): string | undefined {
7+
public static getUserDic(): string {
88
let findCommand;
99
const platform = os.platform();
1010
const linuxPlatforms = [
@@ -21,7 +21,7 @@ export default abstract class Utils {
2121
} else if (platform === 'win32') {
2222
findCommand = 'cd';
2323
} else {
24-
return undefined;
24+
return '';
2525
}
2626

2727
let dir: string | undefined;
@@ -31,11 +31,11 @@ export default abstract class Utils {
3131
.trim()
3232
.replace(/\r?\n|\r/g, '');
3333
} catch {
34-
return undefined;
34+
return '';
3535
}
3636

3737
if (!fs.existsSync(nodePath.normalize(dir))) {
38-
return undefined;
38+
return '';
3939
}
4040

4141
return dir;

0 commit comments

Comments
 (0)