-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Adds templates to
@flare-city/cli
to power the init command (#6)
- Loading branch information
1 parent
1a483c9
commit 40e49b8
Showing
16 changed files
with
204 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@flare-city/test": minor | ||
"@flare-city/cli": minor | ||
--- | ||
|
||
Removes `@flare-city/cli` dependency from `@flare-city/test` and adds templates to power the `flare-city init` CLI command |
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
app-city | ||
app-city | ||
bin |
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
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,100 @@ | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
|
||
import { fileURLToPath } from "url"; | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
||
interface WordReplacement { | ||
oldWord: string | RegExp; | ||
newWord: string; | ||
} | ||
|
||
function replaceWordsInFile( | ||
filePath: string, | ||
outputFilePath: string, | ||
replacements: WordReplacement[] | ||
) { | ||
const fileContent = fs.readFileSync(filePath, "utf-8"); | ||
let updatedContent = fileContent; | ||
|
||
replacements.forEach(({ oldWord, newWord }) => { | ||
updatedContent = updatedContent.replace(new RegExp(oldWord, "g"), newWord); | ||
}); | ||
|
||
fs.writeFileSync(outputFilePath, updatedContent); | ||
} | ||
|
||
function processDirectory( | ||
packageSampleDirPath: string, | ||
packageTemplateDirPath: string, | ||
replacements: WordReplacement[], | ||
excludedDirectories: string[] | ||
) { | ||
fs.readdirSync(packageSampleDirPath).forEach((file) => { | ||
const inputFilePath = path.join(packageSampleDirPath, file); | ||
const outputFilePath = path | ||
.join(packageTemplateDirPath, file) | ||
.concat(".hbs"); | ||
|
||
if (fs.statSync(inputFilePath).isDirectory()) { | ||
if (excludedDirectories.includes(file)) { | ||
// Skip excluded directory | ||
return; | ||
} | ||
const subDirectory = path.join(packageTemplateDirPath, file); | ||
fs.mkdirSync(subDirectory, { recursive: true }); | ||
processDirectory( | ||
inputFilePath, | ||
subDirectory, | ||
replacements, | ||
excludedDirectories | ||
); | ||
} else { | ||
replaceWordsInFile(inputFilePath, outputFilePath, replacements); | ||
} | ||
}); | ||
} | ||
|
||
const examplesDirPath = path.resolve(__dirname, "../examples"); | ||
const templatesDirPath = path.resolve(__dirname, "../templates"); | ||
const excludedDirectories = [".turbo", "node_modules", ".wrangler"]; | ||
|
||
try { | ||
const directories = fs | ||
.readdirSync(examplesDirPath, { withFileTypes: true }) | ||
.filter((dirent) => dirent.isDirectory()) | ||
.map((dirent) => dirent.name); | ||
|
||
// create the templates directory | ||
fs.mkdirSync(templatesDirPath, { recursive: true }); | ||
|
||
directories.forEach((packageName) => { | ||
const packageExampleDirPath = examplesDirPath.concat(`/${packageName}`); | ||
const packageTemplateDirPath = templatesDirPath.concat(`/${packageName}`); | ||
|
||
fs.mkdirSync(packageTemplateDirPath, { recursive: true }); | ||
|
||
const wordReplacements: WordReplacement[] = [ | ||
{ | ||
oldWord: `${packageName}-project-description`, | ||
newWord: "{{projectDescription}}", | ||
}, | ||
{ oldWord: `${packageName}-project-name`, newWord: `{{projectName}}` }, | ||
{ oldWord: packageName, newWord: `{{projectName}}` }, | ||
{ oldWord: /workspace:\*/, newWord: "latest" }, | ||
// Add more replacements as needed | ||
]; | ||
|
||
processDirectory( | ||
packageExampleDirPath, | ||
packageTemplateDirPath, | ||
wordReplacements, | ||
excludedDirectories | ||
); | ||
|
||
console.log(`Complete processing template: ${packageName}`); | ||
}); | ||
} catch (error) { | ||
throw new Error(error as string); | ||
} |
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,8 @@ | ||
{ | ||
"extends": "@flare-city/tsconfig/library/build", | ||
"compilerOptions": { | ||
"outDir": "./bin", | ||
"declarationDir": "./bin" | ||
}, | ||
"include": ["./src/**/*"] | ||
} |
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 |
---|---|---|
@@ -1,8 +1,4 @@ | ||
{ | ||
"extends": "@flare-city/tsconfig/library/build", | ||
"compilerOptions": { | ||
"outDir": "./bin", | ||
"declarationDir": "./bin" | ||
}, | ||
"include": ["./src/**/*.ts"] | ||
"extends": "@flare-city/tsconfig/library", | ||
"include": ["./src/**/*", "scripts", "examples"] | ||
} |
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
Oops, something went wrong.