Skip to content

Commit

Permalink
add cli template
Browse files Browse the repository at this point in the history
  • Loading branch information
IMax153 committed Sep 5, 2024
1 parent 48086ca commit af48851
Show file tree
Hide file tree
Showing 28 changed files with 6,708 additions and 430 deletions.
79 changes: 0 additions & 79 deletions .eslintrc.cjs

This file was deleted.

122 changes: 122 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { fixupPluginRules } from "@eslint/compat"
import { FlatCompat } from "@eslint/eslintrc"
import js from "@eslint/js"
import tsParser from "@typescript-eslint/parser"
import codegen from "eslint-plugin-codegen"
import deprecation from "eslint-plugin-deprecation"
import _import from "eslint-plugin-import"
import simpleImportSort from "eslint-plugin-simple-import-sort"
import sortDestructureKeys from "eslint-plugin-sort-destructure-keys"
import path from "node:path"
import { fileURLToPath } from "node:url"

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
})

export default [
{
ignores: ["**/dist", "**/build", "**/docs", "**/*.md"]
},
...compat.extends(
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@effect/recommended"
),
{
plugins: {
deprecation,
import: fixupPluginRules(_import),
"sort-destructure-keys": sortDestructureKeys,
"simple-import-sort": simpleImportSort,
codegen
},

languageOptions: {
parser: tsParser,
ecmaVersion: 2018,
sourceType: "module"
},

settings: {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},

"import/resolver": {
typescript: {
alwaysTryTypes: true
}
}
},

rules: {
"codegen/codegen": "error",
"no-fallthrough": "off",
"no-irregular-whitespace": "off",
"object-shorthand": "error",
"prefer-destructuring": "off",
"sort-imports": "off",

"no-restricted-syntax": ["error", {
selector: "CallExpression[callee.property.name='push'] > SpreadElement.arguments",
message: "Do not use spread arguments in Array.push"
}],

"no-unused-vars": "off",
"prefer-rest-params": "off",
"prefer-spread": "off",
"import/first": "error",
"import/newline-after-import": "error",
"import/no-duplicates": "error",
"import/no-unresolved": "off",
"import/order": "off",
"simple-import-sort/imports": "off",
"sort-destructure-keys/sort-destructure-keys": "error",
"deprecation/deprecation": "off",

"@typescript-eslint/array-type": ["warn", {
default: "generic",
readonly: "generic"
}],

"@typescript-eslint/member-delimiter-style": 0,
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/consistent-type-imports": "warn",

"@typescript-eslint/no-unused-vars": ["error", {
argsIgnorePattern: "^_",
varsIgnorePattern: "^_"
}],

"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/no-array-constructor": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-namespace": "off",

"@effect/dprint": ["error", {
config: {
indentWidth: 2,
lineWidth: 120,
semiColons: "asi",
quoteStyle: "alwaysDouble",
trailingCommas: "never",
operatorPosition: "maintain",
"arrowFunction.useParentheses": "force"
}
}]
}
}
]
6 changes: 3 additions & 3 deletions examples/http-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
"@opentelemetry/exporter-trace-otlp-http": "^0.53.0",
"@opentelemetry/sdk-trace-base": "^1.26.0",
"@opentelemetry/sdk-trace-node": "^1.26.0",
"effect": "^3.7.0",
"effect": "^3.7.2",
"uuid": "^10.0.0"
},
"devDependencies": {
"@effect/language-service": "^0.1.0",
"@effect/vitest": "^0.9.0",
"@types/node": "^22.5.1",
"@effect/vitest": "^0.9.2",
"@types/node": "^22.5.3",
"@types/uuid": "^10.0.0",
"prettier": "^3.3.3",
"tsup": "^8.2.4",
Expand Down
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
"@changesets/cli": "^2.27.7",
"@effect/eslint-plugin": "^0.2.0",
"@effect/language-service": "^0.1.0",
"@effect/vitest": "^0.9.0",
"@types/node": "^22.5.2",
"@effect/vitest": "^0.9.2",
"@eslint/compat": "^1.1.1",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.9.1",
"@types/node": "^22.5.3",
"@typescript-eslint/eslint-plugin": "^8.4.0",
"@typescript-eslint/parser": "^8.4.0",
"eslint": "^8.57.0",
"effect": "^3.7.2",
"eslint": "^9.9.1",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-codegen": "^0.28.0",
"eslint-plugin-deprecation": "^3.0.0",
Expand All @@ -42,11 +46,6 @@
"patchedDependencies": {
"@changesets/[email protected]": "patches/@[email protected]",
"@changesets/[email protected]": "patches/@[email protected]"
},
"updateConfig": {
"ignoreDependencies": [
"eslint"
]
}
}
}
7 changes: 4 additions & 3 deletions packages/create-effect-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"description": "Create Effect-powered applications with a single command",
"engines": {
"node": ">=20.16.0"
"node": ">=20.14.0"
},
"repository": {
"type": "git",
Expand All @@ -25,10 +25,11 @@
"check": "tsc -b tsconfig.json"
},
"devDependencies": {
"@effect/cli": "^0.42.0",
"@effect/cli": "^0.42.2",
"@effect/platform": "^0.63.0",
"@effect/platform-node": "^0.58.0",
"effect": "^3.7.0",
"effect": "^3.7.2",
"tar": "^7.4.3",
"tsup": "^8.2.4"
}
}
93 changes: 87 additions & 6 deletions packages/create-effect-app/src/Cli.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,104 @@
import * as Args from "@effect/cli/Args"
import * as Command from "@effect/cli/Command"
import * as Options from "@effect/cli/Options"
import * as Prompt from "@effect/cli/Prompt"
import * as FileSystem from "@effect/platform/FileSystem"
import * as Effect from "effect/Effect"
import * as Option from "effect/Option"
import type { TemplateOptions } from "./Domain.js"
import { GitHub } from "./GitHub.js"
import * as InternalVersion from "./internal/version.js"
import { validateProjectName } from "./Utils.js"

