Giter Site home page Giter Site logo

create-backend's Introduction

Join our Discord to discuss our software!

@heusalagroup/create-backend

A command-line tool to easily create NodeJS REST backend projects with TypeScript in the style inspired by Java Spring Boot. For more information on our style of NodeJS backends, check out HG.fi.

Usage

To create a minimal backend project, run either of the following commands:

npm init @heusalagroup/backend ./foo-backend

...or..

npm install -g @heusalagroup/create-backend
create-backend ./foo-backend

This command also accepts any argument from the npm init command. For example, you can call it with --yes to answer "yes" to every question:

create-backend ./foo-backend --yes

To increase the log level for debugging, set the LOG_LEVEL environment variable:

LOG_LEVEL=DEBUG npm init @heusalagroup/backend ./foo-backend

Development

Fetching source code

To get started with development, clone the repository locally and install the git submodules:

git clone [email protected]:heusalagroup/create-backend.git create-backend
cd create-backend
git submodule update --init --recursive

Listing state of git modules

To see the state of the git modules, run this command:

./scripts/get-all-branches.sh

If you see states like this, run the set-branch-main.sh script:

$ ./scripts/get-all-branches.sh 
main    .
(HEAD detached at 34566e9)      src/fi/hg/core
(HEAD detached at 898988b)      src/fi/hg/create

When everything is correct, you should see this:

$ ./scripts/get-all-branches.sh 
main    .
main    src/fi/hg/core
main    src/fi/hg/create

Unless you want to use a different branch, of course.

Changing all git modules to the main branch

To switch all git modules to main, run this script:

./scripts/set-branch-main.sh

Updating git modules to the latest version

To update all git modules to the latest version, run this script:

./scripts/pull-all.sh

Building the project

This script will build a standalone version of the project and output it to ./dist/create-backend.js. It will be zero dep after that, meaning that only Node.js is required to run it, along with ./create.config.json and the files in ./templates.

npm run build

Testing locally

You can install your own locally changed version globally:

npm install -g .

Then use it to kickstart a backend project:

create-backend ./foo-backend

Development with GitHub Using SSH

To use SSH when working with submodules in this repository, you will need to configure your Git settings as follows:

git config --global url."[email protected]:heusalagroup/".insteadOf "https://github.com/heusalagroup/"

This configuration is necessary because the repository uses HTTPS links for read-only access. However, you may prefer to use SSH when pushing and pulling changes.

License

Copyright (c) 2022 Heusala Group. All rights reserved. Licensed under the MIT License (the "License").

create-backend's People

Contributors

thejhh avatar

Watchers

 avatar  avatar

create-backend's Issues

Error: Could not resolve './fi/hg/core/RequestServer'

[!] Error: Could not resolve './fi/hg/core/RequestServer' from src/main.ts
Error: Could not resolve './fi/hg/core/RequestServer' from src/main.ts
    at error (/Users/jhh/tmp/foo-backend/node_modules/rollup/dist/shared/rollup.js:198:30)
    at ModuleLoader.handleResolveId (/Users/jhh/tmp/foo-backend/node_modules/rollup/dist/shared/rollup.js:22287:24)
    at /Users/jhh/tmp/foo-backend/node_modules/rollup/dist/shared/rollup.js:22250:26

RollupError: Node tried to load your configuration file as CommonJS even though it is likely an ES module.

(node:61485) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
[!] RollupError: Node tried to load your configuration file as CommonJS even though it is likely an ES module. To resolve this, change the extension of your configuration to ".mjs", set "type": "module" in your package.json file or pass the "--bundleConfigAsCjs" flag.

Original error: Cannot use import statement outside a module
https://rollupjs.org/guide/en/#--bundleconfigascjs

It seems that the installer is selecting rollup from version 3, when we currently relay on version 2.79.1.

Workaround for this is to change the rollup to use version 2.79.1 or newer before version 3.

Rollup dependency resolution error on installation

The following dependency resolution error was encountered while trying to checkout and install the backend and subsequent calls to npm run build fail due to rollup not being installed:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @rollup/[email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/rollup
npm ERR!   rollup@"*" from the root project
npm ERR!   peerOptional rollup@"^1.20.0||^2.0.0||^3.0.0" from @rollup/[email protected]
npm ERR!   node_modules/@rollup/plugin-babel
npm ERR!     @rollup/plugin-babel@"*" from the root project
npm ERR!   5 more (@rollup/plugin-inject, @rollup/plugin-json, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional rollup@"^2.68.0||^3.0.0" from @rollup/[email protected]
npm ERR! node_modules/@rollup/plugin-commonjs
npm ERR!   @rollup/plugin-commonjs@"*" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/rollup
npm ERR!   peerOptional rollup@"^2.68.0||^3.0.0" from @rollup/[email protected]
npm ERR!   node_modules/@rollup/plugin-commonjs
npm ERR!     @rollup/plugin-commonjs@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Environment:

OS: MacOS Monterey
Node: 18.9.0
NPM: 9.2.0

TypeError: n.replaceAll is not a function

TypeError: n.replaceAll is not a function
    at /Users/jhh/git/heusalagroup/create-backend/dist/create-backend.js:456:100
    at Array.forEach (<anonymous>)
    at Function.copyTextFileWithReplacements (/Users/jhh/git/heusalagroup/create-backend/dist/create-backend.js:456:73)
    at Function.copyTextFileWithReplacementsIfMissing (/Users/jhh/git/heusalagroup/create-backend/dist/create-backend.js:458:39)
    at /Users/jhh/git/heusalagroup/create-backend/dist/create-backend.js:917:64
    at Array.forEach (<anonymous>)
    at /Users/jhh/git/heusalagroup/create-backend/dist/create-backend.js:917:24
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
$ node --version
v14.20.1

Check for newer dependencies

Project warns about vulnerabilities.

2 high severity vulnerabilities
  1. We relay on some quite old tools (like uglifyjs), since newer ones didn't do all the tricks for transpiling and minimizing the source code. Newer tools should support for example removing blocks like if (false) {{ ... }}.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.