Skip to content

Commit

Permalink
v1.6.0 (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolae-Rares Ailincai authored Jun 24, 2023
1 parent d231fdf commit bebd2f8
Show file tree
Hide file tree
Showing 15 changed files with 449 additions and 760 deletions.
35 changes: 34 additions & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
build:
name: Build
name: Unit Test & Build
runs-on: ubuntu-latest

strategy:
Expand All @@ -28,3 +28,36 @@ jobs:
run: yarn test
- name: Build
run: yarn build
- name: Archive production binary
uses: actions/upload-artifact@v3
if: matrix.node-version == '20.x'
with:
name: binary
path: bin
e2e:
needs: build
name: E2E Testing - Node.js 20.x
runs-on: ubuntu-latest
env:
NODE_ENV: production
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
cache: 'yarn'
- uses: actions/download-artifact@v3
with:
name: binary
path: 'bin'
- name: Install Dependencies
run: yarn install --frozen-lockfile
- name: Map Mocked Schemas to Camel Case
run: |
node bin/commands.js map --camel --schema src/__tests__/mock.prisma -o e2e-generated.prisma
node bin/commands.js map --camel --schema src/__tests__/mock-multi-schema.prisma -o e2e-multi-generated.prisma
- name: Verify Mapped Schemas
run: |
cmp -s e2e-generated.prisma src/__tests__/expected.prisma
cmp -s e2e-multi-generated.prisma src/__tests__/expected-multi-schema.prisma
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@ bin
prisma
prisma-mapper.json
.DS_Store
out*.prisma
out*.prisma
e2e/generated*
114 changes: 0 additions & 114 deletions .npmignore

This file was deleted.

15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# @raresail/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)
[![Yarn Audit CI](https://github.com/RaresAil/prisma-mapper/actions/workflows/audit.yml/badge.svg)](https://github.com/RaresAil/prisma-mapper/actions/workflows/audit.yml)

<center>

Downloads on old package naming
[![Web Documentation](https://packages.raresdesigns.com/badges/raresail-prisma-mapper.svg)](https://packages.raresdesigns.com/@raresail/prisma-mapper)

![NPM Package Downloads](https://badgen.net/npm/dm/prisma-mapper)
</center>

Downloads on new package naming
<br/>

[![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)
[![Yarn Audit CI](https://github.com/RaresAil/prisma-mapper/actions/workflows/audit.yml/badge.svg)](https://github.com/RaresAil/prisma-mapper/actions/workflows/audit.yml)
![NPM Package Downloads](https://badgen.net/npm/dm/@raresail/prisma-mapper)

</center>
---

A CLI that adds @map and @@map based on a json

Expand Down
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@raresail/prisma-mapper",
"version": "1.5.4",
"version": "1.6.0",
"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,
Expand Down Expand Up @@ -41,19 +41,20 @@
"test": "jest"
},
"dependencies": {
"@prisma/internals": "^4.15.0",
"@prisma/internals": "^4.16.1",
"colors": "^1.4.0",
"commander": "^10.0.1",
"inquirer": "^9.2.7"
"commander": "^11.0.0"
},
"resolutions": {
"semver": "^7.5.2"
},
"resolutions": {},
"devDependencies": {
"@types/inquirer": "^9.0.3",
"@types/jest": "^29.5.2",
"@types/node": "^20.2.5",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"eslint": "^8.42.0",
"@types/node": "^20.3.1",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"eslint": "^8.43.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^16.0.0",
Expand Down
58 changes: 56 additions & 2 deletions src/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { execSync } from 'child_process';
import process from 'node:process';
import fs from 'fs/promises';
import nodePath from 'path';
import syncFs from 'fs';
import os from 'os';
import fs from 'fs';

export default abstract class Utils {
public static getUserDic(): string {
Expand Down Expand Up @@ -34,10 +36,62 @@ export default abstract class Utils {
return '';
}

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

return dir;
}

public static clearPrevLine(line = 1) {
Array.from(Array(line).keys()).forEach(() => {
process.stdout?.moveCursor?.(0, -1);
process.stdout?.clearLine?.(1);
});
}

public static isUnicodeSupported(): boolean {
if (process.platform !== 'win32') {
return process.env.TERM !== 'linux'; // Linux console (kernel)
}

return (
Boolean(process.env.CI) ||
Boolean(process.env.WT_SESSION) || // Windows Terminal
Boolean(process.env.TERMINUS_SUBLIME) || // Terminus (<0.2.27)
process.env.ConEmuTask === '{cmd::Cmder}' || // ConEmu and cmder
process.env.TERM_PROGRAM === 'Terminus-Sublime' ||
process.env.TERM_PROGRAM === 'vscode' ||
process.env.TERM === 'xterm-256color' ||
process.env.TERM === 'alacritty' ||
process.env.TERMINAL_EMULATOR === 'JetBrains-JediTerm'
);
}

public static terminalSymbols() {
const main = {
info: 'ℹ',
success: '✔',
warning: '⚠',
error: '✖'
};

const fallback = {
info: 'i',
success: '√',
warning: '‼',
error: 'x'
};

return Utils.isUnicodeSupported() ? main : fallback;
}

public static async fsExists(path: string) {
try {
await fs.lstat(path);
return true;
} catch {
return false;
}
}
}
17 changes: 10 additions & 7 deletions src/__tests__/expected-multi-schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ model ModelThree {
}

model ModelFour {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
enumOne EnumOne @default(SomeValue) @map("enum_one")
enumTwo EnumTwo? @map("enum_two")
enumThree EnumThree? @map("enum_three")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6)
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
enumOne EnumOne @default(SomeValue) @map("enum_one")
enumTwo EnumTwo? @map("enum_two")
enumThree EnumThree? @map("enum_three")
booleanOne Boolean @default(false) @map("boolean_one")
stringOne String @map("string_one")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6)
camelCase String?
@@map("model_four")
@@schema("transactional")
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/map-multi-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('Test map command with multiSchema feature', () => {
it('command should pass', async () => {
await action(
{ schema: MOCK_PRISMA, output: OUTPUT_PRISMA, camel: true },
true,
true
);

Expand All @@ -40,7 +41,7 @@ describe('Test map command with multiSchema feature', () => {

it('command should fail with no schema found', async () => {
try {
await action({ schema: '', camel: true });
await action({ schema: '', camel: true }, false, true);
throw new Error('Should not reach here');
} catch (e) {
const error = e as CLIError;
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/map.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('Test map command', () => {
it('command should pass', async () => {
await action(
{ schema: MOCK_PRISMA, output: OUTPUT_PRISMA, camel: true },
true,
true
);

Expand All @@ -40,7 +41,7 @@ describe('Test map command', () => {

it('command should fail with no schema found', async () => {
try {
await action({ schema: '', camel: true });
await action({ schema: '', camel: true }, false, true);
throw new Error('Should not reach here');
} catch (e) {
const error = e as CLIError;
Expand Down
Loading

0 comments on commit bebd2f8

Please sign in to comment.