-
Notifications
You must be signed in to change notification settings - Fork 63
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
Invert direction of dependency between @faststore/core and @faststore/cli #2377
Changes from 14 commits
5cfe1ea
c9dfaae
cbb18e0
fcdc4a6
c2d7ed7
5d10fa8
08da42d
b58abdf
436c990
84ee8cf
18645f9
c86b1e9
2c7f1f4
4d81118
4435bb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,11 @@ import { spawn } from 'child_process'; | |
import chokidar from 'chokidar'; | ||
import dotenv from 'dotenv'; | ||
|
||
import { readFileSync } from 'fs'; | ||
import { readFileSync, cpSync } from 'fs'; | ||
import path from 'path'; | ||
import { withBasePath } from '../utils/directory'; | ||
import { generate } from '../utils/generate'; | ||
import { runCommandSync } from '../utils/runCommandSync'; | ||
|
||
/** | ||
* Taken from toolbelt | ||
|
@@ -31,10 +32,21 @@ const defaultIgnored = [ | |
|
||
const devAbortController = new AbortController() | ||
|
||
async function storeDev(rootDir: string, tmpDir: string) { | ||
async function storeDev(rootDir: string, tmpDir: string, coreDir: string) { | ||
const envVars = dotenv.parse(readFileSync(path.join(rootDir, 'vtex.env'))) | ||
|
||
const devProcess = spawn('yarn dev', { | ||
runCommandSync({ | ||
cmd: 'yarn predev', | ||
errorMessage: | ||
'GraphQL was not optimized and TS files were not updated. Changes in the GraphQL layer did not take effect', | ||
throws: 'error', | ||
debug: true, | ||
cwd: tmpDir, | ||
}) | ||
|
||
copyGenerated(path.join(tmpDir, '@generated'), path.join(coreDir, '@generated')) | ||
|
||
const devProcess = spawn('yarn dev-only', { | ||
shell: true, | ||
cwd: tmpDir, | ||
signal: devAbortController.signal, | ||
|
@@ -50,6 +62,16 @@ async function storeDev(rootDir: string, tmpDir: string) { | |
}) | ||
} | ||
|
||
function copyGenerated(from: string, to: string) { | ||
try { | ||
cpSync(from, to, { recursive: true, force: true }) | ||
|
||
return { success: true } | ||
} catch (err) { | ||
return { success: false } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: an error to copy would abort the command run? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should not. But I believe you asked this question because the code is returning this and we're not using it anywhere else. I'll adjust the code to warn the user of the impact of the failure to copy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
} | ||
} | ||
|
||
export default class Dev extends Command { | ||
static args = [ | ||
{ | ||
|
@@ -62,7 +84,7 @@ export default class Dev extends Command { | |
const { args } = await this.parse(Dev) | ||
const basePath = args.path ?? process.cwd() | ||
|
||
const { getRoot, tmpDir } = withBasePath(basePath) | ||
const { getRoot, tmpDir, coreDir } = withBasePath(basePath) | ||
|
||
const queueChange = (/* path: string, remove: boolean */) => { | ||
generate({ basePath }) | ||
|
@@ -86,7 +108,7 @@ export default class Dev extends Command { | |
|
||
await generate({ setup: true, basePath }) | ||
|
||
storeDev(getRoot(), tmpDir) | ||
storeDev(getRoot(), tmpDir, coreDir) | ||
|
||
return await new Promise((resolve, reject) => { | ||
watcher | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,17 +13,19 @@ | |
"scripts": { | ||
"generate:schema": "tsx src/server/generator/generateGraphQLSchemaFile.ts", | ||
"generate:codegen": "graphql-codegen", | ||
"generate:copy-back": "copyfiles \"@generated/**/*\" $DESTINATION", | ||
"generate": "faststore generate-graphql -c -d", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I miss the -d (debug) flag. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I belive that the flag and better error messages are two different problems, but I'll add this back There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I linked these two topics because we previously saw the specific error messages when using the flag. |
||
"build": "yarn partytown & yarn generate && next build", | ||
"dev": "yarn partytown & yarn generate && next dev", | ||
"format:generated": "prettier --write \"@generated/**/*.{ts,js,tsx,jsx,json}\" --loglevel error", | ||
"generate": "yarn generate:schema && yarn generate:codegen && yarn format:generated", | ||
"prebuild": "yarn partytown && yarn generate", | ||
"build": "next build", | ||
"predev": "yarn partytown && yarn generate", | ||
"dev": "next dev", | ||
"dev-only": "next dev", | ||
Comment on lines
+21
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same? Why 2 scripts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey, I thought I had given you an answer here. Yes it's intentional and if we need to change something that should happen before the |
||
"clean": "rm -r .next", | ||
"serve": "next start", | ||
"test:e2e": "cypress open", | ||
"test": "jest", | ||
"lhci": "lhci autorun", | ||
"format": "prettier --write \"**/*.{ts,js,tsx,jsx,json}\"", | ||
"format:generated": "prettier --write \"@generated/**/*.{ts,js,tsx,jsx,json}\" --loglevel error", | ||
"lint": "next lint", | ||
"stylelint": "stylelint \"**/*.scss\"", | ||
"stylelint:fix": "stylelint \"**/*.scss\" --fix", | ||
|
@@ -60,7 +62,6 @@ | |
"@vtex/prettier-config": "1.0.0", | ||
"autoprefixer": "^10.4.0", | ||
"chalk": "^5.2.0", | ||
"copyfiles": "^2.4.1", | ||
"css-loader": "^6.7.1", | ||
"deepmerge": "^4.3.1", | ||
"draftjs-to-html": "^0.9.1", | ||
|
@@ -86,7 +87,6 @@ | |
"devDependencies": { | ||
"@cypress/code-coverage": "^3.12.1", | ||
"@envelop/testing": "^6.0.0", | ||
"@faststore/cli": "^3.0.83", | ||
"@faststore/eslint-config": "^3.0.68", | ||
"@faststore/lighthouse": "^1.12.32", | ||
"@lhci/cli": "^0.9.0", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: here other commands are run, right?
yarn generate:schema && yarn generate:codegen && yarn format:generated
not only theyarn generate:codegen
. What would happen if only theformat
returned error? It would fail but the previous commands would have made changes on the files?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but the changes are made to ephemeral files so, theoretically, no harm is done. Because of
throws: 'error'
here, the behavior is the same. Whatever step fails there will be no rollback.