Skip to content

Console Script to Select Database + Template #67

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

Merged
merged 15 commits into from
Mar 12, 2019
Merged

Conversation

benloh
Copy link
Collaborator

@benloh benloh commented Mar 6, 2019

You can now select a database file, a corresponding template file, and start the server with one command:

./nc.js --dataset=projectname

Installing

There are some new packages, so:

  1. Checkout this branch
  2. cd netcreate/build
  3. npm run clean
  4. npm ci

The script won't run until these packages are installed.

Set up

The script expects your database file and template file to have the same name. And it expects to find them in the build/runtime folder.

Template files have been renamed from templatename.json to templatename.template.

So if you have some existing projects, e.g. tacitus, then you'll want to set up the build/runtime folder like this:

/build/runtime/tacitus.loki
/build/runtime/tacitus.template

Just copy the .loki and .json files (that you were using as a template) to the runtime folder and rename them.

To Run the Script

  1. cd netcreate/build
  2. ./nc.js --dataset=projectname (e.g. --dataset=tacitus)

This will set up the app to load the project called tacitus and start the server. You no longer need to type npm run dev.

NOTES

  • If the projectname does not exist, the system will create a new project and template with that name, cloning the _default.template template found in /build/app/assets/templates/_default.template.
  • If you have an existing projectname but it does not have a corresponding template, a new one will be created, again using the _default.template template found in /build/app/assets/templates/_default.template.
  • You can delete all the other templates in /build/app/assets/templates/ (or move them to the runtime folder as appropriate).
  • The npm run package script for Standalone Mode will use the last project you had run with the nc.js script. e.g. if you had run ./nc.js --dataset=tacitus then npm run package, the standalone files in the public folder will use the tacitus database and template.

@daveseah
Copy link
Collaborator

daveseah commented Mar 8, 2019

THINGS TO UPDATE

  • standalone-template.template was supposed to be standalone-template.json to match the standalone-db.json naming scheme.

COOL THINGS NOTICED

  • I like the way you put a "comments" section in the _default.template JSON file to have some in-file documentation!

CODE REVIEW-Y THINGS THAT DON'T NEED CHANGING

  • Discussion: Since you're using nc.js as a shell script, you can actually named it nc to shorten it. If the script is primarily meant to be directly invoked with node as in MEME (e.g. node meme.js through a package.json run scripting) then I leave the .js extension on. Is it worth removing the extension for the sake of saving a few more letters to type? (MAYBE)

  • Discussion: Thinking that nc.js could benefit from using Javascript's template literals instead of string arithmetic might look cleaner. They are even multi-line, and include newlines (I didn't realize this until just now)

  • Discussion: The comment in server-database.js that reads "Ideally we should use m_otions value, but in standlone mode, m_options might not be defined" is not very clear because it doesn't explain what you mean by "ideal" but implies this is a hack of some kind, and "standalone mode" implies that this is something that is happening in the static package. Since server-database.js isn't available in standalone mode, it took me a while to puzzle out what you meant...I think you mean "when this function is invoked from brunch-server.js to build the 'standalone' package, m_options is not defined"; I'll have to look more closely at this to see if this is true.

@daveseah
Copy link
Collaborator

I'm waiting for the correction of the template file naming before I accept this pull request, unless there is a good reason not to do so.

@benloh
Copy link
Collaborator Author

benloh commented Mar 12, 2019

@daveseah The standalone-template.template filename has been changed to standalone-template.json. Please review and accept.

@benloh benloh merged commit d04ceb5 into dev Mar 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants