Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Feat/#173 #175

Merged
merged 6 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ build-times.png

# python
__pycache__
.pytest_cache
.pytest_cache

/examples/spa/dist
23 changes: 17 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
# Contributing to orbit

### Finding a task
## Finding a task

Before contributing to this project, please ensure that an open issue first exists outlining that issue you plan to resolve.

### Running the project
## Running the project

To run the project, please first download the required tools.

- nodeJS >= v11
- golang 1.14

### Building the project
## Building the project

After golang is installed on your machine, you can build with `go run build`

### Running tests
You can run the tests with `make test`
## Running tests

### Requirements

- lighthouse CLI `npm i -g lighthouse`
- pytest `pip install pytest`

You can run the entire test suite with `make test` or the go tests with `make gotest` or integration tests with `make integrationtest`

## Committing code

### Committing code
This project uses the golang project standard for commit messages, you find it [here](https://go.dev/doc/contribute#commit_messages).
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ license:
gotest:
go test `go list ./... | grep -v examples`

test:
make gotest

integrationtest:
echo 'running integration tests'
make example
pytest ./scripts/test

test:
make gotest
make integrationtest

44 changes: 26 additions & 18 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,47 @@ var buildCMD = &cobra.Command{
logger.Warn(err.Error())
}

if viper.GetString("build_bundle_mode") != "production" {
buildOpts := internal.NewBuildOptsFromViper()
if buildOpts.Mode != "production" {
logger.Warn(fmt.Sprintf("bundling mode '%s'\n", viper.GetString("build_bundle_mode")))
}

buildOpts := &internal.BuildOpts{
Packname: viper.GetString("pacname"),
OutDir: viper.GetString("out"),
WebDir: viper.GetString("webdir"),
Mode: viper.GetString("build_bundle_mode"),
NodeModulePath: viper.GetString("nodemod"),
PublicDir: viper.GetString("publicdir"),
}
components, err := internal.Build(buildOpts)
if len(components) < 1 {
logger.Warn("no components were found, exiting")
return
}

if viper.GetString("spa_entry_path") != "" {
// if we are using the spa settings, there will only be a single bundle component
if err := internal.BuildSPA(components[0], &internal.SPABuildOpts{
PublicHTMLPath: viper.GetString("public_path"),
SpaOutDir: viper.GetString("spa_out_dir"),
}); err != nil {
logger.Error(err.Error())
return
}
}

if err != nil {
logger.Error(err.Error())
return
}

if viper.GetString("auditpage") != "" {
components.Write(viper.GetString("auditpage"))
if viper.GetString("audit_path") != "" {
components.Write(viper.GetString("audit_path"))
}

if viper.GetString("depout") != "" {
sourceMap, err := srcpack.New(viper.GetString("webdir"), components, &srcpack.NewSourceMapOpts{
WebDirPath: viper.GetString("webdir"),
if viper.GetString("dep_map_out_dir") != "" {
sourceMap, err := srcpack.New(viper.GetString("app_dir"), components, &srcpack.NewSourceMapOpts{
WebDirPath: buildOpts.ApplicationDir,
Parser: &jsparse.JSFileParser{},
})
if err != nil {
panic(err)
}

err = sourceMap.Write(viper.GetString("depout"))
err = sourceMap.Write(viper.GetString("dep_map_out_dir"))
if err != nil {
panic(err)
}
Expand All @@ -72,9 +80,9 @@ func init() {
var pageaudit string
var mode string

buildCMD.PersistentFlags().StringVar(&pageaudit, "auditpage", "", "file path used to output an audit file for the pages")
viper.BindPFlag("auditpage", buildCMD.PersistentFlags().Lookup("auditpage"))
buildCMD.PersistentFlags().StringVar(&pageaudit, "audit_path", "", "file path used to output an audit file for the pages")
viper.BindPFlag("audit_path", buildCMD.PersistentFlags().Lookup("audit_path"))

buildCMD.PersistentFlags().StringVar(&mode, "mode", "production", "specifies the underlying bundler mode to run in")
viper.BindPFlag("build_bundle_mode", buildCMD.PersistentFlags().Lookup("mode"))
viper.BindPFlag("mode", buildCMD.PersistentFlags().Lookup("mode"))
}
38 changes: 23 additions & 15 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,47 @@ var RootCMD = &cobra.Command{
}

func init() {
var webdir string
var appDir string
var outDir string
var pacname string
var nodeModDir string
var publicDir string
var publicPath string
var dependout string
var spaEntry string
var spaOutDir string
var experimentalFeatures []string

buildCmds := [4]*cobra.Command{
buildCMD, devCMD, initCMD, deployCMD,
}

for _, cmd := range buildCmds {
cmd.PersistentFlags().StringVar(&webdir, "webdir", "./", "specifies the directory of the web pages, leave blank for use of the root dir")
viper.BindPFlag("webdir", cmd.PersistentFlags().Lookup("webdir"))
cmd.PersistentFlags().StringVar(&appDir, "app_dir", "./", "specifies the directory where the application lives, left blank will use the root directory")
viper.BindPFlag("app_dir", cmd.PersistentFlags().Lookup("app_dir"))

cmd.PersistentFlags().StringVar(&outDir, "out", "./", "specifies the out directory of the generated code files")
viper.BindPFlag("out", cmd.PersistentFlags().Lookup("out"))
cmd.PersistentFlags().StringVar(&outDir, "out_dir", "./", "specifies the out directory of the generated code files")
viper.BindPFlag("out_dir", cmd.PersistentFlags().Lookup("out_dir"))

cmd.PersistentFlags().StringVar(&publicDir, "publicdir", "./public/index.html", "specifies the public directory for the base html webpage")
viper.BindPFlag("publicdir", cmd.PersistentFlags().Lookup("publicdir"))
cmd.PersistentFlags().StringVar(&publicPath, "public_path", "./public/index.html", "specifies the path for the base html webpage default './public/index.html'")
viper.BindPFlag("public_path", cmd.PersistentFlags().Lookup("public_path"))

cmd.PersistentFlags().StringVar(&pacname, "pacname", "orbit", "specifies the package name of the generated code files")
viper.BindPFlag("pacname", cmd.PersistentFlags().Lookup("pacname"))
cmd.PersistentFlags().StringVar(&pacname, "package_name", "orbit", "specifies the package name of the generated code files")
viper.BindPFlag("package_name", cmd.PersistentFlags().Lookup("package_name"))

cmd.PersistentFlags().StringVar(&nodeModDir, "nodemod", "./node_modules", "specifies the directory to find node modules")
viper.BindPFlag("nodemod", cmd.PersistentFlags().Lookup("nodemod"))
cmd.PersistentFlags().StringVar(&nodeModDir, "node_modules_dir", "./node_modules", "specifies the directory to find node modules")
viper.BindPFlag("node_modules_dir", cmd.PersistentFlags().Lookup("node_modules_dir"))

cmd.PersistentFlags().StringVar(&dependout, "depout", "", "specifies the directory to output a dependency map")
viper.BindPFlag("depout", cmd.PersistentFlags().Lookup("depout"))
cmd.PersistentFlags().StringVar(&dependout, "dep_map_out_dir", "", "specifies the directory to output a dependency map")
viper.BindPFlag("dep_map_out_dir", cmd.PersistentFlags().Lookup("dep_map_out_dir"))

cmd.PersistentFlags().StringSliceVar(&experimentalFeatures, "experimental", []string{}, "comma delimated list of experimental features to turn on, to view experiemental features use the command 'experimental'")
cmd.PersistentFlags().StringSliceVar(&experimentalFeatures, "experimental", []string{}, "comma delimited list of experimental features to turn on, to view experiemental features use the command 'experimental'")
viper.BindPFlag("experimental", cmd.PersistentFlags().Lookup("experimental"))

cmd.PersistentFlags().StringVar(&spaEntry, "spa_entry_path", "", "when specified this entry should be the file name of the entrypoint file. note this command will force the application to become an SPA")
viper.BindPFlag("spa_entry_path", cmd.PersistentFlags().Lookup("spa_entry_path"))

cmd.PersistentFlags().StringVar(&spaOutDir, "spa_out_dir", "./dist", "output directory to write an SPA, requires 'spa_entry_path' to be set")
viper.BindPFlag("spa_out_dir", cmd.PersistentFlags().Lookup("spa_out_dir"))
}
}

Expand Down
24 changes: 6 additions & 18 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,17 @@ var deployCMD = &cobra.Command{
logger.Warn(err.Error())
}

buildOpts := &internal.BuildOpts{
Packname: viper.GetString("pacname"),
OutDir: viper.GetString("out"),
WebDir: viper.GetString("webdir"),
Mode: viper.GetString("deploy_bundle_mode"),
NodeModulePath: viper.GetString("nodemod"),
PublicDir: viper.GetString("publicdir"),
NoWrite: true,
Dirs: []string{
viper.GetString("staticout"),
},
buildOpts := internal.NewBuildOptsFromViper()
buildOpts.RequiredDirs = []string{
viper.GetString("static_out_dir"),
}

components, err := internal.Build(buildOpts)
if err != nil {
panic(err)
}

staticBuild := internal.NewStaticBuild(buildOpts, viper.GetString("staticout"))
staticBuild := internal.NewStaticBuild(buildOpts, viper.GetString("static_out_dir"))
err = staticBuild.Build(components)

if err != nil {
Expand All @@ -54,11 +46,7 @@ var deployCMD = &cobra.Command{

func init() {
var staticOut string
var mode string

deployCMD.PersistentFlags().StringVar(&staticOut, "staticout", "./static", "path for the static file directory")
viper.BindPFlag("staticout", deployCMD.PersistentFlags().Lookup("staticout"))

deployCMD.PersistentFlags().StringVar(&mode, "mode", "production", "specifies the underlying bundler mode to run in")
viper.BindPFlag("deploy_bundle_mode", deployCMD.PersistentFlags().Lookup("mode"))
deployCMD.PersistentFlags().StringVar(&staticOut, "static_out_dir", "./static", "path for the static file directory")
viper.BindPFlag("staticout", deployCMD.PersistentFlags().Lookup("static_out_dir"))
}
29 changes: 10 additions & 19 deletions cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,8 @@ var devCMD = &cobra.Command{
logger.Warn(err.Error())
}

s, err := internal.New(context.Background(), &internal.SessionOpts{
WebDir: viper.GetString("webdir"),
Mode: viper.GetString("dev_bundle_mode"),
Pacname: viper.GetString("pacname"),
OutDir: viper.GetString("out"),
NodeModDir: viper.GetString("nodemod"),
PublicDir: viper.GetString("publicdir"),
devSession, err := internal.NewDevSession(context.Background(), &internal.SessionOpts{
BuildOpts: internal.NewBuildOptsFromViper(),
HotReloadPort: viper.GetInt("hotreloadport"),
})

Expand All @@ -69,11 +64,11 @@ var devCMD = &cobra.Command{
Parser: &jsparse.JSFileParser{},
}

if viper.GetBool("terminateonstartup") {
if viper.GetBool("terminate_on_startup") {
return
}

devServer := internal.NewDevServer(reloader, logger, s, fileChangeOpts)
devServer := internal.NewDevServer(reloader, logger, devSession, fileChangeOpts)

go devServer.FileWatcherBundler(timeout, watcher)
go devServer.RedirectionBundler()
Expand Down Expand Up @@ -111,20 +106,16 @@ func init() {
var samefileTimeout int
var port int
var terminateStartup bool
var mode string

devCMD.PersistentFlags().IntVar(&timeoutDuration, "timeout", 500, "specifies the timeout duration in milliseconds until a change will be detected")
viper.BindPFlag("timeout", devCMD.PersistentFlags().Lookup("timeout"))

devCMD.PersistentFlags().IntVar(&samefileTimeout, "samefiletimeout", 500, "specifies the timeout duration in milliseconds until a change will be detected for repeating files")
viper.BindPFlag("samefiletimeout", devCMD.PersistentFlags().Lookup("samefiletimeout"))
devCMD.PersistentFlags().IntVar(&samefileTimeout, "same_file_timeout", 500, "specifies the timeout duration in milliseconds until a change will be detected for repeating files")
viper.BindPFlag("samefiletimeout", devCMD.PersistentFlags().Lookup("same_file_timeout"))

devCMD.PersistentFlags().IntVar(&port, "hotreloadport", 3005, "port used for hotreload")
viper.BindPFlag("hotreloadport", devCMD.PersistentFlags().Lookup("hotreloadport"))
devCMD.PersistentFlags().IntVar(&port, "hot_reload_port", 3005, "port used for hotreload")
viper.BindPFlag("hotreloadport", devCMD.PersistentFlags().Lookup("hot_reload_port"))

devCMD.PersistentFlags().BoolVar(&terminateStartup, "terminateonstartup", false, "flag used for terminating the dev command after startup")
viper.BindPFlag("terminateonstartup", devCMD.PersistentFlags().Lookup("terminateonstartup"))

devCMD.PersistentFlags().StringVar(&mode, "mode", "development", "specifies the underlying bundler mode to run in")
viper.BindPFlag("dev_bundle_mode", devCMD.PersistentFlags().Lookup("mode"))
devCMD.PersistentFlags().BoolVar(&terminateStartup, "terminate_on_startup", false, "flag used for terminating the dev command after startup")
viper.BindPFlag("terminate_on_startup", devCMD.PersistentFlags().Lookup("terminate_on_startup"))
}
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ var versionCMD = &cobra.Command{
Use: "version",
Short: "version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("version 0.21.0")
fmt.Println("version 0.21.1")
},
}
Binary file modified examples/basic-react/main
Binary file not shown.
Loading
Loading