Skip to content

Commit

Permalink
fix(cli): Create functions/.env with Store ID from config.json on f…
Browse files Browse the repository at this point in the history
…irst dev command
  • Loading branch information
leomp12 committed Jul 24, 2023
1 parent 7383674 commit 17bf92b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/cli/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { join as joinPath } from 'node:path';
import { $, fs } from 'zx';

const copyFunctionsConfig = async () => {
const copyFunctionsConfig = async (isDev = false) => {
const functionsDir = joinPath(process.cwd(), 'functions');
if (isDev && !fs.existsSync(joinPath(functionsDir, '.env'))) {
try {
const { storeId } = JSON.parse(
fs.readFileSync(joinPath(functionsDir, 'config.json'), 'utf8'),
);
await fs.writeFile(joinPath(functionsDir, '.env'), `ECOM_STORE_ID=${storeId}\n`);
} catch {
//
}
}
const filesToCopy = ['.env', 'config.json', 'ssr/content/settings.json'];
const dirents = await fs.readdir(functionsDir, { withFileTypes: true });
for (let i = 0; i < dirents.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Finish by saving the following secrets to your GitHub repository:
}

if (argv._.includes('dev') || !argv._.length) {
await prepareCodebases();
await prepareCodebases(true);
return $`npm --prefix "${path.join(pwd, 'functions/ssr')}" run dev`;
}
return $`echo 'Hello from @cloudcommerce/cli'`;
Expand Down

0 comments on commit 17bf92b

Please sign in to comment.