@windrun-huaiin/dev-scripts 6.8.2 ā 6.9.1
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.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +137 -1410
- package/dist/cli.mjs +145 -432
- package/dist/commands/check-translations.d.ts +3 -0
- package/dist/commands/check-translations.d.ts.map +1 -0
- package/dist/commands/check-translations.js +132 -0
- package/dist/commands/check-translations.mjs +130 -0
- package/dist/commands/clean-translations.d.ts +3 -0
- package/dist/commands/clean-translations.d.ts.map +1 -0
- package/dist/commands/clean-translations.js +148 -0
- package/dist/commands/clean-translations.mjs +146 -0
- package/dist/commands/create-diaomao-app.d.ts +2 -0
- package/dist/commands/create-diaomao-app.d.ts.map +1 -0
- package/dist/commands/create-diaomao-app.js +151 -0
- package/dist/commands/create-diaomao-app.mjs +149 -0
- package/dist/commands/deep-clean.d.ts +3 -0
- package/dist/commands/deep-clean.d.ts.map +1 -0
- package/dist/commands/deep-clean.js +119 -0
- package/dist/commands/deep-clean.mjs +117 -0
- package/dist/commands/easy-changeset.d.ts +2 -0
- package/dist/commands/easy-changeset.d.ts.map +1 -0
- package/dist/commands/easy-changeset.js +39 -0
- package/dist/commands/easy-changeset.mjs +37 -0
- package/dist/commands/generate-blog-index.d.ts +3 -0
- package/dist/commands/generate-blog-index.d.ts.map +1 -0
- package/dist/commands/generate-blog-index.js +302 -0
- package/dist/commands/generate-blog-index.mjs +300 -0
- package/dist/commands/generate-nextjs-architecture.d.ts +3 -0
- package/dist/commands/generate-nextjs-architecture.d.ts.map +1 -0
- package/dist/commands/generate-nextjs-architecture.js +84 -0
- package/dist/commands/generate-nextjs-architecture.mjs +82 -0
- package/dist/config/index.d.ts +10 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +173 -0
- package/dist/config/index.mjs +170 -0
- package/dist/config/schema.d.ts +34 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +80 -0
- package/dist/config/schema.mjs +78 -0
- package/dist/index.d.ts +6 -49
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -996
- package/dist/index.mjs +4 -3
- package/dist/utils/file-scanner.d.ts +22 -0
- package/dist/utils/file-scanner.d.ts.map +1 -0
- package/dist/utils/file-scanner.js +70 -0
- package/dist/utils/file-scanner.mjs +65 -0
- package/dist/utils/logger.d.ts +24 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +63 -0
- package/dist/utils/logger.mjs +61 -0
- package/dist/utils/translation-parser.d.ts +29 -0
- package/dist/utils/translation-parser.d.ts.map +1 -0
- package/dist/utils/translation-parser.js +225 -0
- package/dist/utils/translation-parser.mjs +218 -0
- package/package.json +5 -5
- package/dist/chunk-GVR6HFHM.mjs +0 -989
- package/dist/chunk-GVR6HFHM.mjs.map +0 -1
- package/dist/cli.d.mts +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cli.mjs.map +0 -1
- package/dist/index.d.mts +0 -49
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fsExtra = require('fs-extra');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var child_process = require('child_process');
|
|
6
|
+
var os = require('os');
|
|
7
|
+
|
|
8
|
+
async function createDiaomaoApp(targetDir) {
|
|
9
|
+
if (!targetDir) {
|
|
10
|
+
console.error('Usage: create-diaomao-app <project-name>');
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
const cwd = process.cwd();
|
|
14
|
+
const cwdPackageJson = path.join(cwd, 'package.json');
|
|
15
|
+
const cwdWorkspaceYaml = path.join(cwd, 'pnpm-workspace.yaml');
|
|
16
|
+
// detect current directory type
|
|
17
|
+
const hasPkgJson = await fsExtra.pathExists(cwdPackageJson);
|
|
18
|
+
const hasWorkspace = await fsExtra.pathExists(cwdWorkspaceYaml);
|
|
19
|
+
let destDir;
|
|
20
|
+
if (hasPkgJson && hasWorkspace) {
|
|
21
|
+
// monorepo scenario - create under apps/
|
|
22
|
+
console.error('Detected monorepo environment, NextJS DO NOT SUPPORT MONOREPO WELL!');
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
else if (hasPkgJson && !hasWorkspace) {
|
|
26
|
+
// wrong directory - user might be inside an existing project
|
|
27
|
+
console.error('Warning: You are in a directory that already contains package.json');
|
|
28
|
+
console.error('This might create a nested project structure which is usually not intended.');
|
|
29
|
+
console.error('');
|
|
30
|
+
console.error('Recommendations:');
|
|
31
|
+
console.error('- If you want to create a standalone project, run this command in an empty directory');
|
|
32
|
+
console.error('- If you want to add to a monorepo, run this command in the monorepo root');
|
|
33
|
+
console.error('');
|
|
34
|
+
// for now, let's exit with error - can be enhanced to ask for user confirmation
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// normal scenario - create in current directory
|
|
39
|
+
destDir = path.resolve(cwd, targetDir);
|
|
40
|
+
}
|
|
41
|
+
const tempDir = path.join(os.tmpdir(), `diaomao-template-${Date.now()}`);
|
|
42
|
+
console.log(`Creating project: ${targetDir}...`);
|
|
43
|
+
try {
|
|
44
|
+
// create temp dir
|
|
45
|
+
await fsExtra.ensureDir(tempDir);
|
|
46
|
+
// download diaomao package from npm
|
|
47
|
+
console.log('Downloading diaomao template from npm...');
|
|
48
|
+
child_process.execSync(`npm pack @windrun-huaiin/diaomao`, { cwd: tempDir, stdio: 'inherit' });
|
|
49
|
+
// unzip npm package
|
|
50
|
+
const packageFiles = child_process.execSync('ls *.tgz', { cwd: tempDir, encoding: 'utf8' }).trim().split('\n');
|
|
51
|
+
const packageFile = packageFiles[0];
|
|
52
|
+
child_process.execSync(`tar -xzf ${packageFile}`, { cwd: tempDir });
|
|
53
|
+
// copy template content (npm package unzip in package/ directory)
|
|
54
|
+
const templateDir = path.join(tempDir, 'package');
|
|
55
|
+
await fsExtra.copy(templateDir, destDir, { overwrite: true });
|
|
56
|
+
// rename .env.local.txt to .env.local
|
|
57
|
+
const envTxtPath = path.join(destDir, '.env.local.txt');
|
|
58
|
+
const envPath = path.join(destDir, '.env.local');
|
|
59
|
+
if (await fsExtra.pathExists(envTxtPath)) {
|
|
60
|
+
await fsExtra.rename(envTxtPath, envPath);
|
|
61
|
+
console.log('Renamed .env.local.txt to .env.local');
|
|
62
|
+
}
|
|
63
|
+
// handle .changeset folder if exists
|
|
64
|
+
const changesetDir = path.join(destDir, '.changeset');
|
|
65
|
+
if (await fsExtra.pathExists(changesetDir)) {
|
|
66
|
+
const templateFile = path.join(changesetDir, 'd8-template.mdx');
|
|
67
|
+
const changesetContent = `---\n"${path.basename(targetDir)}": major\n---\n\nfeat(init): app created by @windrun-huaiin/diaomao`;
|
|
68
|
+
await fsExtra.writeFile(templateFile, changesetContent, 'utf8');
|
|
69
|
+
console.log('Created changeset template file: d8-template.mdx');
|
|
70
|
+
}
|
|
71
|
+
// read and modify package.json
|
|
72
|
+
const pkgPath = path.join(destDir, 'package.json');
|
|
73
|
+
const pkg = await fsExtra.readJson(pkgPath);
|
|
74
|
+
pkg.name = path.basename(targetDir);
|
|
75
|
+
pkg.version = "1.0.0";
|
|
76
|
+
pkg.private = true;
|
|
77
|
+
// add pnpm configuration for standalone project
|
|
78
|
+
pkg.pnpm = {
|
|
79
|
+
"onlyBuiltDependencies": [
|
|
80
|
+
"@clerk/shared",
|
|
81
|
+
"@parcel/watcher",
|
|
82
|
+
"@tailwindcss/oxide",
|
|
83
|
+
"core-js",
|
|
84
|
+
"esbuild",
|
|
85
|
+
"sharp",
|
|
86
|
+
"unrs-resolver"
|
|
87
|
+
],
|
|
88
|
+
"overrides": {
|
|
89
|
+
"@types/react": "19.1.2",
|
|
90
|
+
"@types/react-dom": "19.1.3"
|
|
91
|
+
},
|
|
92
|
+
"patchedDependencies": {
|
|
93
|
+
"fumadocs-ui@15.3.3": "patches/fumadocs-ui@15.3.3.patch"
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
// remove standalone-specific scripts for non-monorepo scenario
|
|
97
|
+
if (pkg.scripts) {
|
|
98
|
+
delete pkg.scripts['djvp'];
|
|
99
|
+
}
|
|
100
|
+
// remove publish related config
|
|
101
|
+
delete pkg.publishConfig;
|
|
102
|
+
delete pkg.files;
|
|
103
|
+
await fsExtra.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
104
|
+
console.log('Installing dependencies...');
|
|
105
|
+
// auto install dependencies
|
|
106
|
+
try {
|
|
107
|
+
child_process.execSync('pnpm install', { cwd: destDir, stdio: 'inherit' });
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
console.warn('pnpm failed, trying npm...');
|
|
111
|
+
try {
|
|
112
|
+
child_process.execSync('npm install', { cwd: destDir, stdio: 'inherit' });
|
|
113
|
+
}
|
|
114
|
+
catch (npmError) {
|
|
115
|
+
console.error('Failed to install dependencies. Please run npm install or pnpm install manually.');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
console.log('Initializing Git repository...');
|
|
119
|
+
// initialize git
|
|
120
|
+
try {
|
|
121
|
+
child_process.execSync('git init', { cwd: destDir, stdio: 'inherit' });
|
|
122
|
+
child_process.execSync('git add .', { cwd: destDir, stdio: 'inherit' });
|
|
123
|
+
child_process.execSync('git commit -m "feat: initial commit from diaomao template"', { cwd: destDir, stdio: 'inherit' });
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
console.warn('Failed to initialize Git repository. Please initialize manually.');
|
|
127
|
+
}
|
|
128
|
+
console.log(`\nā
Project created: ${destDir}`);
|
|
129
|
+
console.log(`\nNext steps:`);
|
|
130
|
+
console.log(` cd ${targetDir}`);
|
|
131
|
+
console.log(` pnpm build`);
|
|
132
|
+
console.log(` pnpm dev`);
|
|
133
|
+
console.log(` NOTE: if you want to update @windrun-huaiin packages, please run pnpm windrun`);
|
|
134
|
+
console.log(` NOTE: please check .env.local file and set your own env!`);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.error('Failed to create project:', error);
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
// cleanup temp dir
|
|
142
|
+
try {
|
|
143
|
+
await fsExtra.remove(tempDir);
|
|
144
|
+
}
|
|
145
|
+
catch (cleanupError) {
|
|
146
|
+
console.warn('Failed to cleanup temporary directory:', tempDir);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
exports.createDiaomaoApp = createDiaomaoApp;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { pathExists, ensureDir, copy, rename, writeFile, readJson, writeJson, remove } from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { execSync } from 'child_process';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
|
|
6
|
+
async function createDiaomaoApp(targetDir) {
|
|
7
|
+
if (!targetDir) {
|
|
8
|
+
console.error('Usage: create-diaomao-app <project-name>');
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
const cwd = process.cwd();
|
|
12
|
+
const cwdPackageJson = path.join(cwd, 'package.json');
|
|
13
|
+
const cwdWorkspaceYaml = path.join(cwd, 'pnpm-workspace.yaml');
|
|
14
|
+
// detect current directory type
|
|
15
|
+
const hasPkgJson = await pathExists(cwdPackageJson);
|
|
16
|
+
const hasWorkspace = await pathExists(cwdWorkspaceYaml);
|
|
17
|
+
let destDir;
|
|
18
|
+
if (hasPkgJson && hasWorkspace) {
|
|
19
|
+
// monorepo scenario - create under apps/
|
|
20
|
+
console.error('Detected monorepo environment, NextJS DO NOT SUPPORT MONOREPO WELL!');
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
else if (hasPkgJson && !hasWorkspace) {
|
|
24
|
+
// wrong directory - user might be inside an existing project
|
|
25
|
+
console.error('Warning: You are in a directory that already contains package.json');
|
|
26
|
+
console.error('This might create a nested project structure which is usually not intended.');
|
|
27
|
+
console.error('');
|
|
28
|
+
console.error('Recommendations:');
|
|
29
|
+
console.error('- If you want to create a standalone project, run this command in an empty directory');
|
|
30
|
+
console.error('- If you want to add to a monorepo, run this command in the monorepo root');
|
|
31
|
+
console.error('');
|
|
32
|
+
// for now, let's exit with error - can be enhanced to ask for user confirmation
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// normal scenario - create in current directory
|
|
37
|
+
destDir = path.resolve(cwd, targetDir);
|
|
38
|
+
}
|
|
39
|
+
const tempDir = path.join(os.tmpdir(), `diaomao-template-${Date.now()}`);
|
|
40
|
+
console.log(`Creating project: ${targetDir}...`);
|
|
41
|
+
try {
|
|
42
|
+
// create temp dir
|
|
43
|
+
await ensureDir(tempDir);
|
|
44
|
+
// download diaomao package from npm
|
|
45
|
+
console.log('Downloading diaomao template from npm...');
|
|
46
|
+
execSync(`npm pack @windrun-huaiin/diaomao`, { cwd: tempDir, stdio: 'inherit' });
|
|
47
|
+
// unzip npm package
|
|
48
|
+
const packageFiles = execSync('ls *.tgz', { cwd: tempDir, encoding: 'utf8' }).trim().split('\n');
|
|
49
|
+
const packageFile = packageFiles[0];
|
|
50
|
+
execSync(`tar -xzf ${packageFile}`, { cwd: tempDir });
|
|
51
|
+
// copy template content (npm package unzip in package/ directory)
|
|
52
|
+
const templateDir = path.join(tempDir, 'package');
|
|
53
|
+
await copy(templateDir, destDir, { overwrite: true });
|
|
54
|
+
// rename .env.local.txt to .env.local
|
|
55
|
+
const envTxtPath = path.join(destDir, '.env.local.txt');
|
|
56
|
+
const envPath = path.join(destDir, '.env.local');
|
|
57
|
+
if (await pathExists(envTxtPath)) {
|
|
58
|
+
await rename(envTxtPath, envPath);
|
|
59
|
+
console.log('Renamed .env.local.txt to .env.local');
|
|
60
|
+
}
|
|
61
|
+
// handle .changeset folder if exists
|
|
62
|
+
const changesetDir = path.join(destDir, '.changeset');
|
|
63
|
+
if (await pathExists(changesetDir)) {
|
|
64
|
+
const templateFile = path.join(changesetDir, 'd8-template.mdx');
|
|
65
|
+
const changesetContent = `---\n"${path.basename(targetDir)}": major\n---\n\nfeat(init): app created by @windrun-huaiin/diaomao`;
|
|
66
|
+
await writeFile(templateFile, changesetContent, 'utf8');
|
|
67
|
+
console.log('Created changeset template file: d8-template.mdx');
|
|
68
|
+
}
|
|
69
|
+
// read and modify package.json
|
|
70
|
+
const pkgPath = path.join(destDir, 'package.json');
|
|
71
|
+
const pkg = await readJson(pkgPath);
|
|
72
|
+
pkg.name = path.basename(targetDir);
|
|
73
|
+
pkg.version = "1.0.0";
|
|
74
|
+
pkg.private = true;
|
|
75
|
+
// add pnpm configuration for standalone project
|
|
76
|
+
pkg.pnpm = {
|
|
77
|
+
"onlyBuiltDependencies": [
|
|
78
|
+
"@clerk/shared",
|
|
79
|
+
"@parcel/watcher",
|
|
80
|
+
"@tailwindcss/oxide",
|
|
81
|
+
"core-js",
|
|
82
|
+
"esbuild",
|
|
83
|
+
"sharp",
|
|
84
|
+
"unrs-resolver"
|
|
85
|
+
],
|
|
86
|
+
"overrides": {
|
|
87
|
+
"@types/react": "19.1.2",
|
|
88
|
+
"@types/react-dom": "19.1.3"
|
|
89
|
+
},
|
|
90
|
+
"patchedDependencies": {
|
|
91
|
+
"fumadocs-ui@15.3.3": "patches/fumadocs-ui@15.3.3.patch"
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
// remove standalone-specific scripts for non-monorepo scenario
|
|
95
|
+
if (pkg.scripts) {
|
|
96
|
+
delete pkg.scripts['djvp'];
|
|
97
|
+
}
|
|
98
|
+
// remove publish related config
|
|
99
|
+
delete pkg.publishConfig;
|
|
100
|
+
delete pkg.files;
|
|
101
|
+
await writeJson(pkgPath, pkg, { spaces: 2 });
|
|
102
|
+
console.log('Installing dependencies...');
|
|
103
|
+
// auto install dependencies
|
|
104
|
+
try {
|
|
105
|
+
execSync('pnpm install', { cwd: destDir, stdio: 'inherit' });
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
console.warn('pnpm failed, trying npm...');
|
|
109
|
+
try {
|
|
110
|
+
execSync('npm install', { cwd: destDir, stdio: 'inherit' });
|
|
111
|
+
}
|
|
112
|
+
catch (npmError) {
|
|
113
|
+
console.error('Failed to install dependencies. Please run npm install or pnpm install manually.');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
console.log('Initializing Git repository...');
|
|
117
|
+
// initialize git
|
|
118
|
+
try {
|
|
119
|
+
execSync('git init', { cwd: destDir, stdio: 'inherit' });
|
|
120
|
+
execSync('git add .', { cwd: destDir, stdio: 'inherit' });
|
|
121
|
+
execSync('git commit -m "feat: initial commit from diaomao template"', { cwd: destDir, stdio: 'inherit' });
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.warn('Failed to initialize Git repository. Please initialize manually.');
|
|
125
|
+
}
|
|
126
|
+
console.log(`\nā
Project created: ${destDir}`);
|
|
127
|
+
console.log(`\nNext steps:`);
|
|
128
|
+
console.log(` cd ${targetDir}`);
|
|
129
|
+
console.log(` pnpm build`);
|
|
130
|
+
console.log(` pnpm dev`);
|
|
131
|
+
console.log(` NOTE: if you want to update @windrun-huaiin packages, please run pnpm windrun`);
|
|
132
|
+
console.log(` NOTE: please check .env.local file and set your own env!`);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
console.error('Failed to create project:', error);
|
|
136
|
+
process.exit(1);
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
// cleanup temp dir
|
|
140
|
+
try {
|
|
141
|
+
await remove(tempDir);
|
|
142
|
+
}
|
|
143
|
+
catch (cleanupError) {
|
|
144
|
+
console.warn('Failed to cleanup temporary directory:', tempDir);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export { createDiaomaoApp };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-clean.d.ts","sourceRoot":"","sources":["../../src/commands/deep-clean.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AA4C7D,wBAAsB,SAAS,CAC7B,MAAM,EAAE,gBAAgB,EACxB,GAAG,GAAE,OAAe,EACpB,GAAG,GAAE,MAA6D,GACjE,OAAO,CAAC,MAAM,CAAC,CA+EjB"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var logger = require('../utils/logger.js');
|
|
6
|
+
|
|
7
|
+
const MONOREPO_CLEAN_TARGETS = [
|
|
8
|
+
{ pattern: 'node_modules', description: 'Root directory dependencies' },
|
|
9
|
+
{ pattern: 'packages/*/node_modules', description: 'Package dependencies' },
|
|
10
|
+
{ pattern: 'apps/*/node_modules', description: 'Application dependencies' },
|
|
11
|
+
{ pattern: 'apps/*/.next', description: 'Next.js cache' },
|
|
12
|
+
{ pattern: 'packages/*/dist', description: 'Package build artifacts' },
|
|
13
|
+
{ pattern: 'apps/*/dist', description: 'Application build artifacts' },
|
|
14
|
+
{ pattern: '.turbo', description: 'Root directory Turbo cache' },
|
|
15
|
+
{ pattern: 'packages/*/.turbo', description: 'Package Turbo cache' },
|
|
16
|
+
{ pattern: 'apps/*/.turbo', description: 'Application Turbo cache' },
|
|
17
|
+
{ pattern: 'pnpm-lock.yaml', description: 'pnpm lock file', isFile: true }
|
|
18
|
+
];
|
|
19
|
+
const SINGLE_CLEAN_TARGETS = [
|
|
20
|
+
{ pattern: 'node_modules', description: 'Root directory dependencies' },
|
|
21
|
+
{ pattern: '.next', description: 'Next.js cache' },
|
|
22
|
+
{ pattern: 'pnpm-lock.yaml', description: 'pnpm lock file', isFile: true }
|
|
23
|
+
];
|
|
24
|
+
function globDirsOrFiles(pattern, cwd, isFile) {
|
|
25
|
+
if (!pattern.includes('*')) {
|
|
26
|
+
const abs = path.resolve(cwd, pattern);
|
|
27
|
+
if (isFile) {
|
|
28
|
+
return fs.existsSync(abs) ? [abs] : [];
|
|
29
|
+
}
|
|
30
|
+
return fs.existsSync(abs) && fs.statSync(abs).isDirectory() ? [abs] : [];
|
|
31
|
+
}
|
|
32
|
+
const [base, rest] = pattern.split('/*');
|
|
33
|
+
const absBase = path.resolve(cwd, base);
|
|
34
|
+
if (!fs.existsSync(absBase) || !fs.statSync(absBase).isDirectory())
|
|
35
|
+
return [];
|
|
36
|
+
const subdirs = fs.readdirSync(absBase);
|
|
37
|
+
return subdirs.map(d => path.join(absBase, d, rest.replace(/^[\/]/, '')))
|
|
38
|
+
.filter(p => fs.existsSync(p) && (isFile ? true : fs.statSync(p).isDirectory()));
|
|
39
|
+
}
|
|
40
|
+
async function deepClean(config, yes = false, cwd = typeof process !== 'undefined' ? process.cwd() : '.') {
|
|
41
|
+
const logger$1 = new logger.Logger(config);
|
|
42
|
+
// Environment check, DO NOT EXECUTE IN PRODUCTION ENVIRONMENT
|
|
43
|
+
if (process.env.NODE_ENV === 'production') {
|
|
44
|
+
logger$1.error('ā Production environment prohibits deep clean operations');
|
|
45
|
+
logger$1.log(' If you need to clean, please set: NODE_ENV=development');
|
|
46
|
+
logger$1.saveToFile('deep-clean.log', cwd);
|
|
47
|
+
return 1;
|
|
48
|
+
}
|
|
49
|
+
logger$1.warn('==============================');
|
|
50
|
+
logger$1.warn(`ā¼ļø Current working directory: ā ${cwd} ā`);
|
|
51
|
+
logger$1.warn('==============================');
|
|
52
|
+
// Auto detect project type
|
|
53
|
+
const isMonorepo = fs.existsSync(path.resolve(cwd, 'pnpm-workspace.yaml'));
|
|
54
|
+
const cleanTargets = isMonorepo ? MONOREPO_CLEAN_TARGETS : SINGLE_CLEAN_TARGETS;
|
|
55
|
+
let totalToDelete = [];
|
|
56
|
+
let groupDeleteMap = {};
|
|
57
|
+
for (const target of cleanTargets) {
|
|
58
|
+
const found = globDirsOrFiles(target.pattern, cwd, target.isFile);
|
|
59
|
+
groupDeleteMap[target.description] = found;
|
|
60
|
+
if (found.length === 0) {
|
|
61
|
+
logger$1.info(`šÆ ${target.description}: No need to clean`);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
logger$1.log(`\n[${target.description}]`);
|
|
65
|
+
found.forEach(p => logger$1.warn(`š [Preview] ${p}`));
|
|
66
|
+
totalToDelete.push(...found);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (totalToDelete.length === 0) {
|
|
70
|
+
logger$1.success('No directories or files to clean.');
|
|
71
|
+
logger$1.saveToFile('deep-clean.log', cwd);
|
|
72
|
+
return 0;
|
|
73
|
+
}
|
|
74
|
+
if (!yes) {
|
|
75
|
+
logger$1.log('\nIf you need to actually delete, please add --yes parameter.');
|
|
76
|
+
logger$1.saveToFile('deep-clean.log', cwd);
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
// Execute deletion, grouped print
|
|
80
|
+
let deleted = 0;
|
|
81
|
+
for (const target of cleanTargets) {
|
|
82
|
+
const items = groupDeleteMap[target.description] || [];
|
|
83
|
+
if (items.length > 0) {
|
|
84
|
+
logger$1.log(`\n[${target.description}]`);
|
|
85
|
+
for (const p of items) {
|
|
86
|
+
try {
|
|
87
|
+
if (target.isFile) {
|
|
88
|
+
fs.unlinkSync(p);
|
|
89
|
+
if (!fs.existsSync(p)) {
|
|
90
|
+
logger$1.success(`š» Deleted: ${p}`);
|
|
91
|
+
deleted++;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
logger$1.error(`ā Delete failed: ${p} (file still exists)`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
fs.rmSync(p, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
99
|
+
if (!fs.existsSync(p)) {
|
|
100
|
+
logger$1.success(`š» Deleted: ${p}`);
|
|
101
|
+
deleted++;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
logger$1.error(`ā Delete failed: ${p} (directory still exists)`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
logger$1.error(`ā Delete failed: ${p} (${e.message})`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
logger$1.log(`\nšŗ Total cleaned: ${deleted} directories or files.`);
|
|
115
|
+
logger$1.saveToFile('deep-clean.log', cwd);
|
|
116
|
+
return 0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
exports.deepClean = deepClean;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { existsSync, unlinkSync, rmSync, statSync, readdirSync } from 'fs';
|
|
2
|
+
import { resolve, join } from 'path';
|
|
3
|
+
import { Logger } from '../utils/logger.mjs';
|
|
4
|
+
|
|
5
|
+
const MONOREPO_CLEAN_TARGETS = [
|
|
6
|
+
{ pattern: 'node_modules', description: 'Root directory dependencies' },
|
|
7
|
+
{ pattern: 'packages/*/node_modules', description: 'Package dependencies' },
|
|
8
|
+
{ pattern: 'apps/*/node_modules', description: 'Application dependencies' },
|
|
9
|
+
{ pattern: 'apps/*/.next', description: 'Next.js cache' },
|
|
10
|
+
{ pattern: 'packages/*/dist', description: 'Package build artifacts' },
|
|
11
|
+
{ pattern: 'apps/*/dist', description: 'Application build artifacts' },
|
|
12
|
+
{ pattern: '.turbo', description: 'Root directory Turbo cache' },
|
|
13
|
+
{ pattern: 'packages/*/.turbo', description: 'Package Turbo cache' },
|
|
14
|
+
{ pattern: 'apps/*/.turbo', description: 'Application Turbo cache' },
|
|
15
|
+
{ pattern: 'pnpm-lock.yaml', description: 'pnpm lock file', isFile: true }
|
|
16
|
+
];
|
|
17
|
+
const SINGLE_CLEAN_TARGETS = [
|
|
18
|
+
{ pattern: 'node_modules', description: 'Root directory dependencies' },
|
|
19
|
+
{ pattern: '.next', description: 'Next.js cache' },
|
|
20
|
+
{ pattern: 'pnpm-lock.yaml', description: 'pnpm lock file', isFile: true }
|
|
21
|
+
];
|
|
22
|
+
function globDirsOrFiles(pattern, cwd, isFile) {
|
|
23
|
+
if (!pattern.includes('*')) {
|
|
24
|
+
const abs = resolve(cwd, pattern);
|
|
25
|
+
if (isFile) {
|
|
26
|
+
return existsSync(abs) ? [abs] : [];
|
|
27
|
+
}
|
|
28
|
+
return existsSync(abs) && statSync(abs).isDirectory() ? [abs] : [];
|
|
29
|
+
}
|
|
30
|
+
const [base, rest] = pattern.split('/*');
|
|
31
|
+
const absBase = resolve(cwd, base);
|
|
32
|
+
if (!existsSync(absBase) || !statSync(absBase).isDirectory())
|
|
33
|
+
return [];
|
|
34
|
+
const subdirs = readdirSync(absBase);
|
|
35
|
+
return subdirs.map(d => join(absBase, d, rest.replace(/^[\/]/, '')))
|
|
36
|
+
.filter(p => existsSync(p) && (isFile ? true : statSync(p).isDirectory()));
|
|
37
|
+
}
|
|
38
|
+
async function deepClean(config, yes = false, cwd = typeof process !== 'undefined' ? process.cwd() : '.') {
|
|
39
|
+
const logger = new Logger(config);
|
|
40
|
+
// Environment check, DO NOT EXECUTE IN PRODUCTION ENVIRONMENT
|
|
41
|
+
if (process.env.NODE_ENV === 'production') {
|
|
42
|
+
logger.error('ā Production environment prohibits deep clean operations');
|
|
43
|
+
logger.log(' If you need to clean, please set: NODE_ENV=development');
|
|
44
|
+
logger.saveToFile('deep-clean.log', cwd);
|
|
45
|
+
return 1;
|
|
46
|
+
}
|
|
47
|
+
logger.warn('==============================');
|
|
48
|
+
logger.warn(`ā¼ļø Current working directory: ā ${cwd} ā`);
|
|
49
|
+
logger.warn('==============================');
|
|
50
|
+
// Auto detect project type
|
|
51
|
+
const isMonorepo = existsSync(resolve(cwd, 'pnpm-workspace.yaml'));
|
|
52
|
+
const cleanTargets = isMonorepo ? MONOREPO_CLEAN_TARGETS : SINGLE_CLEAN_TARGETS;
|
|
53
|
+
let totalToDelete = [];
|
|
54
|
+
let groupDeleteMap = {};
|
|
55
|
+
for (const target of cleanTargets) {
|
|
56
|
+
const found = globDirsOrFiles(target.pattern, cwd, target.isFile);
|
|
57
|
+
groupDeleteMap[target.description] = found;
|
|
58
|
+
if (found.length === 0) {
|
|
59
|
+
logger.info(`šÆ ${target.description}: No need to clean`);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
logger.log(`\n[${target.description}]`);
|
|
63
|
+
found.forEach(p => logger.warn(`š [Preview] ${p}`));
|
|
64
|
+
totalToDelete.push(...found);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (totalToDelete.length === 0) {
|
|
68
|
+
logger.success('No directories or files to clean.');
|
|
69
|
+
logger.saveToFile('deep-clean.log', cwd);
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
if (!yes) {
|
|
73
|
+
logger.log('\nIf you need to actually delete, please add --yes parameter.');
|
|
74
|
+
logger.saveToFile('deep-clean.log', cwd);
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
// Execute deletion, grouped print
|
|
78
|
+
let deleted = 0;
|
|
79
|
+
for (const target of cleanTargets) {
|
|
80
|
+
const items = groupDeleteMap[target.description] || [];
|
|
81
|
+
if (items.length > 0) {
|
|
82
|
+
logger.log(`\n[${target.description}]`);
|
|
83
|
+
for (const p of items) {
|
|
84
|
+
try {
|
|
85
|
+
if (target.isFile) {
|
|
86
|
+
unlinkSync(p);
|
|
87
|
+
if (!existsSync(p)) {
|
|
88
|
+
logger.success(`š» Deleted: ${p}`);
|
|
89
|
+
deleted++;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
logger.error(`ā Delete failed: ${p} (file still exists)`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
rmSync(p, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
97
|
+
if (!existsSync(p)) {
|
|
98
|
+
logger.success(`š» Deleted: ${p}`);
|
|
99
|
+
deleted++;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
logger.error(`ā Delete failed: ${p} (directory still exists)`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
logger.error(`ā Delete failed: ${p} (${e.message})`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
logger.log(`\nšŗ Total cleaned: ${deleted} directories or files.`);
|
|
113
|
+
logger.saveToFile('deep-clean.log', cwd);
|
|
114
|
+
return 0;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { deepClean };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"easy-changeset.d.ts","sourceRoot":"","sources":["../../src/commands/easy-changeset.ts"],"names":[],"mappings":"AAGA,wBAAsB,aAAa,CAAC,GAAG,GAAE,MAA6D,kBAiCrG"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
|
|
6
|
+
async function easyChangeset(cwd = typeof process !== 'undefined' ? process.cwd() : '.') {
|
|
7
|
+
// Environment check, DO NOT EXECUTE IN PRODUCTION ENVIRONMENT
|
|
8
|
+
if (process.env.NODE_ENV === 'production') {
|
|
9
|
+
console.log('ā Production environment prohibits deep clean operations');
|
|
10
|
+
console.log(' If you need to clean, please set: NODE_ENV=development');
|
|
11
|
+
return 1;
|
|
12
|
+
}
|
|
13
|
+
console.log('==============================');
|
|
14
|
+
console.log(`ā¼ļø Current working directory: ā ${cwd} ā`);
|
|
15
|
+
console.log('==============================');
|
|
16
|
+
const changesetDir = path.join(cwd, '.changeset');
|
|
17
|
+
const mdxFile = path.join(changesetDir, 'd8-template.mdx');
|
|
18
|
+
const mdFile = path.join(changesetDir, 'd8-template.md');
|
|
19
|
+
if (!fs.existsSync(changesetDir)) {
|
|
20
|
+
console.log('ā No .changeset directory found, skipping.');
|
|
21
|
+
return 1;
|
|
22
|
+
}
|
|
23
|
+
if (!fs.existsSync(mdxFile)) {
|
|
24
|
+
console.log('ā No .changeset/d8-template.mdx file found, skipping.');
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const content = fs.readFileSync(mdxFile, 'utf-8');
|
|
29
|
+
fs.writeFileSync(mdFile, content, 'utf-8');
|
|
30
|
+
console.log('ā
Copied d8-template.mdx content to d8-template.md');
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
console.log('ā Copy failed:', e.message);
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.easyChangeset = easyChangeset;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
|
|
4
|
+
async function easyChangeset(cwd = typeof process !== 'undefined' ? process.cwd() : '.') {
|
|
5
|
+
// Environment check, DO NOT EXECUTE IN PRODUCTION ENVIRONMENT
|
|
6
|
+
if (process.env.NODE_ENV === 'production') {
|
|
7
|
+
console.log('ā Production environment prohibits deep clean operations');
|
|
8
|
+
console.log(' If you need to clean, please set: NODE_ENV=development');
|
|
9
|
+
return 1;
|
|
10
|
+
}
|
|
11
|
+
console.log('==============================');
|
|
12
|
+
console.log(`ā¼ļø Current working directory: ā ${cwd} ā`);
|
|
13
|
+
console.log('==============================');
|
|
14
|
+
const changesetDir = join(cwd, '.changeset');
|
|
15
|
+
const mdxFile = join(changesetDir, 'd8-template.mdx');
|
|
16
|
+
const mdFile = join(changesetDir, 'd8-template.md');
|
|
17
|
+
if (!existsSync(changesetDir)) {
|
|
18
|
+
console.log('ā No .changeset directory found, skipping.');
|
|
19
|
+
return 1;
|
|
20
|
+
}
|
|
21
|
+
if (!existsSync(mdxFile)) {
|
|
22
|
+
console.log('ā No .changeset/d8-template.mdx file found, skipping.');
|
|
23
|
+
return 1;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const content = readFileSync(mdxFile, 'utf-8');
|
|
27
|
+
writeFileSync(mdFile, content, 'utf-8');
|
|
28
|
+
console.log('ā
Copied d8-template.mdx content to d8-template.md');
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
console.log('ā Copy failed:', e.message);
|
|
33
|
+
return 1;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { easyChangeset };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-blog-index.d.ts","sourceRoot":"","sources":["../../src/commands/generate-blog-index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAoH7D,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,gBAAgB,EACxB,GAAG,GAAE,MAA6D,GACjE,OAAO,CAAC,MAAM,CAAC,CA0JjB"}
|