Skip to content

Commit

Permalink
♻️ Fix pathing on lint, prettier and dts-bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
CryogenicPlanet committed Dec 12, 2021
1 parent b49456e commit 19576db
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
21 changes: 17 additions & 4 deletions internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,33 @@ import (

var buildWg sync.WaitGroup

func emitDts(cwd string, name string) {
func emitDts(cwd string, name string) error {
if _, err := os.Stat(types.BUNDLE_DTS_PATH); errors.Is(err, os.ErrNotExist) {

fmt.Println("[WARN] You can only use --dts flag if you have installed tsdev as a dependency")
buildWg.Done()
return
return nil
}
utils.ExecWithOutput(cwd, "tsc", "--outDir", "dist/src/")
bundleDts(cwd, name)
return bundleDts(cwd, name)
}

func bundleDts(cwd string, name string) {
func bundleDts(cwd string, name string) error {

if _, err := os.Stat(types.BUNDLE_DTS_PATH); errors.Is(err, os.ErrNotExist) {

if _, err := os.Stat(types.BUNDLE_BACKUP_DTS_PATH); errors.Is(err, os.ErrNotExist) {
fmt.Println("[WARN] You can only use --dts flag if you have installed tsdev as a dependency")
return errors.New("cannot find bundle-dts path")
}
utils.ExecWithOutput(cwd, "node", types.BUNDLE_BACKUP_DTS_PATH, "--name", name, "--main", "dist/src/index.d.ts", "--out", "../index.d.ts")
buildWg.Done()
return nil
}

utils.ExecWithOutput(cwd, "node", types.BUNDLE_DTS_PATH, "--name", name, "--main", "dist/src/index.d.ts", "--out", "../index.d.ts")
buildWg.Done()
return nil
}

func buildCJS(entryPoint string, cwd string) {
Expand Down
13 changes: 12 additions & 1 deletion internal/commands/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ func HandleLintCommand(fix bool) error {

if _, err := os.Stat(types.ESLINT_PATH); errors.Is(err, os.ErrNotExist) {

return fmt.Errorf("cannot use lint without installing tsdev as a dependency")
if _, err := os.Stat(types.ESLINT_BACKUP_PATH); errors.Is(err, os.ErrNotExist) {

return fmt.Errorf("cannot use lint without installing tsdev as a dependency")

}

if fix {
utils.ExecWithOutput(cwd, "node", types.ESLINT_BACKUP_PATH, "--config", types.ESLINT_CONFIG_PATH, "src/*", "--fix")
} else {
utils.ExecWithOutput(cwd, "node", types.ESLINT_BACKUP_PATH, "--config", types.ESLINT_CONFIG_PATH, "src/*")
}
return nil
}

if fix {
Expand Down
11 changes: 10 additions & 1 deletion internal/commands/prettier.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ func HandlePrettierCommand() error {

if _, err := os.Stat(types.PRETTY_QUICK_PATH); errors.Is(err, os.ErrNotExist) {

return fmt.Errorf("cannot use prettier without installing tsdev as a dependency")
if _, err := os.Stat(types.PRETTY_BACKUP_QUICK_PATH); errors.Is(err, os.ErrNotExist) {

return fmt.Errorf("cannot use prettier without installing tsdev as a dependency")
}

cwd, err := os.Getwd()

utils.CheckErr(err)

return utils.ExecWithOutput(cwd, "node", types.PRETTY_BACKUP_QUICK_PATH, "--staged")
}

cwd, err := os.Getwd()
Expand Down
12 changes: 9 additions & 3 deletions internal/types/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ package types

const PACKAGE_NAME = "@cryogenicplanet/tsdev"

const BUNDLE_DTS_PATH = "node_modules/" + PACKAGE_NAME + "/node_modules/dts-bundle/lib/dts-bundle.js"
const BUNDLE_DTS_PATH = "node_modules/" + PACKAGE_NAME + "/" + BUNDLE_BACKUP_DTS_PATH

const BUNDLE_BACKUP_DTS_PATH = "node_modules/dts-bundle/lib/dts-bundle.js"

const ESLINT_CONFIG_PATH = "node_modules/" + PACKAGE_NAME + "/dist/.eslintrc"

const ESLINT_PATH = "node_modules/" + PACKAGE_NAME + "/node_modules/eslint/bin/eslint.js"
const ESLINT_PATH = "node_modules/" + PACKAGE_NAME + "/" + ESLINT_BACKUP_PATH

const ESLINT_BACKUP_PATH = "node_modules/eslint/bin/eslint.js"

const PRETTY_QUICK_PATH = "node_modules/" + PACKAGE_NAME + "/" + PRETTY_BACKUP_QUICK_PATH

const PRETTY_QUICK_PATH = "node_modules/" + PACKAGE_NAME + "/node_modules/pretty-quick/bin/pretty-quick.js"
const PRETTY_BACKUP_QUICK_PATH = "node_modules/pretty-quick/bin/pretty-quick.js"

0 comments on commit 19576db

Please sign in to comment.