-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨 feat: copy components script (#120)
- Loading branch information
Showing
9 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// Storybook components directory | ||
const componentsDir = 'starters/storybook/app/components/ui'; | ||
// Remix components directory | ||
const remixDir = 'starters/remix/app/components/ui'; | ||
// Next components directory | ||
const nextDir = 'starters/next/components/ui'; | ||
|
||
function copyComponents(source, target) { | ||
try { | ||
fs.rmSync(target, { recursive: true, force: true }); | ||
fs.cpSync(source, target, { recursive: true }); | ||
} catch (error) { | ||
console.error('An error occurred:', error); | ||
} | ||
} | ||
|
||
function modifyComponents() { | ||
try { | ||
// Add use client to next components | ||
const clientComponents = [ | ||
'/Header/Header.tsx', | ||
]; | ||
for (const component of clientComponents) { | ||
const fileName = path.join(nextDir, component); | ||
const content = fs.readFileSync(fileName, 'utf8'); | ||
fs.writeFileSync(fileName, `'use client'\n\n${content}`); | ||
} | ||
// Replace path alias to next components | ||
const files = fs.readdirSync(nextDir, { withFileTypes: true, recursive: true, encoding: 'utf8' }); | ||
for (const file of files) { | ||
if (file.isDirectory()) { | ||
continue; | ||
} | ||
if (!file.name.endsWith('.tsx')) { | ||
continue; | ||
} | ||
const fileName = path.join(file.parentPath, file.name); | ||
const content = fs.readFileSync(fileName, 'utf8'); | ||
fs.writeFileSync(fileName, content.replaceAll('~/', '@/')); | ||
} | ||
} | ||
catch (error) { | ||
console.error('An error occurred:', error); | ||
} | ||
} | ||
|
||
console.log('Copying remix components...'); | ||
copyComponents(componentsDir, remixDir) | ||
console.log('Copying next components...'); | ||
copyComponents(componentsDir, nextDir) | ||
console.log('Modifying next components...'); | ||
modifyComponents(); |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.