-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat(scaffolder): add scaffolder command #277
base: main
Are you sure you want to change the base?
Conversation
@tavsec we'll get to trying this out soon! |
src/commands/scaffold.ts
Outdated
{ | ||
connection_uri: connectionString, | ||
connection_parameters: { | ||
database: projectData.project.name, |
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.
The project name is not the database name, project names could have spaces and emoji etc. I guess you could try to parse out the path from the URL but there might be a better way.
👋🏼 this is very cool. here's some feedback i wrote up: I ended up with an
I like how it creates the
Part of this issue will be fixed when we allow free users more than 1 project but I don't think it should create a new project automatically. Would be better to ask if I want to reuse a project or at least list out the project names and ids along with the parameter so i could choose 1 without jumping to the console. I ended up going into the console, finding the project id and then running |
…database#297) Move action repo from personal account to org, and bump to last version.
Hey @clarkbw thank you so much for taking the time and reviewing this PR, and also sorry for the late response from my side. Regarding the first point ( As for the second point (error handling and project selection), I will update the code with better validation and error handling (check if project exists, check if enough parameters has been passed, ...), and change the behavior in case that no arguments have been passed (ask the user if he wants to reuse the project or create new one). Thanks again, will push the updates soon 😃 |
that sounds like a good pattern to me. |
@clarkbw In the latest commit, I added the following:
|
@tavsec since the UX/DevEx is now addressed, we'll do a code review soon |
There is nothing left logic-wise, mostly just the tasks on the list you posted |
package.json
Outdated
@@ -58,13 +59,17 @@ | |||
"@segment/analytics-node": "^1.0.0-beta.26", | |||
"axios": "^1.4.0", | |||
"axios-debug-log": "^1.0.0", | |||
"buffer": "^6.0.3", |
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.
Where is this dependency being used in?
src/utils/github.ts
Outdated
|
||
const MULTITHREADING_LIMIT = 10; | ||
|
||
export async function getContent(owner: string, repository: string) { |
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: can we use an object to pass the params instead of 2 string
args? It just makes it a bit less error-prone:
e.g.
export async function getContent({owner, repository}: {owner: string, repository: string}) {
...
}
src/commands/scaffold.ts
Outdated
|
||
const GENERATED_FOLDER_PREFIX = 'neon-'; | ||
|
||
// TODO: Maybe move to constants file? |
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.
Let's remove the TODO
, colocation is more than fine here 👍
src/commands/scaffold.ts
Outdated
'List available templates', | ||
(yargs) => yargs, | ||
async (args) => { | ||
// @ts-expect-error: TODO - Assert `args` is `CommonProps` |
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.
Let's make use of the yargs.Argv
generic and remove this comment:
e.g.
export const builder = (argv: yargs.Argv<CommonProps>) => {
'aws-eu-central-1', | ||
'aws-us-east-2', | ||
'aws-us-east-1', | ||
]; |
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.
Should we also include Azure regions by now? cc @davidgomes
src/commands/scaffold.ts
Outdated
|
||
if (!availableTemplates.includes(props.templateId)) { | ||
log.error( | ||
'Template not found. Please make sure the template exists and is public.', |
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: let's add the templateID
to this error message, should be easier to follow up from a user perspective
await getFileContent( | ||
REPOSITORY_OWNER, | ||
REPOSITORY, | ||
(props.templateId as string) + '/config.neon.json', |
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.
What's this '/config.neon.json'
for? If it's relevant, let's extract it into it's own const
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.
The file config.neon.json
is part of every "template" project and includes which files should be templated, copied and/or deleted in the scaffolding process. Example of such file: https://github.com/neon-scaffolder/templates/blob/main/astro/config.neon.json .
I'm not entirely sure what you mean by extracting it into it's own const
. Currently, it is extracted into its own variable config
, but I cannot change it to const
, as it is assigned in the try-catch
block.
src/commands/scaffold.ts
Outdated
props.templateId, | ||
dir, | ||
); | ||
} else { |
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.
If this a possible code path? seems like we are returning early in line 250 if the templateID doesn't exist?
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, you are right, this is dead code branch. Removed it.
src/utils/github.ts
Outdated
import path from 'path'; | ||
import fs from 'fs'; | ||
|
||
const MULTITHREADING_LIMIT = 10; |
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: can we rename this to CONCURRENT_OPERATIONS_LIMIT
? The current name is clear, but it's not threads
that we are referring here
src/utils/github.ts
Outdated
'/' + | ||
repository + | ||
'/main/' + | ||
path; |
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.
Can we extract this into a util function that builds the URL? Since it's used in multiple place
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.
Extracted into own util function 👍
@pffigueiredo Thanks for the review! I pushed some changes/fixes, feel free to review again :) |
neonctl scaffold
This PR will add
scaffold
command to theneonctl
tool. This command consists of two subcommandslist
andstart
.list
The
list
subcommand will list all of the available templates from templates repository, and display the via the default output. It utilises GitHub API to list the folders from the repository.Note
The "template" repository has to be created and populated before this functionality can be tested. For development purposes, I created temporary repository https://github.com/neon-scaffolder/templates
start <template-name>
This subcommand will initialize the scaffolding process. If the
project-id
flag is set, then the newly scaffolded directory will be templated using the data from the given project. Otherwise, new Neon project will be created. This subcommand accepts the same flags asneonctl projects create
.Templating
One of the biggest functionality that this commands provide is for community users to declare their own scaffolding templates, that can be used and selected by end users. This is done by using [mustache.js] (https://github.com/janl/mustache.js) templating engine. Available templating variables are
project
API object, andconnection
strings, but this can be extended if needed.TODO: