Skip to content

Commit

Permalink
finish cleanup of basic template
Browse files Browse the repository at this point in the history
  • Loading branch information
IMax153 committed Sep 10, 2024
1 parent d7ff698 commit 06ebce5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 42 deletions.
3 changes: 2 additions & 1 deletion packages/create-effect-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@effect/printer-ansi": "^0.35.2",
"effect": "^3.7.2",
"tar": "^7.4.3",
"tsup": "^8.2.4"
"tsup": "^8.2.4",
"yaml": "^2.5.1"
}
}
55 changes: 27 additions & 28 deletions packages/create-effect-app/src/Cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as Array from "effect/Array"
import * as Effect from "effect/Effect"
import * as Match from "effect/Match"
import * as Option from "effect/Option"
import * as Yaml from "yaml"
import { ProjectType } from "./Domain.js"
import { GitHub } from "./GitHub.js"
import type { Example } from "./internal/examples.js"
Expand Down Expand Up @@ -51,10 +52,6 @@ const withNixFlake = Options.boolean("flake").pipe(
Options.withDescription("Initialize project with a Nix flake")
)

const withMadge = Options.boolean("madge").pipe(
Options.withDescription("Initialize project with Madge")
)

const withPrettier = Options.boolean("prettier").pipe(
Options.withDescription("Initialize project with Prettier")
)
Expand All @@ -76,7 +73,6 @@ const projectType: Options.Options<Option.Option<ProjectType>> = Options.all({
template: templateType,
withChangesets,
withNixFlake,
withMadge,
withPrettier,
withESLint,
withWorkflows
Expand Down Expand Up @@ -215,7 +211,7 @@ function createTemplate(config: TemplateConfig) {
// Handle user preferences for changesets
if (!config.projectType.withChangesets) {
// Remove the .changesets directory
yield* fs.remove(path.join(config.projectName, ".changesets"), {
yield* fs.remove(path.join(config.projectName, ".changeset"), {
recursive: true
})
// Remove patches for changesets
Expand All @@ -228,7 +224,7 @@ function createTemplate(config: TemplateConfig) {
Object.keys(packageJson["pnpm"]["patchedDependencies"]),
(key) => key.includes("changeset")
)
for (const patch in depsToRemove) {
for (const patch of depsToRemove) {
delete packageJson["pnpm"]["patchedDependencies"][patch]
}
// Remove scripts for changesets
Expand All @@ -249,6 +245,7 @@ function createTemplate(config: TemplateConfig) {
}
// If git workflows are enabled, remove changesets related workflows
if (config.projectType.withWorkflows) {
yield* fs.remove(path.join(config.projectName, ".github", "workflows", "release.yml"))
}
}

Expand All @@ -260,26 +257,11 @@ function createTemplate(config: TemplateConfig) {
)
}

// Handle user preferences for Madge
if (!config.projectType.withMadge) {
// Remove the madge configuration file
yield* fs.remove(path.join(config.projectName, ".madgerc"))
// Remove the madge dependency
delete packageJson["devDependencies"]["madge"]
// Remove circular script if monorepo
if (config.projectType.template === "monorepo") {
yield* fs.remove(path.join(config.projectName, "scripts", "circular.js"))
}
if (config.projectType.withWorkflows) {
// If git workflows are enabled, remove madge check workflows
}
}

// Handle user preferences for Prettier
if (!config.projectType.withPrettier) {
// Remove prettier configuration files
yield* Effect.forEach(
[".prettierignore", ".prettierc.json"],
[".prettierignore", ".prettierrc.json"],
(file) => fs.remove(path.join(config.projectName, file))
)
// Remove prettier from dependencies
Expand All @@ -306,6 +288,11 @@ function createTemplate(config: TemplateConfig) {
}
// If git workflows are enabled, remove lint workflows
if (config.projectType.withWorkflows) {
const checkWorkflowPath = path.join(config.projectName, ".github", "workflows", "check.yml")
const checkWorkflow = yield* fs.readFileString(checkWorkflowPath)
const checkYaml = Yaml.parse(checkWorkflow)
delete checkYaml["jobs"]["lint"]
yield* fs.writeFileString(checkWorkflowPath, Yaml.stringify(checkYaml, undefined, 2))
}
}

Expand All @@ -315,10 +302,27 @@ function createTemplate(config: TemplateConfig) {
yield* fs.remove(path.join(config.projectName, ".github"))
}

// Write out the updated package.json
yield* fs.writeFileString(
path.join(config.projectName, "package.json"),
JSON.stringify(packageJson, undefined, 2)
)

yield* Effect.logInfo(AnsiDoc.hsep([
AnsiDoc.text("Success!").pipe(AnsiDoc.annotate(Ansi.green)),
AnsiDoc.text(`Effect template project was initialized in ${config.projectName}`)
]))

if (config.projectType.withChangesets) {
yield* Effect.logInfo(AnsiDoc.hsep([
AnsiDoc.text("Make sure to update the Changesets configuration file"),
AnsiDoc.text("with your target GitHub repository for Changesets changelogs"),
AnsiDoc.hardLine,
AnsiDoc.text(path.join(config.projectName, ".changeset", "config.json")).pipe(
AnsiDoc.annotate(Ansi.magenta)
)
]))
}
})
}

Expand Down Expand Up @@ -382,11 +386,6 @@ const getUserInput = Prompt.select<"example" | "template">({
message: "Initialize project with a Nix flake?",
initial: true
}),
withMadge: Prompt.toggle({
message: "Initialize project with Madge?",
initial: true
}),

withPrettier: Prompt.toggle({
message: "Initialize project with Prettier?",
initial: true
Expand Down
1 change: 0 additions & 1 deletion packages/create-effect-app/src/Domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export type ProjectType = Data.TaggedEnum<{
readonly template: Template
readonly withChangesets: boolean
readonly withNixFlake: boolean
readonly withMadge: boolean
readonly withPrettier: boolean
readonly withESLint: boolean
readonly withWorkflows: boolean
Expand Down
5 changes: 1 addition & 4 deletions packages/create-effect-app/src/GitHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ export const make = Effect.gen(function*() {
Tar.extract({
cwd: config.projectName,
strip: 2 + config.projectType.template.split("/").length,
filter: (path) => {
console.log(path)
return path.includes(`examples-chore-enhance-templates/templates/${config.projectType.template}`)
}
filter: (path) => path.includes(`examples-chore-enhance-templates/templates/${config.projectType.template}`)
}), (cause) => new TarExtractionError({ cause, directory: config.projectName })))
)

Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions templates/basic/.madgerc

This file was deleted.

1 change: 0 additions & 1 deletion templates/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"eslint-plugin-sort-destructure-keys": "^2.0.0",
"fast-check": "^3.21.0",
"glob": "^11.0.0",
"madge": "^8.0.0",
"playwright": "^1.46.0",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
Expand Down

0 comments on commit 06ebce5

Please sign in to comment.