Skip to content

Commit a40b0c7

Browse files
committed
[migration] All build command to skip specified folders during migration
For example: pnpm build --ignore "developer-platforms,guides,reference"
1 parent a8a9a87 commit a40b0c7

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

scripts/migration/src/index.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ interface ExtendedTransformerOptions extends TransformerOptions {
3232
}
3333
import type { Handle, State } from "mdast-util-to-markdown";
3434

35+
interface MigrationConfig {
36+
ignoredFolders: string[];
37+
useComponentSyntax: boolean;
38+
}
39+
3540
const __dirname = path.dirname(fileURLToPath(import.meta.url));
3641
const projectRoot = path.resolve(__dirname, "../../..");
3742

@@ -249,6 +254,7 @@ async function getSourcePath(): Promise<string> {
249254
async function processDirectory(
250255
dirPath: string,
251256
options: ExtendedTransformerOptions,
257+
config: MigrationConfig,
252258
): Promise<void> {
253259
console.log(`Processing directory: ${dirPath}`);
254260
const entries = await fs.readdir(dirPath, { withFileTypes: true });
@@ -259,7 +265,12 @@ async function processDirectory(
259265

260266
if (entry.isDirectory()) {
261267
console.log(`Found directory: ${entry.name}`);
262-
await processDirectory(fullPath, options);
268+
// Check if this directory should be ignored
269+
if (config.ignoredFolders.includes(entry.name)) {
270+
console.log(`Skipping ignored directory: ${entry.name}`);
271+
continue;
272+
}
273+
await processDirectory(fullPath, options, config);
263274
} else if (entry.isFile() && /\.mdx?$/.test(entry.name)) {
264275
console.log(`Found MDX file: ${entry.name}`);
265276
try {
@@ -276,18 +287,30 @@ async function processDirectory(
276287
async function main() {
277288
program
278289
.option("--use-directive-syntax", "Use ::: syntax instead of component syntax")
290+
.option("--ignore <folders>", "Comma-separated list of folders to ignore")
279291
.parse(process.argv);
280292

281293
const options = program.opts();
282294

295+
// Setup migration configuration
296+
const config: MigrationConfig = {
297+
ignoredFolders: options.ignore ? options.ignore.split(",") : ["developer-platforms"],
298+
useComponentSyntax: !options.useDirectiveSyntax,
299+
};
300+
283301
try {
284302
const sourcePath = await getSourcePath();
285303
console.log(`Starting migration from ${sourcePath}`);
304+
console.log("Ignored folders:", config.ignoredFolders);
286305

287-
await processDirectory(sourcePath, {
288-
useComponentSyntax: !options.useDirectiveSyntax, // Default to component syntax
306+
await processDirectory(
289307
sourcePath,
290-
});
308+
{
309+
useComponentSyntax: config.useComponentSyntax,
310+
sourcePath,
311+
},
312+
config,
313+
);
291314

292315
// Clean up temp directory if it exists
293316
const tempDir = path.join(projectRoot, "temp-nextra-docs");

0 commit comments

Comments
 (0)