Skip to content

Commit

Permalink
build/test commands
Browse files Browse the repository at this point in the history
  • Loading branch information
teintinu committed Aug 9, 2021
1 parent 524c166 commit 1190ff6
Show file tree
Hide file tree
Showing 33 changed files with 238 additions and 141 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

node_modules

__debug_bin

npm/

snapshot/**/*.js
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ It will create and maintain automatically package.json, tsconfig.json, eslint.js
`monoclean build` build everything in the repository

### another commands
- [ ] monoclean build
- [ ] monoclean run
- [ ] monoclean watch --tray
- [ ] https://github.com/getlantern/systray
Expand Down
2 changes: 1 addition & 1 deletion cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var buildCmd = &cobra.Command{
Args: cobra.RangeArgs(0, 0),
RunE: func(cmd *cobra.Command, args []string) error {
internal.Logger.FlagInit()
repo := mustLoadRepository()
repo := mustLoadRepository(true)
if err := internal.CheckEngines(repo); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var cleanCmd = &cobra.Command{
Short: "Removes build output.",
Long: `Removes build output.`,
RunE: func(cmd *cobra.Command, args []string) error {
repo := mustLoadRepository()
repo := mustLoadRepository(false)
return internal.CleanRepository(repo)
},
}
2 changes: 1 addition & 1 deletion cmd/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var depsCmd = &cobra.Command{
Short: "Install dependencies",
Long: `Generates a root package.json, tsconfig.json and other config files and runs your package manager.`,
RunE: func(cmd *cobra.Command, args []string) error {
repo := mustLoadRepository()
repo := mustLoadRepository(false)
if err := internal.CheckEngines(repo); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var lintCmd = &cobra.Command{
DisableFlagsInUseLine: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
repo := mustLoadRepository()
repo := mustLoadRepository(true)
if err := internal.CheckEngines(repo); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Prints the absolute path of each created package.
The package must already be built. Use the build command.`,
Args: cobra.RangeArgs(0, 1),
RunE: func(cmd *cobra.Command, args []string) error {
repo := mustLoadRepository()
repo := mustLoadRepository(true)

var packages map[string]*internal.Package
switch len(args) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var publishCmd = &cobra.Command{
The package must already be packed. Use the pack command.`,
Args: cobra.RangeArgs(0, 1),
RunE: func(cmd *cobra.Command, args []string) error {
repo := mustLoadRepository()
repo := mustLoadRepository(true)
if err := internal.CheckEngines(repo); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var replCmd = &cobra.Command{
Short: "Start a Read Evaluate Print Loop.",
Long: "Start a Read Evaluate Print Loop.",
RunE: func(cmd *cobra.Command, args []string) error {
repo := mustLoadRepository()
repo := mustLoadRepository(false)
if err := internal.CheckEngines(repo); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ func Execute() {
}
}

func mustLoadRepository() *internal.Repository {
func mustLoadRepository(checkEntryPoints bool) *internal.Repository {
cwd, err := os.Getwd()
if err != nil {
internal.Logger.ErrorObj(err)
os.Exit(1)
}
repo, err := internal.LoadRepository(cwd)
repo, err := internal.LoadRepository(cwd, checkEntryPoints)
if err != nil {
internal.Logger.ErrorObj(err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var runCmd = &cobra.Command{
DisableFlagsInUseLine: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
repo := mustLoadRepository()
repo := mustLoadRepository(true)
var packagesToRun []string = []string{}

if err := internal.CheckEngines(repo); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var testCmd = &cobra.Command{
DisableFlagsInUseLine: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
repo := mustLoadRepository()
repo := mustLoadRepository(true)
if err := internal.CheckEngines(repo); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions examples/clean-architecture/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ node_modules
.nvm.rc
package.json
package-lock.json
yarn-lock.*
yarn-error.log
yarn.lock
tsconfig.**
jest.config.js
Expand All @@ -12,4 +12,4 @@ out
.eslintrc.json
coverage
.vscode

jest.config.js
4 changes: 2 additions & 2 deletions examples/new/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ node_modules
.nvm.rc
package.json
package-lock.json
yarn-lock.*
yarn-error.log
yarn.lock
tsconfig.**
jest.config.js
Expand All @@ -12,4 +12,4 @@ out
.eslintrc.json
coverage
.vscode

jest.config.js
4 changes: 2 additions & 2 deletions examples/new/monoclean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ workspace:

packages:
"@new/a":
public: true
publish: public
folder: "a"
dependencies:
"@new/b": "*"

"@new/b":
public: true
publish: public
folder: "b"
2 changes: 1 addition & 1 deletion examples/simple-workspace/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ out
.eslintrc.json
coverage
.vscode

jest.config.js
2 changes: 1 addition & 1 deletion examples/simple-workspace/a/src/a.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { functionA } from './'
import { functionA } from './index'

it('module a', () => {
expect(functionA()).toEqual({
Expand Down
7 changes: 7 additions & 0 deletions examples/simple-workspace/appA/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {functionA} from '@simple-workspace/a'

export async function main() {
console.log(functionA())
}

main().catch(console.log)
7 changes: 7 additions & 0 deletions examples/simple-workspace/appD/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {functionD} from '@simple-workspace/d'

export async function main() {
console.log(functionD())
}

main().catch(console.log)
34 changes: 0 additions & 34 deletions examples/simple-workspace/jest.config.js

This file was deleted.

29 changes: 21 additions & 8 deletions examples/simple-workspace/monoclean.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
engines:
node: "v14.17.3"
npm: "6.14.13"
workspace:
name: "simple-workspace"
version: "1.0.0"

packages:
"@simple-workspace/a":
"appA":
publish: public
folder: "appA"
executable: true
dependencies:
"@simple-workspace/a": "*"

"appD":
publish: public
folder: "appD"
executable: true
dependencies:
"@simple-workspace/d": "*"

"@simple-workspace/a":
publish: public
folder: "a"
dependencies:
"@simple-workspace/b": "*"
Expand Down Expand Up @@ -34,6 +47,6 @@ packages:
publish: public
folder: "e"

workspace:
name: "simple-workspace"
version: "1.0.0"
engines:
node: "v14.17.3"
npm: "6.14.13"
8 changes: 4 additions & 4 deletions internal/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ func BuildWorkspace(repo *Repository) error {
}

func bundleExecutable(repo *Repository, pkg *Package) error {
Logger.Info("Bundling executable ", pkg.Name)
Logger.Info("Bundling executable:", pkg.Name)
msgs, err := BundleWithEsbuild(repo, pkg)
if err != nil {
Logger.ErrorObj(err)
}
for _, msg := range msgs.Errors {
Logger.Error(msg.Text)
}
Logger.Debug("Bundled executable ", pkg.Name)
Logger.Debug("Bundled executable:", pkg.Name)
return err
}

func buildLibrary(repo *Repository, pkg *Package) error {
Logger.Info("Building library ", pkg.Name)
Logger.Info("Building library :", pkg.Name)
err := BuildWithTSC(repo, pkg)
if err != nil {
Logger.ErrorObj(err)
}
Logger.Debug("Built library ", pkg.Name)
Logger.Debug("Built library :", pkg.Name)
return err
}
3 changes: 2 additions & 1 deletion internal/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ type PackageMetadata struct {
Private bool `json:"private"`
Repository string `json:"repository,omitempty"`
Main string `json:"main,omitempty"`
Bin map[string]string `json:"bin,omitempty"`
Types string `json:"types,omitempty"`
Bin string `json:"bin,omitempty"`
Dependencies map[string]string `json:"dependencies,omitempty"`
DevDependencies map[string]string `json:"devDependencies,omitempty"`
Scripts map[string]string `json:"scripts,omitempty"`
Expand Down
39 changes: 19 additions & 20 deletions internal/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type Executable struct {

const DefaultRegistry = "https://registry.npmjs.org/"

func LoadRepository(searchDir string) (*Repository, error) {
func LoadRepository(searchDir string, checkEntryPoints bool) (*Repository, error) {
f, err := openConfigFile(searchDir)
if err != nil {
return nil, err
Expand Down Expand Up @@ -115,19 +115,19 @@ func LoadRepository(searchDir string) (*Repository, error) {
}

repo.Packages = make(map[string]*Package)
err = loadPackages(&repo, cfg.Packages, NormalLayer)
err = loadPackages(&repo, cfg.Packages, NormalLayer, checkEntryPoints)
if err != nil {
return nil, err
}
err = loadPackages(&repo, cfg.BusinessRules, BusinessRulesLayer)
err = loadPackages(&repo, cfg.BusinessRules, BusinessRulesLayer, checkEntryPoints)
if err != nil {
return nil, err
}
err = loadPackages(&repo, cfg.Executables, ExecutablesLayer)
err = loadPackages(&repo, cfg.Executables, ExecutablesLayer, checkEntryPoints)
if err != nil {
return nil, err
}
err = loadPackages(&repo, cfg.Adapters, AdaptersLayer)
err = loadPackages(&repo, cfg.Adapters, AdaptersLayer, checkEntryPoints)
if err != nil {
return nil, err
}
Expand All @@ -146,15 +146,22 @@ func LoadRepository(searchDir string) (*Repository, error) {
}
}
for pkgName := range repo.Packages {
err = validateLayer(&repo, repo.Packages[pkgName])
pkg := repo.Packages[pkgName]
if checkEntryPoints {
_, err = GetPackageEntryPoint(&repo, pkg)
if err != nil {
return nil, err
}
}
err = validateLayer(&repo, pkg)
if err != nil {
return nil, err
}
}
return &repo, nil
}

func loadPackages(repo *Repository, packages map[string]PackageConfig, layer PackageLayer) error {
func loadPackages(repo *Repository, packages map[string]PackageConfig, layer PackageLayer, checkEntryPoints bool) error {
for packageName, packageConfig := range packages {

if len(packageConfig.Index) > 0 {
Expand Down Expand Up @@ -208,25 +215,17 @@ func loadPackages(repo *Repository, packages map[string]PackageConfig, layer Pac
}

if pkg.Executable {
if endpoint, err := GetPackageEntryPoint(repo, pkg); err != nil {
if _, err := GetPackageEntryPoint(repo, pkg); err != nil && checkEntryPoints {
return err
} else {
if endpoint == "" {
return errors.New("package " + pkg.Name + " has not main.ts entrypoint")
} else {
pkg.Bin = path.Join(pkgFolder, "dist/main.js")
}
pkg.Bin = path.Join(pkgFolder, "dist/main.js")
}
} else {
if endpoint, err := GetPackageEntryPoint(repo, pkg); err != nil {
if _, err := GetPackageEntryPoint(repo, pkg); err != nil && checkEntryPoints {
return err
} else {
if endpoint == "" {
return errors.New("package " + pkg.Name + " has not index.ts or index.tsx")
} else {
pkg.Main = path.Join(pkgFolder, "dist/index.js")
pkg.Types = path.Join(pkgFolder, "dist/index.d.ts")
}
pkg.Main = path.Join(pkgFolder, "dist/index.js")
pkg.Types = path.Join(pkgFolder, "dist/index.d.ts")
}
}
repo.Packages[packageName] = pkg
Expand Down
3 changes: 3 additions & 0 deletions internal/required.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ var requiredWorkspaceDevDependencies = map[string]string{
var requiredPackageDevDependencies = map[string]string{
"source-map-support": "^0.5.19",
"@types/source-map-support": "^0.5.3",
"jest": "^27.0.6",
"@types/jest": "^26.0.24",
"ts-jest": "^27.0.3",
"typescript": "^4.3.5",
"dts-bundle-generator": "^5.9.0",
"esbuild": "^0.12.15",
Expand Down
Loading

0 comments on commit 1190ff6

Please sign in to comment.