const projectName = Prompt.text({
message: "What is your project named?",
default: "effect-app",
validate: (name) =>
Option.match(validateProjectName(name), {
onNone: () => Effect.succeed(name),
onSome: Effect.fail
})
})

const projectType = Prompt.select<"basic" | "monorepo" | "cli">({
message: "What type of project should be created?",
choices: [
{
title: "Basic Package",
value: "basic",
description: "A project containing a single package"
},
{
title: "Multi Package",
value: "monorepo",
description: "A project containing multiple packages or applications"
},
{
title: "CLI Application",
value: "cli",
description: "A project containing a CLI application"
}
]
})

const prompt: Prompt.Prompt<TemplateOptions> = Prompt.all({
projectName,
projectType
})

const example = Options.text("example").pipe(
Options.withAlias("e"),
Options.withDescription(
"The name of an official Effect example to use to bootstrap the application"
)
),
Options.optional
)

const outDir = Options.directory("out-dir", { exists: "no" }).pipe(
Options.withAlias("o"),
Options.withDefault("."),
Options.withDescription("The directory to output the Effect application code into")
const directory = Args.directory({
name: "project-directory",
exists: "no"
}).pipe(
Args.withDefault("."),
Args.withDescription("The directory to output the Effect application code into")
)

const command = Command.make("create-effect-app", { example, outDir })
const command = Command.make("create-effect-app", { example, directory }).pipe(
Command.withDescription("Create an Effect application from an example or a template repository"),
Command.withHandler(({ directory, example }) =>
Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
yield* fs.makeDirectory(directory)
return yield* Option.match(example, {
onNone: () => Effect.orDie(Effect.asVoid(prompt)),
onSome: (example) => createExample(directory, example)
})
})
),
Command.provide(GitHub.Live)
)

export const cli = Command.run(command, {
name: "Create Effect App",
version: `v${InternalVersion.moduleVersion}`
})

function createExample(directory: string, example: string) {
return Effect.gen(function*() {
// TODO: logging
yield* GitHub.downloadExample(directory, example)
})
}

function createTemplate(directory: string) {
return Effect.gen(function*() {
// TODO: logging
const options = yield* prompt
yield* GitHub.downloadTemplate(directory, options)
})
}

// packages/*/package.json
// tsconfig.base.json
// tsconfig.build.json
// tsconfig.json
// vitest.shared.ts
4 changes: 4 additions & 0 deletions packages/create-effect-app/src/Domain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface TemplateOptions {
readonly projectName: string
readonly projectType: "basic" | "monorepo" | "cli"
}
Loading

0 comments on commit af48851

Please sign in to comment.