npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dm-tools

v0.7.8

Published

Dev Mentor Project Creator Tools

Downloads

115

Readme

Dev Mentor Project Creator Tool

Travis Version License Greenkeeper badge

Image Logo

  1. Dev Mentor Project Creator Tool
    1. Introduction
    2. Debugging
      1. VSCode debugging
      2. No IDE: Build and Debug like a Pro
    3. Installing DM-Tools
    4. Viewing Usage info
    5. Benefits
    6. Creating a Project
    7. Project Types
      1. NPM Scripts
    8. Running a Node.js program
    9. Running Tests
      1. Developing and watching
        1. Watching Tests
    10. TypeScript development
      1. Project structure
      2. Building
      3. Warning
      4. Library code (Modules)
      5. Formatting the code
      6. Linting
      7. Testing
    11. Static Web development
      1. Browsersync Asset fetching
    12. Test coverage
    13. Create a Node.js JavaScript project
      1. TypeScript Node ES5
    14. Building C++ Testable Projects
      1. Basic Usage
        1. Project "hello_world" Creation
      2. Building Project
      3. Running hello_world program
      4. Running the Test Program
      5. Micro Test - Testing Your Project
    15. TypeScript Coding Guideline
    16. Debugging

Introduction

DM-Tools is a command-line utility for generating a project for the following programming languages.

  1. TypeScript
  2. HTML, CSS, Sass
  3. 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 debug

This 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 debug

This 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.

Brave inspect

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. 🧙🏽‍♂️

browser debugger

NOTE: TypeScript file(s) will appear in the debugger windows, not transpiled JavaScript files. ❤️

Installing DM-Tools

npm install -g dm-tools

This will make the command "dm" available from the terminal.

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>  project types: koa, node, ts, web
  --e2e              end to end testing
  -w, --web          simple static Web setup
  --cpp [items]      C++ project
  -D, --debug        debug build
  --release          debug build
  -M, --make         Unix Makefile build
  --xcode            XCode Makefile
  --eclipse          Eclipse CDT4 Makefile
  -N, --nmake        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-tools

Benefits

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
  • ✅ Code coverage
  • ✅ Document generation
  • ✅ Git commit hooks

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 demo

Note: If you are using Yarn over NPM, continue to work with Yarn, the DM-Tools generated project will use Yarn before NPM if it is available 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) 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

NPM Scripts

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.

The following NPM commands are provided, some are project type dependent.

NPM script|Description ----------|----------- build|Perform a release build dev|Run in watch mode. debug|Debug and build watch mode. debug:node|Start debugger, requires Chrome. doc|Generate doc files (jsdocs). format|Format the source code. |lint|Run TypeScript / ES linter start|Run the Node.js program. test|Run Unit testing in watch mode test:coverage|Run Unit test with coverage test:e2e|End to end test with Cypress web|Run static web server

Running a Node.js program

To simply run a production build of the Node.js program, type:

npm start

This 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 test

It 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 dev

This 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 testwatch

TypeScript 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

Supported compiled targets include:

ES3, ES5, ES6, ES2016, ES2017, ES2018, ES2019, ES2020

See compiler options for more details.

Building

To compile the TypeScript code, use the following command to start the build process:

npm run release

Warning

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 lint

Note: 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 Ava, the test methods are simple and easy to learn.

Ava makes testing simple. Code is easy to read since it is just JavaScript, this avoids the need to context switch to BDD syntax. Plus anyone who knows JavaScript will be able to write test code immediately.

I firmly believe less time should be put into writing test code and having more time to write production code. Ava delivers on this by keeping the setup and test writing to a bare minimum. I believe Ava is the best option for writing unit test for JavaScript based code.

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 test

Note: 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 web

This 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 install

Note: 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 dev

TypeScript 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:

  1. Linux
  2. MacOS
  3. 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 --cpp

Building Project

The Makefile is located under sub-folder build.

cd hello_world/build
make

Running hello_world program

The executable hello_world will be found in the build folder.

./hello_world

Running 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_world

Micro 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 =)