Skip to content

Commit

Permalink
Improve templates and error logging (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
IMax153 authored Sep 11, 2024
1 parent 5f20705 commit 243077d
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 83 deletions.
20 changes: 0 additions & 20 deletions packages/create-effect-app/src/Cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ const withNixFlake = Options.boolean("flake").pipe(
Options.withDescription("Initialize project with a Nix flake")
)

const withPrettier = Options.boolean("prettier").pipe(
Options.withDescription("Initialize project with Prettier")
)

const withESLint = Options.boolean("eslint").pipe(
Options.withDescription("Initialize project with ESLint")
)
Expand All @@ -73,7 +69,6 @@ const projectType: Options.Options<Option.Option<ProjectType>> = Options.all({
template: templateType,
withChangesets,
withNixFlake,
withPrettier,
withESLint,
withWorkflows
}).pipe(Options.map(ProjectType.Template))
Expand Down Expand Up @@ -257,17 +252,6 @@ function createTemplate(config: TemplateConfig) {
)
}

// Handle user preferences for Prettier
if (!config.projectType.withPrettier) {
// Remove prettier configuration files
yield* Effect.forEach(
[".prettierignore", ".prettierrc.json"],
(file) => fs.remove(path.join(config.projectName, file))
)
// Remove prettier from dependencies
delete packageJson["devDependencies"]["prettier"]
}

// Handle user preferences for ESLint
if (!config.projectType.withESLint) {
// Remove eslint.config.mjs
Expand Down Expand Up @@ -393,10 +377,6 @@ const getUserInput = Prompt.select<"example" | "template">({
message: "Initialize project with a Nix flake?",
initial: true
}),
withPrettier: Prompt.toggle({
message: "Initialize project with Prettier?",
initial: true
}),
withESLint: Prompt.toggle({
message: "Initialize project with ESLint?",
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 withPrettier: boolean
readonly withESLint: boolean
readonly withWorkflows: boolean
}
Expand Down
25 changes: 12 additions & 13 deletions packages/create-effect-app/src/GitHub.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import * as HelpDoc from "@effect/cli/HelpDoc"
import * as ValidationError from "@effect/cli/ValidationError"
import * as NodeSink from "@effect/platform-node/NodeSink"
import * as HttpClient from "@effect/platform/HttpClient"
import * as HttpClientRequest from "@effect/platform/HttpClientRequest"
import * as HttpClientResponse from "@effect/platform/HttpClientResponse"
import * as Data from "effect/Data"
import * as Effect from "effect/Effect"
import * as Layer from "effect/Layer"
import * as Stream from "effect/Stream"
import * as Tar from "tar"
import type { ExampleConfig, TemplateConfig } from "./Cli.js"

export class TarExtractionError extends Data.TaggedError("TarExtractionError")<{
readonly cause: unknown
readonly directory: string
}> {}

export const make = Effect.gen(function*() {
const client = yield* HttpClient.HttpClient

Expand All @@ -33,19 +29,22 @@ export const make = Effect.gen(function*() {
cwd: config.projectName,
strip: 2 + config.projectType.example.split("/").length,
filter: (path) => path.includes(`examples-main/examples/${config.projectType.example}`)
}), (cause) => new TarExtractionError({ cause, directory: config.projectName })))
}), () => ValidationError.invalidValue(HelpDoc.p(`Failed to download example ${config.projectType.example}`))))
)

const downloadTemplate = (config: TemplateConfig) =>
HttpClientRequest.get("/Effect-TS/examples/tar.gz/main").pipe(
codeloadClient,
HttpClientResponse.stream,
Stream.run(NodeSink.fromWritable(() =>
Tar.extract({
cwd: config.projectName,
strip: 2 + config.projectType.template.split("/").length,
filter: (path) => path.includes(`examples-main/templates/${config.projectType.template}`)
}), (cause) => new TarExtractionError({ cause, directory: config.projectName })))
Stream.run(NodeSink.fromWritable(
() =>
Tar.extract({
cwd: config.projectName,
strip: 2 + config.projectType.template.split("/").length,
filter: (path) => path.includes(`examples-main/templates/${config.projectType.template}`)
}),
() => ValidationError.invalidValue(HelpDoc.p(`Failed to download template ${config.projectType.template}`))
))
)

return {
Expand Down
8 changes: 1 addition & 7 deletions packages/create-effect-app/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ cli(process.argv).pipe(
Effect.logError(AnsiDoc.cat(
AnsiDoc.hardLine,
AnsiDoc.text("Exiting...").pipe(AnsiDoc.annotate(Ansi.red))
)),
TarExtractionError: (error) =>
Effect.logError(
AnsiDoc.text(
`Error extracting the TAR archive to ${error.directory}`
).pipe(AnsiDoc.annotate(Ansi.red))
)
))
}),
Effect.orDie,
Effect.provide(MainLive),
Expand Down
3 changes: 0 additions & 3 deletions templates/basic/.prettierignore

