dm-tools
v0.9.14
Published
Dev Mentor Project Creator Tools
Downloads
189
Maintainers
Readme
Dev Mentor Project Creator Tool

- Dev Mentor Project Creator Tool
- Summary of Commands
- Introduction
- Debugging
- Installing DM-Tools
- Viewing Usage info
- Benefits
- Creating a Project
- Project Types
- Running a Node.js program
- Running Tests
- TypeScript development
- Static Web development
- Test coverage
- Create a Node.js JavaScript project
- Building C++ Testable Projects
- TypeScript Coding Guideline
- Debugging
Summary of Commands
Jump to all commands with their usage and description.
Introduction
DM-Tools is a command-line utility for generating a project for the following programming languages.
- TypeScript
- HTML, CSS, Sass
- C++
Focus has been put into encouraging the use of best practices and the best tools.
Version of Node supported: Node v14.16.1+, for version earlier you will need to polyfill using "core-js".
Debugging
Both No IDE browser debugger and VSCode debugger support is provided.
VSCode debugging
Make sure project is open in VSCode. To get started open a terminal and type:
npn run debugThis will start a debug build for TypeScript files in development build mode then run it using Node.js and immediately break. JavaScript program will run immediately and break.
From VSCode press "F5" to run the debugger, it will attached to the started Node.js program in break mode. Step through the code or pressed "F5" to continue executing the program.
Set breakpoints 🎯 and step through code like a debugging pro. 😎
Feel free to edit make code edit, this will cause a rebuild on file save. You will need to re-start the debugger and press "F5" after a new build.
No IDE: Build and Debug like a Pro
You can easily run and debug any TypeScript, JavaScript, Node.js program with ease. You do not need and IDE to debug! 💪🏽 All you need is a terminal and a browser and you can step through any code.
It is even possible to debug remotely, for more information, read the Node Debugging Guide.
To get started open a terminal and type:
npm run debugThis will start a debug build for TypeScript files in development build mode then run it using Node.js and immediately break. JavaScript program will run immediately and break.
Next open a browser.
Browser | Debug URL
-|-
Brave| brave://inspect
Chrome| chrome://inspect
Edge|edge://inspect
Look for an "Open dedicated DevTools for Node" or "inspect" link.

Clicking on either link will popup a browser debug window. You are good to go. ✅
Set breakpoints 🎯 and step through code like a debugging Wizard. 🧙🏽♂️

