create-prisma-php-app 1.0.10 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/prisma/seed.ts +73 -0
- package/dist/prisma-client-php/index.js +2 -0
- package/package.json +2 -2
- package/dist/node_modules/prisma-client-php/index.js +0 -2
- package/dist/prisma/seed.js +0 -68
- /package/dist/{node_modules/prisma-client-php → prisma-client-php}/index.enc +0 -0
- /package/dist/{node_modules/prisma-client-php → prisma-client-php}/key.enc +0 -0
- /package/dist/{node_modules/prisma-client-php → prisma-client-php}/package.json +0 -0
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{execSync}from"child_process";import fs from"fs";import{fileURLToPath}from"url";import path from"path";import chalk from"chalk";import prompts from"prompts";const __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename);async function updatePackageJson(i){const
|
|
2
|
+
import{execSync}from"child_process";import fs from"fs";import{fileURLToPath}from"url";import path from"path";import chalk from"chalk";import prompts from"prompts";const __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename);async function updatePackageJson(i){const t=path.join(i,"package.json"),e=JSON.parse(fs.readFileSync(t,"utf8"));e.scripts=Object.assign(Object.assign({},e.scripts),{postinstall:"prisma generate"}),e.type="module",e.prisma={seed:'ts-node --compiler-options {"module":"CommonJS"} prisma/seed.ts'},fs.writeFileSync(t,JSON.stringify(e,null,2))}async function createUpdateGitignoreFile(i,t){const e=path.join(i,".gitignore");let s="";fs.existsSync(e)&&(s=fs.readFileSync(e,"utf8")),t.forEach((i=>{s.includes(i)||(s+=`\n${i}`)})),s=s.trimStart(),fs.writeFileSync(e,s)}function copyRecursiveSync(i,t){const e=fs.existsSync(i),s=e&&fs.statSync(i);e&&s&&s.isDirectory()?(fs.mkdirSync(t,{recursive:!0}),fs.readdirSync(i).forEach((e=>copyRecursiveSync(path.join(i,e),path.join(t,e))))):fs.copyFileSync(i,t)}async function executeCopy(i,t){t.forEach((({srcDir:t,destDir:e})=>{copyRecursiveSync(path.join(__dirname,t),path.join(i,e))}))}function modifyTailwindConfig(i){const t=path.join(i,"tailwind.config.js");let e=fs.readFileSync(t,"utf8");const s=["./public/**/*.php","./public/**/*.html"].map((i=>` "${i}"`)).join(",\n");e=e.replace(/content: \[\],/g,`content: [\n${s}\n ],`),fs.writeFileSync(t,e,"utf8")}function modifyIndexPHP(i,t){const e=path.join(i,"public","index.php");try{let i=fs.readFileSync(e,"utf8");const s=t?' <link href="css/styles.css" rel="stylesheet"> \x3c!-- Stylesheet link to the tailwind compiled css --\x3e':' <script src="https://cdn.tailwindcss.com"><\/script>';i=i.replace("</head>",`${s}\n</head>`),fs.writeFileSync(e,i,"utf8")}catch(i){}}async function createDirectoryStructure(i,t){await updatePackageJson(i);const e=[{srcDir:"/settings",destDir:"/settings"},{srcDir:"/prisma",destDir:"/prisma"},{srcDir:"/src",destDir:"/src"},{srcDir:"/../vendor",destDir:"/vendor"}];t.tailwindcss&&e.push({srcDir:"/public/css/",destDir:"/public/css/"}),e.push({srcDir:"/public/assets/",destDir:"/public/assets/"}),await executeCopy(i,e),[{src:"/public/favicon.ico",dest:"/public/favicon.ico"},{src:"/public/index.php",dest:"/public/index.php"},{src:"/bootstrap.php",dest:"/bootstrap.php"},{src:"/../composer.json",dest:"/composer.json"},{src:"/../composer.lock",dest:"/composer.lock"}].forEach((({src:t,dest:e})=>{const s=path.join(__dirname,t),c=path.join(i,e),n=fs.readFileSync(s,"utf8");fs.writeFileSync(c,n)})),t.tailwindcss?(modifyTailwindConfig(i),modifyIndexPHP(i,!0)):modifyIndexPHP(i,!1)}async function getAnswer(){const i=[{type:"text",name:"projectName",message:"What is your project named?",initial:"my-app"},{type:"toggle",name:"tailwindcss",message:`Would you like to use ${chalk.blue("Tailwind CSS")}?`,initial:!0,active:"Yes",inactive:"No"}],t=()=>!1;try{const e=await prompts(i,{onCancel:t});return 0===Object.keys(e).length?null:{projectName:String(e.projectName).trim().replace(/ /g,"-"),tailwindcss:e.tailwindcss}}catch(i){return null}}async function installDependencies(i,t){execSync("npm init -y",{stdio:"inherit",cwd:i}),t.forEach((i=>{})),execSync(`npm install ${t.join(" ")}`,{stdio:"inherit",cwd:i})}async function main(){try{const i=await getAnswer();if(null===i)return;execSync("npm install -g create-prisma-php-app",{stdio:"inherit"}),fs.mkdirSync(i.projectName);const t=path.join(process.cwd(),i.projectName);process.chdir(i.projectName);const e=["prisma","@prisma/client","typescript","@types/node","ts-node"];i.tailwindcss&&e.push("tailwindcss","autoprefixer","postcss"),await installDependencies(t,e),execSync("npx prisma init",{stdio:"inherit"}),execSync("npx tsc --init",{stdio:"inherit"}),i.tailwindcss&&execSync("npx tailwindcss init -p",{stdio:"inherit"}),await createDirectoryStructure(t,i),i.tailwindcss&&execSync("npx tailwindcss -i ./public/css/tailwind.css -o ./public/css/styles.css --minify",{stdio:"inherit"});const s=path.join(t,"settings","project-settings.js"),c=`export const projectSettings = {\n PROJECT_NAME: "${i.projectName}",\n PROJECT_ROOT_PATH: "${t.replace(/\\/g,"\\\\")}",\n PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",\n PHP_GENERATE_CLASS_PATH: "src/app/classes/prisma",\n };`;fs.writeFileSync(s,c)}catch(i){process.exit(1)}}main();
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { PrismaClient } from "@prisma/client";
|
|
2
|
+
|
|
3
|
+
const prisma = new PrismaClient();
|
|
4
|
+
|
|
5
|
+
// UserRole
|
|
6
|
+
const userRoleData = [
|
|
7
|
+
{
|
|
8
|
+
name: "Admin",
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: "User",
|
|
12
|
+
},
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
// User
|
|
16
|
+
const userData = [
|
|
17
|
+
{
|
|
18
|
+
name: "Juan",
|
|
19
|
+
email: "j@gmail.com",
|
|
20
|
+
password: "$2b$10$mgjotYzIXwrK1MCWmu4tgeUVnLcb.qzvqwxOq4FXEL8k2obwXivDi", // TODO: template password 1234 (bcrypt) testing only
|
|
21
|
+
roleId: 1,
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
async function main() {
|
|
26
|
+
// ========================================
|
|
27
|
+
// Code for PostgreSQL
|
|
28
|
+
// ----------------------------------------
|
|
29
|
+
// UserRole
|
|
30
|
+
// ----------------------------------------
|
|
31
|
+
// await prisma.userRole.deleteMany();
|
|
32
|
+
// await prisma.userRole.createMany({ data: userRoleData });
|
|
33
|
+
// await prisma.$executeRaw`ALTER SEQUENCE "UserRole_id_seq" RESTART WITH 1`;
|
|
34
|
+
// ----------------------------------------
|
|
35
|
+
// User
|
|
36
|
+
// ----------------------------------------
|
|
37
|
+
// await prisma.user.deleteMany();
|
|
38
|
+
// await prisma.user.createMany({ data: userData });
|
|
39
|
+
// ========================================
|
|
40
|
+
// Code for MySQL
|
|
41
|
+
// ----------------------------------------
|
|
42
|
+
// UserRole
|
|
43
|
+
// ----------------------------------------
|
|
44
|
+
// await prisma.userRole.deleteMany();
|
|
45
|
+
// await prisma.userRole.createMany({ data: userRoleData });
|
|
46
|
+
// await prisma.$executeRaw`ALTER TABLE UserRole AUTO_INCREMENT = 1`;
|
|
47
|
+
// ----------------------------------------
|
|
48
|
+
// User
|
|
49
|
+
// ----------------------------------------
|
|
50
|
+
// await prisma.user.deleteMany();
|
|
51
|
+
// await prisma.user.createMany({ data: userData });
|
|
52
|
+
// ========================================
|
|
53
|
+
// Code for MongoDB
|
|
54
|
+
// ----------------------------------------
|
|
55
|
+
// UserRole
|
|
56
|
+
// ----------------------------------------
|
|
57
|
+
// await prisma.userRole.deleteMany();
|
|
58
|
+
// await prisma.userRole.createMany({ data: userRoleData });
|
|
59
|
+
// ----------------------------------------
|
|
60
|
+
// User
|
|
61
|
+
// ----------------------------------------
|
|
62
|
+
// await prisma.user.deleteMany();
|
|
63
|
+
// await prisma.user.createMany({ data: userData });
|
|
64
|
+
// ========================================
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
main()
|
|
68
|
+
.catch((e) => {
|
|
69
|
+
throw e;
|
|
70
|
+
})
|
|
71
|
+
.finally(async () => {
|
|
72
|
+
await prisma.$disconnect();
|
|
73
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import*as fs from"fs";import{exec}from"child_process";import path from"path";import{fileURLToPath,pathToFileURL}from"url";import CryptoJS from"crypto-js";const __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename),args=process.argv.slice(2),getSecretKey=()=>{const e=fs.readFileSync(`${__dirname}/key.enc`,"utf8");if(e.length<400)throw new Error("File content is less than 400 characters.");return e.substring(299,349)},decryptData=(e,t)=>CryptoJS.AES.decrypt(e,t).toString(CryptoJS.enc.Utf8),executePHP=e=>{exec(e,((e,t,r)=>{}))},main=async()=>{if("generate"===args[0]&&"class"===args[1])try{const e=process.cwd(),t=pathToFileURL(path.join(e,"settings","project-settings.js")),r=(await import(t.href)).projectSettings,i=r.PHP_GENERATE_CLASS_PATH,a=`${__dirname}/index.php`,n=`${__dirname}/index.enc`,c=getSecretKey(),s=fs.readFileSync(n,{encoding:"utf8"}),o=decryptData(s,c);fs.writeFileSync(`${__dirname}/index.php`,o);const p=`${r.PHP_ROOT_PATH_EXE} ${a} ${i}`;executePHP(p)}catch(e){}};main().catch((e=>{}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-prisma-php-app",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"bin": {
|
|
13
13
|
"create-prisma-php-app": "dist/index.js",
|
|
14
|
-
"php": "dist/
|
|
14
|
+
"php": "dist/prisma-client-php/index.js"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import*as fs from"fs";import{exec}from"child_process";import path from"path";import{pathToFileURL}from"url";import CryptoJS from"crypto-js";const args=process.argv.slice(2),getSecretKey=e=>{const t=fs.readFileSync(`${e}/key.enc`,"utf8");if(t.length<400)throw new Error("File content is less than 400 characters.");return t.substring(299,349)},decryptData=(e,t)=>CryptoJS.AES.decrypt(e,t).toString(CryptoJS.enc.Utf8),executePHP=e=>{exec(e,((e,t,r)=>{}))},main=async()=>{if("generate"===args[0]&&"class"===args[1])try{const e=process.cwd(),t=pathToFileURL(path.join(e,"settings","project-settings.js")),r=(await import(t.href)).projectSettings,s=r.PHP_GENERATE_CLASS_PATH,c=`${r.PROJECT_ROOT_PATH}/node_modules/prisma-client-php`,i=r.PROJECT_ROOT_PATH?`${c}/index.run.php`:`${c}/dist/prisma-client-php/index.run.php`,n=`${c}/index.enc`,p=getSecretKey(c),o=fs.readFileSync(n,{encoding:"utf8"}),a=decryptData(o,p);fs.writeFileSync(`${c}/index.run.php`,a);r.PHP_ROOT_PATH_EXE}catch(e){}};main().catch((e=>{}));
|
package/dist/prisma/seed.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { PrismaClient } from "@prisma/client";
|
|
2
|
-
const prisma = new PrismaClient();
|
|
3
|
-
// UserRole
|
|
4
|
-
const userRoleData = [
|
|
5
|
-
{
|
|
6
|
-
name: "Admin",
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
name: "User",
|
|
10
|
-
},
|
|
11
|
-
];
|
|
12
|
-
// User
|
|
13
|
-
const userData = [
|
|
14
|
-
{
|
|
15
|
-
name: "Juan",
|
|
16
|
-
email: "j@gmail.com",
|
|
17
|
-
password: "$2b$10$mgjotYzIXwrK1MCWmu4tgeUVnLcb.qzvqwxOq4FXEL8k2obwXivDi", // TODO: template password 1234 (bcrypt) testing only
|
|
18
|
-
roleId: 1,
|
|
19
|
-
},
|
|
20
|
-
];
|
|
21
|
-
async function main() {
|
|
22
|
-
// ========================================
|
|
23
|
-
// Code for PostgreSQL
|
|
24
|
-
// ----------------------------------------
|
|
25
|
-
// UserRole
|
|
26
|
-
// ----------------------------------------
|
|
27
|
-
// await prisma.userRole.deleteMany();
|
|
28
|
-
// await prisma.userRole.createMany({ data: userRoleData });
|
|
29
|
-
// await prisma.$executeRaw`ALTER SEQUENCE "UserRole_id_seq" RESTART WITH 1`;
|
|
30
|
-
// ----------------------------------------
|
|
31
|
-
// User
|
|
32
|
-
// ----------------------------------------
|
|
33
|
-
// await prisma.user.deleteMany();
|
|
34
|
-
// await prisma.user.createMany({ data: userData });
|
|
35
|
-
// ========================================
|
|
36
|
-
// Code for MySQL
|
|
37
|
-
// ----------------------------------------
|
|
38
|
-
// UserRole
|
|
39
|
-
// ----------------------------------------
|
|
40
|
-
// await prisma.userRole.deleteMany();
|
|
41
|
-
// await prisma.userRole.createMany({ data: userRoleData });
|
|
42
|
-
// await prisma.$executeRaw`ALTER TABLE UserRole AUTO_INCREMENT = 1`;
|
|
43
|
-
// ----------------------------------------
|
|
44
|
-
// User
|
|
45
|
-
// ----------------------------------------
|
|
46
|
-
// await prisma.user.deleteMany();
|
|
47
|
-
// await prisma.user.createMany({ data: userData });
|
|
48
|
-
// ========================================
|
|
49
|
-
// Code for MongoDB
|
|
50
|
-
// ----------------------------------------
|
|
51
|
-
// UserRole
|
|
52
|
-
// ----------------------------------------
|
|
53
|
-
// await prisma.userRole.deleteMany();
|
|
54
|
-
// await prisma.userRole.createMany({ data: userRoleData });
|
|
55
|
-
// ----------------------------------------
|
|
56
|
-
// User
|
|
57
|
-
// ----------------------------------------
|
|
58
|
-
// await prisma.user.deleteMany();
|
|
59
|
-
// await prisma.user.createMany({ data: userData });
|
|
60
|
-
// ========================================
|
|
61
|
-
}
|
|
62
|
-
main()
|
|
63
|
-
.catch((e) => {
|
|
64
|
-
throw e;
|
|
65
|
-
})
|
|
66
|
-
.finally(async () => {
|
|
67
|
-
await prisma.$disconnect();
|
|
68
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|