Skip to content

Commit

Permalink
fix: 'fix create-project'
Browse files Browse the repository at this point in the history
  • Loading branch information
irsyadadl committed Jan 15, 2025
1 parent 252c27c commit 4fd102d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 40 deletions.
10 changes: 5 additions & 5 deletions dist/index.js

Large diffs are not rendered by default.

16 changes: 2 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
"bin": {
"justd-cli": "dist/index.js"
},
"files": [
"dist",
"src/resources",
"LICENSE",
"README.md",
"package.json"
],
"files": ["dist", "src/resources", "LICENSE", "README.md", "package.json"],
"repository": {
"type": "git",
"url": "git+https://github.com/justdlabs/cli.git"
Expand All @@ -32,13 +26,7 @@
"release": "export GITHUB_TOKEN=$(cat .github_token) && release-it",
"typecheck": "tsc --noEmit"
},
"keywords": [
"cli",
"justd cli",
"Justd",
"design-system",
"justd"
],
"keywords": ["cli", "justd cli", "Justd", "design-system", "justd"],
"author": "Irsyad A. Panjaitan",
"license": "MIT",
"devDependencies": {
Expand Down
28 changes: 14 additions & 14 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { fileURLToPath } from "node:url"
import { changeGray } from "@/commands/change-gray"
import { startNewProject } from "@/commands/start-new-project"
import { addUiPathToLangConfig, writeCodeFile } from "@/utils"
import { type Config, type ConfigInput, configManager } from "@/utils/config"
import { type ConfigInput, configManager } from "@/utils/config"
import { getPackageManager } from "@/utils/get-package-manager"
import { isRepoDirty } from "@/utils/git"
import {
Expand Down Expand Up @@ -40,7 +40,7 @@ export async function init(flags: {
yes?: boolean
language?: "typescript" | "javascript"
}) {
let language: Config["language"] = flags.language || "typescript"
let language = flags.language

if (!doesProjectExist()) {
const shouldStartNewProject = await input({
Expand Down Expand Up @@ -73,7 +73,9 @@ export async function init(flags: {
}
}

language = isTypescriptProject() ? "typescript" : "javascript"
if (!language) {
language = isTypescriptProject() ? "typescript" : "javascript"
}

if (!flags.force) {
const checkingGit = ora("Checking.").start()
Expand Down Expand Up @@ -188,24 +190,23 @@ export async function init(flags: {
fs.mkdirSync(uiFolder, { recursive: true })
}

async function getUserAlias(language: "typescript" | "javascript"): Promise<string | null> {
const configFilePaths =
language === "typescript"
? [path.join(process.cwd(), "tsconfig.app.json"), path.join(process.cwd(), "tsconfig.json")]
: [path.join(process.cwd(), "jsconfig.json")]
async function getUserAlias(): Promise<string> {
const isTypescript = language === "typescript"
const configFilePaths = isTypescript
? [path.join(process.cwd(), "tsconfig.app.json"), path.join(process.cwd(), "tsconfig.json")]
: [path.join(process.cwd(), "jsconfig.json")]

const configFilePath = configFilePaths.find((configPath) => fs.existsSync(configPath))
let config: any

if (!configFilePath) {
console.error(
language === "typescript"
isTypescript
? "Neither tsconfig.app.json nor tsconfig.json was found."
: "jsconfig.json was not found.",
)
process.exit(1)
}

let config: any
try {
const configRaw = fs.readFileSync(configFilePath, "utf8")
const stripped = stripJsonComments(configRaw)
Expand All @@ -223,7 +224,6 @@ export async function init(flags: {

if (!("paths" in config.compilerOptions)) {
const rootPath = "./src"

config.compilerOptions.paths = {
"@/*": [`${rootPath}/*`],
}
Expand All @@ -239,7 +239,7 @@ export async function init(flags: {
}
}

await addUiPathToLangConfig(language)
await addUiPathToLangConfig(isTypescript ? "typescript" : "javascript")

const paths = config.compilerOptions.paths
if (paths) {
Expand All @@ -250,7 +250,7 @@ export async function init(flags: {
process.exit(1)
}

const currentAlias = await getUserAlias(language)
const currentAlias = await getUserAlias()

if (isTailwind(3)) {
const content = fs.readFileSync(path.join(stubs, "1.x/zinc.css"), "utf8")
Expand Down
5 changes: 3 additions & 2 deletions src/commands/start-new-project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { input, select } from "@inquirer/prompts"
import { executeCommand } from "./partials/execute-command"

const isProduction = process.env.NODE_ENV === "production"
const cliCommand = isProduction ? "justd-cli@latest" : "justd-cli"

const frameworks: Record<FrameworkKey, Framework> = {
laravel: {
Expand Down Expand Up @@ -180,7 +179,9 @@ export async function startNewProject(
await setupBiome(packageManager)
}

const tsOrJs = language === "typescript" ? "--language --ts" : "--language --js"
// const cliCommand = isProduction ? "justd-cli@latest" : "justd-cli"

const tsOrJs = language === "typescript" ? "--ts" : "--js"
const initJustdCommand = ["npx", "justd-cli@latest", "init", tsOrJs, "--force", "--yes"]
await executeCommand(initJustdCommand, "Finishing.")

Expand Down
6 changes: 1 addition & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ program
.command("init")
.option("--force", "Force initialization without checking Git")
.option("-y, --yes", "Skip prompts and use default values")
.option(
"-l, --language <language>",
"Language of the project (typescript or javascript)",
"typescript",
)
.option("-l, --language <language>", "Language of the project (typescript or javascript)")
.option("--ts", "Use TypeScript for the project")
.option("--js", "Use JavaScript for the project")
.action((options) => {
Expand Down

0 comments on commit 4fd102d

Please sign in to comment.