This file was deleted.

4 changes: 0 additions & 4 deletions templates/basic/.prettierrc.json

This file was deleted.

5 changes: 2 additions & 3 deletions templates/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@babel/plugin-transform-export-namespace-from": "^7.24.7",
"@babel/plugin-transform-modules-commonjs": "^7.24.8",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "2.27.7",
"@changesets/cli": "^2.27.8",
"@edge-runtime/vm": "^4.0.0",
"@effect/build-utils": "^0.7.7",
"@effect/docgen": "^0.4.4",
Expand Down Expand Up @@ -71,7 +71,6 @@
"fast-check": "^3.21.0",
"glob": "^11.0.0",
"playwright": "^1.46.0",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"tsx": "^4.17.0",
"typescript": "^5.6.2",
Expand All @@ -96,7 +95,7 @@
},
"patchedDependencies": {
"@changesets/[email protected]": "patches/@[email protected]",
"@changesets/[email protected].3": "patches/@[email protected].3.patch",
"@changesets/[email protected].4": "patches/@[email protected].4.patch",
"[email protected]": "patches/[email protected]"
}
}
Expand Down
8 changes: 4 additions & 4 deletions [email protected][email protected]
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/dist/changesets-assemble-release-plan.cjs.js b/dist/changesets-assemble-release-plan.cjs.js
index 60427457c887f2d72168fecec83d79088c68e3a4..b48899c83ca2bc5bfa0cbb65e0c098d5bb65fe3d 100644
index 4f7b5e5b37bb05874a5c1d8e583e29d4a9593ecf..980ead81554a8d925b6366e1644f3be03765398e 100644
--- a/dist/changesets-assemble-release-plan.cjs.js
+++ b/dist/changesets-assemble-release-plan.cjs.js
@@ -189,7 +189,7 @@ function determineDependents({
@@ -237,7 +237,7 @@ function determineDependents({
preInfo,
onlyUpdatePeerDependentsWhenOutOfRange: config.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH.onlyUpdatePeerDependentsWhenOutOfRange
})) {
Expand All @@ -12,10 +12,10 @@ index 60427457c887f2d72168fecec83d79088c68e3a4..b48899c83ca2bc5bfa0cbb65e0c098d5
switch (depType) {
case "dependencies":
diff --git a/dist/changesets-assemble-release-plan.esm.js b/dist/changesets-assemble-release-plan.esm.js
index f6583cf3f639e1fe4df764a015689dea74127236..2b9dca9f460793596394484457a94a34bcc1d99a 100644
index a327d9e4c709a6698f505d60d8bbf0046d4bde74..eb00fec7262280fb4876165c942212abc6b25efb 100644
--- a/dist/changesets-assemble-release-plan.esm.js
+++ b/dist/changesets-assemble-release-plan.esm.js
@@ -178,7 +178,7 @@ function determineDependents({
@@ -226,7 +226,7 @@ function determineDependents({
preInfo,
onlyUpdatePeerDependentsWhenOutOfRange: config.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH.onlyUpdatePeerDependentsWhenOutOfRange
})) {
Expand Down
3 changes: 0 additions & 3 deletions templates/cli/.prettierignore

This file was deleted.

4 changes: 0 additions & 4 deletions templates/cli/.prettierrc.json

This file was deleted.

5 changes: 2 additions & 3 deletions templates/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "2.27.7",
"@changesets/cli": "^2.27.8",
"@effect/cli": "latest",
"@effect/eslint-plugin": "^0.2.0",
"@effect/language-service": "^0.1.0",
Expand All @@ -49,7 +49,6 @@
"fast-check": "^3.21.0",
"glob": "^11.0.0",
"playwright": "^1.46.0",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"tsup": "^8.2.4",
"typescript": "^5.6.2",
Expand All @@ -62,7 +61,7 @@
},
"patchedDependencies": {
"@changesets/[email protected]": "patches/@[email protected]",
"@changesets/[email protected].3": "patches/@[email protected].3.patch"
"@changesets/[email protected].4": "patches/@[email protected].4.patch"
}
}
}
8 changes: 4 additions & 4 deletions [email protected][email protected]
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/dist/changesets-assemble-release-plan.cjs.js b/dist/changesets-assemble-release-plan.cjs.js
index 60427457c887f2d72168fecec83d79088c68e3a4..b48899c83ca2bc5bfa0cbb65e0c098d5bb65fe3d 100644
index 4f7b5e5b37bb05874a5c1d8e583e29d4a9593ecf..980ead81554a8d925b6366e1644f3be03765398e 100644
--- a/dist/changesets-assemble-release-plan.cjs.js
+++ b/dist/changesets-assemble-release-plan.cjs.js
@@ -189,7 +189,7 @@ function determineDependents({
@@ -237,7 +237,7 @@ function determineDependents({
preInfo,
onlyUpdatePeerDependentsWhenOutOfRange: config.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH.onlyUpdatePeerDependentsWhenOutOfRange
})) {
Expand All @@ -12,10 +12,10 @@ index 60427457c887f2d72168fecec83d79088c68e3a4..b48899c83ca2bc5bfa0cbb65e0c098d5
switch (depType) {
case "dependencies":
diff --git a/dist/changesets-assemble-release-plan.esm.js b/dist/changesets-assemble-release-plan.esm.js
index f6583cf3f639e1fe4df764a015689dea74127236..2b9dca9f460793596394484457a94a34bcc1d99a 100644
index a327d9e4c709a6698f505d60d8bbf0046d4bde74..eb00fec7262280fb4876165c942212abc6b25efb 100644
--- a/dist/changesets-assemble-release-plan.esm.js
+++ b/dist/changesets-assemble-release-plan.esm.js
@@ -178,7 +178,7 @@ function determineDependents({
@@ -226,7 +226,7 @@ function determineDependents({
preInfo,
onlyUpdatePeerDependentsWhenOutOfRange: config.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH.onlyUpdatePeerDependentsWhenOutOfRange
})) {
Expand Down
13 changes: 13 additions & 0 deletions templates/cli/patches/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/lib/index.js b/lib/index.js
index 2182884e21874ebb37261e2375eec08ad956fc9a..ef5630199121c2830756e00c7cc48cf1078c8207 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -78,7 +78,7 @@ const isInAssignmentContext = path => {

parentPath = _ref.parentPath;

- if (parentPath.isVariableDeclaration() || parentPath.isAssignmentExpression()) {
+ if (parentPath.isVariableDeclaration() || parentPath.isAssignmentExpression() || parentPath.isClassDeclaration()) {
return true;
}
} while (parentPath !== statement);
3 changes: 0 additions & 3 deletions templates/monorepo/.prettierignore

This file was deleted.

4 changes: 0 additions & 4 deletions templates/monorepo/.prettierrc.json

This file was deleted.

5 changes: 2 additions & 3 deletions templates/monorepo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@babel/plugin-transform-export-namespace-from": "^7.24.7",
"@babel/plugin-transform-modules-commonjs": "^7.24.8",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "2.27.7",
"@changesets/cli": "^2.27.8",
"@edge-runtime/vm": "^4.0.0",
"@effect/build-utils": "^0.7.7",
"@effect/eslint-plugin": "^0.2.0",
Expand All @@ -63,7 +63,6 @@
"fast-check": "^3.21.0",
"glob": "^11.0.0",
"playwright": "^1.46.0",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"tsx": "^4.17.0",
"typescript": "^5.6.2",
Expand All @@ -76,7 +75,7 @@
},
"patchedDependencies": {
"@changesets/[email protected]": "patches/@[email protected]",
"@changesets/[email protected].3": "patches/@[email protected].3.patch",
"@changesets/[email protected].4": "patches/@[email protected].4.patch",
"[email protected]": "patches/[email protected]"
}
}
Expand Down
8 changes: 4 additions & 4 deletions [email protected][email protected]
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/dist/changesets-assemble-release-plan.cjs.js b/dist/changesets-assemble-release-plan.cjs.js
index 60427457c887f2d72168fecec83d79088c68e3a4..b48899c83ca2bc5bfa0cbb65e0c098d5bb65fe3d 100644
index 4f7b5e5b37bb05874a5c1d8e583e29d4a9593ecf..980ead81554a8d925b6366e1644f3be03765398e 100644
--- a/dist/changesets-assemble-release-plan.cjs.js
+++ b/dist/changesets-assemble-release-plan.cjs.js
@@ -189,7 +189,7 @@ function determineDependents({
@@ -237,7 +237,7 @@ function determineDependents({
preInfo,
onlyUpdatePeerDependentsWhenOutOfRange: config.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH.onlyUpdatePeerDependentsWhenOutOfRange
})) {
Expand All @@ -12,10 +12,10 @@ index 60427457c887f2d72168fecec83d79088c68e3a4..b48899c83ca2bc5bfa0cbb65e0c098d5
switch (depType) {
case "dependencies":
diff --git a/dist/changesets-assemble-release-plan.esm.js b/dist/changesets-assemble-release-plan.esm.js
index f6583cf3f639e1fe4df764a015689dea74127236..2b9dca9f460793596394484457a94a34bcc1d99a 100644
index a327d9e4c709a6698f505d60d8bbf0046d4bde74..eb00fec7262280fb4876165c942212abc6b25efb 100644
--- a/dist/changesets-assemble-release-plan.esm.js
+++ b/dist/changesets-assemble-release-plan.esm.js
@@ -178,7 +178,7 @@ function determineDependents({
@@ -226,7 +226,7 @@ function determineDependents({
preInfo,
onlyUpdatePeerDependentsWhenOutOfRange: config.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH.onlyUpdatePeerDependentsWhenOutOfRange
})) {
Expand Down

0 comments on commit 243077d

Please sign in to comment.