Skip to content

Commit

Permalink
Updates to scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
jdslaugh committed Mar 27, 2024
1 parent 2585d35 commit 510359a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 26 deletions.
44 changes: 38 additions & 6 deletions tools/scaffolding/scaffolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,50 @@ func generateAPI(args *args, tmpFolder, dest string) {
}

func generateFrontend(args *args, tmpFolder, dest string) {
yarnInstallVersion := args.YarnPin
if len(yarnInstallVersion) == 0 {
yarnInstallVersion = "4.1.1"
}

// Update clutch.config.js for new workflow
log.Println("Compiling workflow, this may take a few minutes...")
yarn := determineYarnPath()
log.Println("cd", tmpFolder, "&&", yarn, "--immutable &&", yarn, "tsc && ", yarn, "compile")
log.Println("cd", tmpFolder, "&&", yarn, "install &&", yarn, "tsc && ", yarn, "compile")
if err := os.Chdir(tmpFolder); err != nil {
log.Fatal(err)
}

installCmd := exec.Command(yarn, "--immutable")
installCmd := exec.Command(yarn, "install")
if out, err := installCmd.CombinedOutput(); err != nil {
fmt.Println(string(out))
log.Fatal("`yarn --immutable` returned the above error")
log.Println("`yarn install` returned the above error")

yarnVersionCmd := exec.Command(yarn, "--version")
if out, err := yarnVersionCmd.CombinedOutput(); err != nil {
fmt.Println(string(out))
log.Fatal("`yarn --version` returned the above error")
} else if strings.TrimRight(string(out), "\n") != yarnInstallVersion {
log.Println("Yarn version is not equal to", yarnInstallVersion)
corepack := promptOrDefault("Would you like to attempt installation of Yarn via corepack?", "Y/n")
if !strings.HasPrefix(strings.ToLower(corepack), "y") {
log.Fatal("Corepack installation not granted, exiting")
} else {
corepackCmd := exec.Command("corepack", "enable")
if out, err := corepackCmd.CombinedOutput(); err != nil {
fmt.Println(string(out))
log.Fatal("`corepack enable` returned the above error. Please make sure you are on Node > 18")
}

corepackPrepareCmd := exec.Command("corepack", "prepare", "yarn@"+yarnInstallVersion, "--activate")
if out, err := corepackPrepareCmd.CombinedOutput(); err != nil {
fmt.Println(string(out))
log.Fatal("`corepack prepare", "yarn@"+yarnInstallVersion, "--activate` returned the above error. Please correct the error and attempt again.")
}
}
}
}

fmt.Println("Running yarn tsc in", tmpFolder, "with yarn path", yarn)
compileTypesCmd := exec.Command(yarn, "tsc")
if out, err := compileTypesCmd.CombinedOutput(); err != nil {
fmt.Println(string(out))
Expand All @@ -256,16 +286,18 @@ func generateFrontend(args *args, tmpFolder, dest string) {
}

type args struct {
Mode string
GoPin string
Org string
Mode string
GoPin string
Org string
YarnPin string
}

func parseArgs() *args {
f := &args{}
flag.StringVar(&f.Mode, "m", "gateway", "oneof gateway, workflow")
flag.StringVar(&f.GoPin, "p", "main", "sha or other github ref to version of tools used in scaffolding")
flag.StringVar(&f.Org, "o", "lyft", "overrides the github organization (for use in fork testing)")
flag.StringVar(&f.YarnPin, "y", "4.1.1", "version of yarn to use")
flag.Parse()
return f
}
Expand Down
12 changes: 6 additions & 6 deletions tools/scaffolding/templates/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
"scripts": {
"clean": "rm -rf ./dist && rm -f tsconfig.tsbuildinfo",
"compile": "tsc -b",
"compile:dev": "yarn workspace @clutch-sh/tools buildDev $INIT_CWD",
"compile:watch": "yarn compile:dev -w",
"compile:dev": "esbuild --target=es2019 --outdir=dist --sourcemap src/*.tsx",
"compile:watch": "yarn compile:dev --watch=forever",
"lint": "yarn run package:lint",
"lint:fix": "yarn run lint --fix",
"test": "yarn run package:test",
"test:coverage": "yarn run test --collect-coverage",
"test:watch": "yarn run test --watch"
},
"dependencies": {
"@clutch-sh/core": "^4.0.0-beta",
{{- if .IsWizardTemplate}}
"@clutch-sh/wizard": "workspace:^",
{{- else}}
"@clutch-sh/core": "workspace:^",
"@clutch-sh/wizard": "^4.0.0-beta",
{{- end}}
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand All @@ -36,10 +35,11 @@
"react-hook-form": "7.25.3"
},
"devDependencies": {
"@clutch-sh/tools": "workspace:^"
"@clutch-sh/tools": "^4.0.0-beta"
},
"engines": {
"node": ">=18 <19",
"yarn": "^4.1.1"
},
"packageManager": "[email protected]"
}
6 changes: 3 additions & 3 deletions tools/scaffolding/templates/gateway/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ MAKEFLAGS += --no-print-directory
PRIMARY_MODULE_DIR := $(shell cd backend && go list -f "{{ "{{" }} .Dir {{ "}}" }}" -m "github.com/lyft/clutch/backend")
TOOLS_MODULE_DIR := $(shell cd backend && go list -f "{{ "{{" }} .Dir {{ "}}" }}" -m "github.com/lyft/clutch/tools")
MY_ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
YARN:=yarn
YARN:=./build/bin/yarn.sh

.PHONY: all # Generate API, Frontend, and backend assets.
all: backend-tidy api frontend backend-with-assets
Expand Down Expand Up @@ -41,9 +41,9 @@ frontend: yarn-install
.PHONY: yarn-install
yarn-install: yarn-ensure
ifneq ("$(wildcard frontend/yarn.lock)","")
$(YARN) --cwd frontend install --immutable
cd frontend && $(YARN) install --immutable
else
$(YARN) --cwd frontend install
cd frontend && $(YARN) --cwd frontend install
endif

.PHONY: yarn-ensure
Expand Down
19 changes: 8 additions & 11 deletions tools/scaffolding/templates/gateway/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
"version": "0.0.0",
"scripts": {
"build": "yarn compile && yarn register-workflows && react-scripts build",
"buildStart": "DANGEROUSLY_DISABLE_HOST_CHECK=true GENERATE_SOURCEMAP=false FORCE_COLOR=true react-app-rewired start | cat",
"buildWatch": "WORKSPACES=\"$(yarn workspaces list --json)\" npm explore @clutch-sh/tools -- yarn run buildWatch compile:watch buildStart $INIT_CWD",
"clean": "rm -rf build",
"compile:dev": "yarn workspaces foreach -Ai run compile:dev",
"compile:watch": "yarn workspaces foreach -Aip -j unlimited run compile:watch",
"compile": "yarn workspaces foreach -Ai run compile",
"compile:watch": "yarn workspaces foreach -Aip -j unlimited run compile:watch",
"eject": "react-scripts eject",
"lint:fix": "eslint --ext .js,.jsx,.ts,.tsx src --fix && yarn run lint --fix",
"lint": "yarn register-workflows && eslint --ext .js,.jsx,.ts,.tsx src && yarn workspaces foreach -Ap -j unlimited --include 'workflows/*' run lint",
"register-workflows": "npm explore @clutch-sh/tools -- yarn run registerWorkflows $INIT_CWD/src clutch-dev.config.js",
"start": "yarn run clean && yarn run register-workflows && yarn run buildWatch",
"test:coverage": "yarn workspaces foreach -Ap -j unlimited --include 'workflows/*' run test:coverage",
"test:watch": "yarn workspaces foreach -Aip -j unlimited --include 'workflows/*' run test:watch",
"test": "yarn workspaces foreach -Ap -j unlimited --include 'workflows/*' run test",
"lint": "eslint --ext .js,.jsx,.ts,.tsx .",
"lint:fix": "yarn run lint --fix",
"register-workflows": "npm explore @clutch-sh/tools -- yarn registerWorkflows $PWD/src",
"start": "yarn clean && yarn compile:watch & yarn register-workflows && DANGEROUSLY_DISABLE_HOST_CHECK=true FORCE_COLOR=true react-scripts start | cat",
"test": "yarn workspaces foreach -Ap -j unlimited run test --silent",
"test:coverage": "yarn workspaces foreach -Ap -j unlimited run test:coverage --silent",
"test:watch": "yarn workspaces foreach -Aip -j unlimited run test:watch",
"upgrade": "yarn upgrade"
},
"dependencies": {
Expand Down

0 comments on commit 510359a

Please sign in to comment.