-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab1c2cc
commit f2ab571
Showing
5 changed files
with
124 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package commands | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"internal/types" | ||
"internal/utils" | ||
"os" | ||
) | ||
|
||
func EmitDts(cwd string, name string) error { | ||
|
||
packageJson, err := utils.ReadPackageJson(cwd + "/package.json") | ||
|
||
if err != nil { | ||
fmt.Println("Could not read package.json", cwd+"./package.json") | ||
buildWg.Done() | ||
return err | ||
} | ||
|
||
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. Error:", err) | ||
buildWg.Done() | ||
return errors.New("cannot find bundle-dts path") | ||
} | ||
} | ||
fmt.Println("Package manager is ", packageJson.TSDEV.PackageManager) | ||
err = utils.ExecWithOutput(cwd, utils.GetPackageManager(packageJson.TSDEV.PackageManager), "tsc", "--outDir", "dist/src/") | ||
if err != nil { | ||
buildWg.Done() | ||
return err | ||
} | ||
return bundleDts(cwd, name) | ||
} | ||
|
||
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. Error:", err) | ||
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 RunDts() error { | ||
|
||
cwd, err := os.Getwd() | ||
|
||
utils.CheckErr(err) | ||
name, err := utils.GetName() | ||
utils.CheckErr(err) | ||
buildWg.Add(1) | ||
|
||
go EmitDts(cwd, name) | ||
|
||
buildWg.Wait() | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package utils | ||
|
||
import "internal/types" | ||
|
||
func GetPackageManager(packageManger types.PackageManagerType) string { | ||
|
||
switch packageManger { | ||
case types.Pnpm: | ||
{ | ||
return "pnpm" | ||
} | ||
case types.Yarn: | ||
{ | ||
return "yarn" | ||
} | ||
case types.Npm: | ||
{ | ||
return "npm" | ||
} | ||
default: | ||
{ | ||
return "npm" | ||
} | ||
} | ||
} |