This repository was archived by the owner on Oct 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
PLAT-13615: Remove cookiecutter from demo command #85
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3dfc7d9
PLAT-13615: use downloaded cache of the demo app
alaisgomes b1d7843
update: improved error handling; add option to get the source branch
alaisgomes 9db1bd4
Minor update: use local error parsing function for async dispatcher
alaisgomes e9a871c
Merge branch 'develop' into PLAT-13615
alaisgomes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,66 +1,29 @@ | ||
| import path from "path"; | ||
| import fs from "fs"; | ||
| import fse from "fs-extra"; | ||
| import { section, generateCommand } from "../utils.js"; | ||
| import { execSync } from "child_process"; | ||
| import { configurePython, execOptions } from "./utils/environment.js"; | ||
|
|
||
| const config = { | ||
| project_name: "demo", | ||
| project_slug: "demo", | ||
| project_generated_name: "demo", | ||
| owner_email: "demo@crowdbotics.com", | ||
| custom_domain: "demo.botics.co", | ||
| repo_url: "https://github.com/crowdbotics/modules", | ||
| heroku_dyno_size: "free", | ||
| is_mobile: "y" | ||
| }; | ||
|
|
||
| const extraContext = Object.entries(config) | ||
| .map((cur) => `${cur[0]}=${cur[1]}`) | ||
| .join(" "); | ||
| import { section } from "../utils.js"; | ||
| import fetch from "node-fetch"; | ||
| import config from "../config.js"; | ||
| import unzipper from "unzipper"; | ||
|
|
||
| async function downloadAndExtract(url, target) { | ||
| const rnResponse = await fetch(url); | ||
| if (rnResponse.ok && rnResponse.body) { | ||
| rnResponse.body.pipe(unzipper.Extract({ path: target })); | ||
| } else { | ||
| throw new Error("Failed to download scaffold for demo app."); | ||
| } | ||
| } | ||
|
|
||
| export function createDemo(dir) { | ||
| const options = Object.assign(execOptions, { | ||
| cwd: path.dirname(dir) | ||
| }); | ||
| export async function createDemo(dir, target = "master") { | ||
| const rnDemoUrl = `${config.constants.REACT_NATIVE_SCAFFOLD_REPO_ORIGIN}/raw/${target}/dist/react-native-demo.zip`; | ||
| const djangoDemoUrl = `${config.constants.DJANGO_SCAFFOLD_REPO_ORIGIN}/raw/${target}/dist/django-demo.zip`; | ||
|
|
||
| if (fs.existsSync(dir)) { | ||
| section("Removing previous demo app"); | ||
| fs.rmSync(dir, { recursive: true }); | ||
| } | ||
|
|
||
| section("Preparing environment"); | ||
| configurePython(); | ||
| execSync("pipenv install cookiecutter", options); | ||
|
|
||
| section("Generating React Native app from scaffold"); | ||
| const rnCookieCutterCommand = generateCommand([ | ||
| "pipenv run cookiecutter", | ||
| "gh:crowdbotics/react-native-scaffold", | ||
| "--directory dist/cookie", | ||
| "--checkout master", | ||
| "--no-input", | ||
| extraContext | ||
| ]); | ||
| execSync(rnCookieCutterCommand, options); | ||
|
|
||
| section("Installing dependencies"); | ||
| execSync("yarn install", { | ||
| cwd: dir, | ||
| encoding: "utf8", | ||
| stdio: "inherit" | ||
| }); | ||
|
|
||
| section("Generating Django app from scaffold"); | ||
| const djangoCookieCutterCommand = generateCommand([ | ||
| "pipenv run cookiecutter", | ||
| "gh:crowdbotics/django-scaffold", | ||
| "--checkout master", | ||
| `--output-dir ${path.basename(dir)}`, | ||
| "--no-input", | ||
| extraContext | ||
| ]); | ||
| execSync(djangoCookieCutterCommand, options); | ||
| fse.moveSync(path.join(dir, path.basename(dir)), path.join(dir, "backend")); | ||
| fs.mkdirSync(dir, { recursive: true }); | ||
| await downloadAndExtract(rnDemoUrl, dir); | ||
| await downloadAndExtract(djangoDemoUrl, path.join(dir, "backend")); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
nit: this won't have any side effects? I mean, if the
.pipefails somehow, we are not catching any exception and throwing the error to the User.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.
Thanks for the comment! Good point... The idea here is that these errors will bubble up to the main dispatch call and the error will be sent to sentry. That's why I also throw the error in the if/else instead of just showing an error message.
But I think we could improve it a bit since this makes the user see an unhandled async error message from Node. I made a small change in 9db1bd4 so that the error messages are routed to sentry and also "parsed". Improvements to the parsing function will probably require some product input, so I will leave it as is for now!