NOTE: TypeScript file(s) will appear in the debugger windows, not transpiled JavaScript files. ❤️
Installing DM-Tools
npm install -g dm-toolsThis will make the command "dm" available from the terminal.
Setup the Editor
On Linux you can set the 'EDITOR' environment variable to point to the location of the source code editor of your choice. It will open up under the root directory of the project just created.
Determine the location of your IDE (vscode or vscode-insider).
Add something like the following to your Bash configuation file: "~/.bashrc".
export EDITOR="/usr/local/bin/code-insiders"Viewing Usage info
Use the "-h" or "--help" option to view help on usage.
$ dm -h
Usage: dm <command> <project> [options...]
commands: new
Options:
-v, --version Show current version
-t, --type <type> Node.js project types: koa, node, pg, ts, web
--e2e end to end testing
-w, --web simple static Web setup
--cpp [items] C++ project
-D, --debug C++ debug build
--release C++ release build
-M, --make C++ Unix Makefile build
--xcode C++ XCode Makefile
--eclipse C++ Eclipse CDT4 Makefile
-N, --nmake C++ Window NMak Makefile
-h, --help display help for command
Dev Mentor DM-Tools
Create C++, TypeScript and JavaScript projects.
Website: https://www.npmjs.com/package/dm-toolsBenefits
Here are the benefits you will enjoy right out of the gate:
- ✅ Quick start
- ✅ Best practices
- ✅ Build system
- ✅ Code in TypeScript
- ✅ Easy no IDE debugging
- ✅ HTML, CSS & Sass live edit and preview
- ✅ Error logging
- ✅ Code linting
- ✅ Code formatting
- ✅ Unit testing
- ✅ Functional testing
- ✅ Code coverage
- ✅ Document generation
Creating a Project
Start playing with the demo starter project now, the generated source code is located in the project "src/" sub-folder.
dm new demo
cd demoNote: If you are using DM-Tools generated project will use pnpm, yarn, npm in this order, if any are installed on your system.
Project Types
To create a specific started project type, use the following syntax:
dm new <project-name> -t <type>The following basic project types that can be created using DM-Tools are:
NOTE: Default project type is "ts" if not type passed.
Type|Language|Description -|-|- ts|TS|TypeScript Express.js Server (Zero compile with static Website) pg|TS|TypeScript PostgreSQL Express.js Server. web|HTML Sass |Static Website. node|TS|TypeScript Node.js Server. koa|TS|Koa Node.js API Server in TypeScript. cpp|CPP |C++ with Micro Test using CMake.
Commands
The following NPM commands you will be using with your project are:
NPM Scripts|Description -|- dev|Development build and watch mode. debug|Start a debug session, attach to process (usually press F5). test|Run Unit test. test:coverage|Run Unit test with coverage. test:watch|Run Unit test in watch mode. test:e2e|End to end test with Playright. web|Start static web server. Play with HTML, CSS. build|Build the project for production. release|Build the project for production. start|Run built Node.js program. check|Perfrom TypeScript typechecking. lint|Lint the source code. format|Format the source code. doc|Generate doc files (jsdocs).
IMPORTANT: Since gazeall is being used to watch and rebuild file, do not call other NPM script from it with watch-mode enabled. This can result in execution problems and the build entering a cycle of repeated rebuilds.
Running a Node.js program
To simply run a production build of the Node.js program, type:
npm startThis will perform a clean build and run the demo program from the "build/" folder. The demo application log will be produced in the "logs/" sub-folder under the project root.
Running Tests
To run tests with coverage for the TypeScript / Node.js based programs, type:
npm testIt might be a good idea to run all the tests with coverage before a production build.
Developing and watching
You can run and watch a Node.js based program during development. To do this, open a terminal and type the following.
npm run devThis will kickoff the "dev build" and "dev watch" NPM scripts.
Watching Tests
To watch the unit tests while developing, type the following command in a new terminal.
npm run testwatchTypeScript development
Project structure
Place all TypeScript source code under the folder, "src/", they will be picked up from here and compiled to the, "build/" folder under the project root.
You are free to create addition folders and sub-folders under, "src/", the compiler will recursively find and compile all TypeScript code.
All TypeScript code is compiled to ES2020 JavaScript. The target JavaScript code can be changed from the TypeScript configuration file, "tsconfig.json".
Some of the things you may want to configure:
- Files to compile
- Folders to include
- Folders to exclude
- Target compiled output
- Source map (Needed for debugging)
- Module system (Use commonjs for Node)
- Output file
Some of the supported compiled targets include:
ES2016, ES2017, ES2018, ES2019, ES2020, ES2021, ES2022, ESNextSee compiler options for more details.
Building
To compile the TypeScript code, use the following command to start the build process:
npm run releaseWarning
The "build/" folder and all sub-folders within it will be deleted to insure a clean build is performed each time. Do not place any files you will need later in the "build/" folder.
Library code (Modules)
Place any module or library source code that you write under the, "src/lib/", sub-folder. The compiled source code will be output to the, "build/lib/", sub-folder.
Formatting the code
The source code will be automatically formatted during development and production build. This will also happen before source code is committed to Git.
It is good practice to format the source code, so it conforms to a uniform structure. Avoid squabbles about style. Formatting in run by the NPM script, "format".
Linting
To validate the project TypeScript source code, use the following command:
npm run lintNote: The TypeScript source code is run through a linter (ESLint) before a build and before it is committed to the Git repository. Any errors encountered must be fixed before the Git commit is allowed to proceed.
Important!: I have noticed, once in a while the git hooks will continue to fail when there is nothing really wrong. If you suspect this is the case, the easy fix is to delete the "node_modules" folder. Follow this with a "npm install" or simply type "yarn" and then try to commit or push the code again.
Testing
Testing is done using Jest, the test methods are simple and easy to learn.
The test code should be co-located with the production source code. As a best practice, place tests under a sub-folder called "test/".
Pay attention to how the test source file is named: "test.<file>.ts". So if you have a file called, "filter.ts", the test file should be named, "test.filter.ts".
To run the test, type:
npm testNote: Running the test will cause a fresh build to be kicked-off. Once the build finishes, all the unit tests will be run.
Static Web development
If you want to hack around with HTML, Sass and try things out quick. Start the project in web mode using the following command:
npm run webThis will run the build first and then open a web browser on port 3000, and load the HTML page, "index.html" located in the "src/" sub-folder.
Any changes made to "index.html" will automatically update and browser on save. You do not need to keep hitting refresh on the browser.
The website uses lite-server, which is based on Browsersync to run a local development web-server and keeps all browsers listening to it in sync. This means it is possible to have multiple browsers listening to the server.
On how to configure the setup, read the Browsersync options.
Basic configurations setting you may be interested in are:
- files
- server
- proxy
- logLevel
- port
The default Browsersync UI web address is: http://localhost:3001/.
Browsersync Asset fetching
With Browsersync, having to serve addition CSS and JavaScript files, make sure to add their path in routes. Something similar to like this:
"server": {
baseDir: "src",
routes: {
"/node_modules/tachyons/css":"node_modules/tachyons/css"
}
},This will allow including "<script>" assets from the index.html file like this:
<head>
<link rel="stylesheet" href="./node_modules/tachyons/css/tachyons.min.css">
</head>Test coverage
Test coverage is done when test is run using "nyc". The test coverage result is displayed to the console after the results of the unit tests. A folder called "coverage/" will be created under the project root. It will hold the results of the code coverage from the test run. Of interest to you will be the HTML report. It is a nice way to see what code was covered and what code was not by the unit tests.
To configure the test coverage, make changes to the "nyc" settings found in the file "package.json".
Create a Node.js JavaScript project
If you want to develop in plain JavaScript, or develop a ES6 Node.js based project, this is now supported. It is also good for quickly testing out code and not getting slowed down by the compile step.
You will need the latest version of Node.js for ES6 and beyond support, otherwise plain JavaScript will continue to work.
dm new demo --type js
npm installNote: You may also use "-t" which is the short-form for "--type".
The plain JavaScript generated file has a development mode. It will run the Entry file ("main.js") using Node.js each time the source code is updated. You can develop and see the output from the terminal to test out code quickly.
npm run devTypeScript Node ES5
If you need to use ES5 Node.js support with TypeScript here are the following change you need to make.
Make sure you're using Node v14.16.1 or higher.
Add the following two lines under compilerOptions to "tsconfig.json" and "tsconfig.test.json".
"compilerOptions": {
"target": "es2020",
"lib": [
"es2020",
"es2019",
"es2018",
"es2017",
"dom"
]
}Building C++ Testable Projects
DM-Tools can be used to create a C++ project with Unit Testing setup using Micro Test.
The C++ project uses CMake to generate cross-platform Makefiles for:
- Linux
- MacOS
- Windows
Basic Usage
Let us go through the steps of creating a simple "hello_world" project.
Project "hello_world" Creation
The created project will be found under the hello_world folder.
cd /tmp
dm new hello_world --cppBuilding Project
The Makefile is located under sub-folder build.
cd hello_world/build
makeRunning hello_world program
The executable hello_world will be found in the build folder.
./hello_worldRunning the Test Program
The test program is located under build/test/ sub-folder. Initially one failing test is created for you to follow.
./test/test.hello_worldMicro Test - Testing Your Project
DM-Tools creates a test sub-folder under src/ and uses the latest Micro Test header file, it basically pulls it from the Micro Test Git repository.
To learn more about how to write tests using Micro Test check out the project site. You will be amazed how simple and fast it is to write test code.
TypeScript Coding Guideline
Read the coding guideline found in the wiki.
Debugging
If you get a post or address is use, you might have a background process that didn't shutdown correctly. To shut it down, use the following command to find its process ID and then kill it.
lsof -i :PORT
lsof -i :3000
kill <PIDP>
kill -9 <PIDP>Happy Hacking =)
