@windrun-huaiin/dev-scripts 13.0.1 → 13.1.0

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/cli.js CHANGED
@@ -158,9 +158,10 @@ commander.program
158
158
  commander.program
159
159
  .command('create-diaomao-app <project-name>')
160
160
  .description('create a new diaomao app from template')
161
- .action(async (projectName) => {
161
+ .option('-s, --schema <name>', 'Database schema name (optional, defaults to project name)')
162
+ .action(async (projectName, options) => {
162
163
  try {
163
- await createDiaomaoApp.createDiaomaoApp(projectName);
164
+ await createDiaomaoApp.createDiaomaoApp(projectName, options);
164
165
  }
165
166
  catch (error) {
166
167
  console.error('Error:', error);
package/dist/cli.mjs CHANGED
@@ -156,9 +156,10 @@ program
156
156
  program
157
157
  .command('create-diaomao-app <project-name>')
158
158
  .description('create a new diaomao app from template')
159
- .action(async (projectName) => {
159
+ .option('-s, --schema <name>', 'Database schema name (optional, defaults to project name)')
160
+ .action(async (projectName, options) => {
160
161
  try {
161
- await createDiaomaoApp(projectName);
162
+ await createDiaomaoApp(projectName, options);
162
163
  }
163
164
  catch (error) {
164
165
  console.error('Error:', error);
@@ -1,2 +1,6 @@
1
- export declare function createDiaomaoApp(targetDir: string): Promise<void>;
1
+ type CreateDiaomaoOptions = {
2
+ schema?: string;
3
+ };
4
+ export declare function createDiaomaoApp(targetDir: string, options?: CreateDiaomaoOptions): Promise<void>;
5
+ export {};
2
6
  //# sourceMappingURL=create-diaomao-app.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-diaomao-app.d.ts","sourceRoot":"","sources":["../../src/commands/create-diaomao-app.ts"],"names":[],"mappings":"AAKA,wBAAsB,gBAAgB,CAAC,SAAS,EAAE,MAAM,iBAwIvD"}
1
+ {"version":3,"file":"create-diaomao-app.d.ts","sourceRoot":"","sources":["../../src/commands/create-diaomao-app.ts"],"names":[],"mappings":"AAKA,KAAK,oBAAoB,GAAG;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,wBAAsB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,iBAgL3F"}
@@ -5,11 +5,8 @@ var path = require('path');
5
5
  var child_process = require('child_process');
6
6
  var os = require('os');
7
7
 
8
- async function createDiaomaoApp(targetDir) {
9
- if (!targetDir) {
10
- console.error('Usage: create-diaomao-app <project-name>');
11
- process.exit(1);
12
- }
8
+ async function createDiaomaoApp(targetDir, options = {}) {
9
+ const schemaName = options.schema || path.basename(targetDir);
13
10
  const cwd = process.cwd();
14
11
  const cwdPackageJson = path.join(cwd, 'package.json');
15
12
  const cwdWorkspaceYaml = path.join(cwd, 'pnpm-workspace.yaml');
@@ -58,7 +55,31 @@ async function createDiaomaoApp(targetDir) {
58
55
  const envPath = path.join(destDir, '.env.local');
59
56
  if (await fsExtra.pathExists(envTxtPath)) {
60
57
  await fsExtra.rename(envTxtPath, envPath);
61
- console.log('Renamed .env.local.txt to .env.local');
58
+ console.log('🍻🍻Renamed .env.local.txt to .env.local');
59
+ }
60
+ // Try to 'generate prisma/schema.prisma'
61
+ const prismaDir = path.join(destDir, 'prisma');
62
+ const schemaPath = path.join(prismaDir, 'schema.prisma');
63
+ await fsExtra.ensureDir(prismaDir);
64
+ // Check prisma dir, if exists then not genarate
65
+ if (!(await fsExtra.pathExists(schemaPath))) {
66
+ const schemaContent = [
67
+ 'generator client {',
68
+ ' provider = "prisma-client-js"',
69
+ '}',
70
+ '',
71
+ 'datasource db {',
72
+ ' provider = "postgresql"',
73
+ ' url = env("DATABASE_URL")',
74
+ ` schemas = ["${schemaName}", "public"]`,
75
+ '}',
76
+ '',
77
+ ].join('\n');
78
+ await fsExtra.writeFile(schemaPath, schemaContent, 'utf8');
79
+ console.log(`🍻🍻Generated initial prisma/schema.prisma with schema: ${schemaName}`);
80
+ }
81
+ else {
82
+ console.log('prisma/schema.prisma already exists in template, skipping generation');
62
83
  }
63
84
  // handle .changeset folder if exists
64
85
  const changesetDir = path.join(destDir, '.changeset');
@@ -66,7 +87,7 @@ async function createDiaomaoApp(targetDir) {
66
87
  const templateFile = path.join(changesetDir, 'd8-template.mdx');
67
88
  const changesetContent = `---\n"${path.basename(targetDir)}": major\n---\n\nfeat(init): app created by @windrun-huaiin/diaomao`;
68
89
  await fsExtra.writeFile(templateFile, changesetContent, 'utf8');
69
- console.log('Created changeset template file: d8-template.mdx');
90
+ console.log('🍻🍻Created changeset template file: d8-template.mdx');
70
91
  }
71
92
  // read and modify package.json
72
93
  const pkgPath = path.join(destDir, 'package.json');
@@ -77,6 +98,12 @@ async function createDiaomaoApp(targetDir) {
77
98
  // remove standalone-specific scripts for non-monorepo scenario
78
99
  if (pkg.scripts) {
79
100
  delete pkg.scripts['djvp'];
101
+ // Repalce 'core-sync-sql' command's '--schema diaomao'
102
+ const scriptKey = 'core-sync-sql';
103
+ if (pkg.scripts[scriptKey]) {
104
+ pkg.scripts[scriptKey] = pkg.scripts[scriptKey].replace('--schema diaomao', `--schema ${schemaName}`);
105
+ console.log(`Updated ${scriptKey} script: --schema ${schemaName}`);
106
+ }
80
107
  }
81
108
  // remove publish related config
82
109
  delete pkg.publishConfig;
@@ -97,6 +124,7 @@ async function createDiaomaoApp(targetDir) {
97
124
  console.error('Failed to install dependencies. Please run npm install or pnpm install manually.');
98
125
  }
99
126
  }
127
+ console.log('🍻🍻Installed dependencies!');
100
128
  console.log('Initializing Git repository...');
101
129
  // initialize git
102
130
  try {
@@ -107,13 +135,17 @@ async function createDiaomaoApp(targetDir) {
107
135
  catch (error) {
108
136
  console.warn('Failed to initialize Git repository. Please initialize manually.');
109
137
  }
110
- console.log(`\n Project created: ${destDir}`);
138
+ console.log(`\n🍻🍻 Project created: ${destDir}`);
111
139
  console.log(`\nNext steps:`);
112
140
  console.log(` cd ${targetDir}`);
141
+ console.log(` 🍎🍎NOTE: if you want to update @windrun-huaiin packages, please run pnpm windrun`);
142
+ console.log(` ⚠️⚠️NOTE: please check .env.local file and set your own env!`);
143
+ console.log(` ⚠️⚠️NOTE: USE 'pnpm core-list-route' for viewing latested api routes`);
144
+ console.log(` ⚠️⚠️NOTE: USE 'pnpm core-sync-route' for syncing latested api routes`);
145
+ console.log(` ⚠️⚠️NOTE: USE 'pnpm core-sync-schema' for appendding basic prisma models`);
146
+ console.log(` ⚠️⚠️NOTE: USE 'pnpm core-sync-sql' for initing sql`);
113
147
  console.log(` pnpm build`);
114
148
  console.log(` pnpm dev`);
115
- console.log(` NOTE: if you want to update @windrun-huaiin packages, please run pnpm windrun`);
116
- console.log(` NOTE: please check .env.local file and set your own env!`);
117
149
  }
118
150
  catch (error) {
119
151
  console.error('Failed to create project:', error);
@@ -3,11 +3,8 @@ import path from 'path';
3
3
  import { execSync } from 'child_process';
4
4
  import os from 'os';
5
5
 
6
- async function createDiaomaoApp(targetDir) {
7
- if (!targetDir) {
8
- console.error('Usage: create-diaomao-app <project-name>');
9
- process.exit(1);
10
- }
6
+ async function createDiaomaoApp(targetDir, options = {}) {
7
+ const schemaName = options.schema || path.basename(targetDir);
11
8
  const cwd = process.cwd();
12
9
  const cwdPackageJson = path.join(cwd, 'package.json');
13
10
  const cwdWorkspaceYaml = path.join(cwd, 'pnpm-workspace.yaml');
@@ -56,7 +53,31 @@ async function createDiaomaoApp(targetDir) {
56
53
  const envPath = path.join(destDir, '.env.local');
57
54
  if (await pathExists(envTxtPath)) {
58
55
  await rename(envTxtPath, envPath);
59
- console.log('Renamed .env.local.txt to .env.local');
56
+ console.log('🍻🍻Renamed .env.local.txt to .env.local');
57
+ }
58
+ // Try to 'generate prisma/schema.prisma'
59
+ const prismaDir = path.join(destDir, 'prisma');
60
+ const schemaPath = path.join(prismaDir, 'schema.prisma');
61
+ await ensureDir(prismaDir);
62
+ // Check prisma dir, if exists then not genarate
63
+ if (!(await pathExists(schemaPath))) {
64
+ const schemaContent = [
65
+ 'generator client {',
66
+ ' provider = "prisma-client-js"',
67
+ '}',
68
+ '',
69
+ 'datasource db {',
70
+ ' provider = "postgresql"',
71
+ ' url = env("DATABASE_URL")',
72
+ ` schemas = ["${schemaName}", "public"]`,
73
+ '}',
74
+ '',
75
+ ].join('\n');
76
+ await writeFile(schemaPath, schemaContent, 'utf8');
77
+ console.log(`🍻🍻Generated initial prisma/schema.prisma with schema: ${schemaName}`);
78
+ }
79
+ else {
80
+ console.log('prisma/schema.prisma already exists in template, skipping generation');
60
81
  }
61
82
  // handle .changeset folder if exists
62
83
  const changesetDir = path.join(destDir, '.changeset');
@@ -64,7 +85,7 @@ async function createDiaomaoApp(targetDir) {
64
85
  const templateFile = path.join(changesetDir, 'd8-template.mdx');
65
86
  const changesetContent = `---\n"${path.basename(targetDir)}": major\n---\n\nfeat(init): app created by @windrun-huaiin/diaomao`;
66
87
  await writeFile(templateFile, changesetContent, 'utf8');
67
- console.log('Created changeset template file: d8-template.mdx');
88
+ console.log('🍻🍻Created changeset template file: d8-template.mdx');
68
89
  }
69
90
  // read and modify package.json
70
91
  const pkgPath = path.join(destDir, 'package.json');
@@ -75,6 +96,12 @@ async function createDiaomaoApp(targetDir) {
75
96
  // remove standalone-specific scripts for non-monorepo scenario
76
97
  if (pkg.scripts) {
77
98
  delete pkg.scripts['djvp'];
99
+ // Repalce 'core-sync-sql' command's '--schema diaomao'
100
+ const scriptKey = 'core-sync-sql';
101
+ if (pkg.scripts[scriptKey]) {
102
+ pkg.scripts[scriptKey] = pkg.scripts[scriptKey].replace('--schema diaomao', `--schema ${schemaName}`);
103
+ console.log(`Updated ${scriptKey} script: --schema ${schemaName}`);
104
+ }
78
105
  }
79
106
  // remove publish related config
80
107
  delete pkg.publishConfig;
@@ -95,6 +122,7 @@ async function createDiaomaoApp(targetDir) {
95
122
  console.error('Failed to install dependencies. Please run npm install or pnpm install manually.');
96
123
  }
97
124
  }
125
+ console.log('🍻🍻Installed dependencies!');
98
126
  console.log('Initializing Git repository...');
99
127
  // initialize git
100
128
  try {
@@ -105,13 +133,17 @@ async function createDiaomaoApp(targetDir) {
105
133
  catch (error) {
106
134
  console.warn('Failed to initialize Git repository. Please initialize manually.');
107
135
  }
108
- console.log(`\n Project created: ${destDir}`);
136
+ console.log(`\n🍻🍻 Project created: ${destDir}`);
109
137
  console.log(`\nNext steps:`);
110
138
  console.log(` cd ${targetDir}`);
139
+ console.log(` 🍎🍎NOTE: if you want to update @windrun-huaiin packages, please run pnpm windrun`);
140
+ console.log(` ⚠️⚠️NOTE: please check .env.local file and set your own env!`);
141
+ console.log(` ⚠️⚠️NOTE: USE 'pnpm core-list-route' for viewing latested api routes`);
142
+ console.log(` ⚠️⚠️NOTE: USE 'pnpm core-sync-route' for syncing latested api routes`);
143
+ console.log(` ⚠️⚠️NOTE: USE 'pnpm core-sync-schema' for appendding basic prisma models`);
144
+ console.log(` ⚠️⚠️NOTE: USE 'pnpm core-sync-sql' for initing sql`);
111
145
  console.log(` pnpm build`);
112
146
  console.log(` pnpm dev`);
113
- console.log(` NOTE: if you want to update @windrun-huaiin packages, please run pnpm windrun`);
114
- console.log(` NOTE: please check .env.local file and set your own env!`);
115
147
  }
116
148
  catch (error) {
117
149
  console.error('Failed to create project:', error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windrun-huaiin/dev-scripts",
3
- "version": "13.0.1",
3
+ "version": "13.1.0",
4
4
  "description": "Development scripts for multilingual projects",
5
5
  "main": "dist/index.js",
6
6
  "bin": {