Skip to content

Commit

Permalink
feat: upgrade to Node 14+ with full ICU support (#7)
Browse files Browse the repository at this point in the history
* feat: upgrade to Node 14+ with full ICU support

BREAKING CHANGES:
- This package now requires Node 14+ to work.
- Built using ES modules instead of CJS modules
  • Loading branch information
uglow authored Jul 7, 2021
1 parent d5f7a1e commit ba0e064
Show file tree
Hide file tree
Showing 23 changed files with 8,871 additions and 7,881 deletions.
6 changes: 0 additions & 6 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# START_CONFIT_GENERATED_CONTENT
# Common folders to ignore
node_modules/*
bower_components/*

# Config folder (optional - you might want to lint this...)
config/*

# END_CONFIT_GENERATED_CONTENT
47 changes: 47 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},

env: {
es6: true,
'jest/globals': true,
},

extends: [
'plugin:prettier/recommended',
'plugin:unicorn/recommended',
'plugin:node/recommended-script',
'plugin:jest/recommended',
],
plugins: ['jest'],
rules: {
// Allow some flexibility here
'unicorn/prevent-abbreviations': 'off',

// Use camelCase for files (and directories - not enforced)
'unicorn/filename-case': ['error', { case: 'camelCase' }],

// Turn off explicit length checks
'unicorn/explicit-length-check': 'off',

// Turning off because it leads to many uses of the word 'error' in the same block, which is confusing
// E.g.
// } catch(error) {
// logger.error(error);
// return error(error);
// }
'unicorn/catch-error-name': 'off',

// This rule is no good for test specs. Need to find a way to disable this for test specs
'unicorn/consistent-function-scoping': 'off',

// This rule is breaking at the moment due to ES module support lacking
'node/no-unsupported-features/es-syntax': 'off',

// Jest does not support the node:protocol, yet
'unicorn/prefer-node-protocol': 'off'
},
};
2 changes: 2 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install
run: npm ci
#- name: List Env vars
# run: env
- name: Test
run: npm run test:coverage
- name: Lint
Expand Down
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run pre-push
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/*.spec.js
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v14
24 changes: 0 additions & 24 deletions .nycrc

This file was deleted.

7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120,
"tabWidth": 2,
"semi": true
}
108 changes: 47 additions & 61 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,62 @@ Welcome! This document explains how you can contribute to making **devlog** even
```
git clone <this repo>
npm install -g commitizen
npm install -g semantic-release-cli
npx husky-init
npm install
```

# Testing

## Unit testing

Command | Description
:------ | :----------
<pre>npm test</pre> | Alias for `npm run test:unit` task
<pre>npm run test:unit</pre> | Run unit tests whenever JS source or tests change. Runs in watch mode.
<pre>npm run test:coverage</pre> | Run unit tests then verify coverage meets defined thresholds.

## Testing the CLI

The `bin/cli.js` file can be tested from the command line by typing `./bin/cli.js`, and passing
any arguments to the command (see [README.md](README.md) for the list of commands).

## Testing via `npm link`

1. Ensure you do not have a globally-installed `devlog` instance. (E.g. Typing `devlog` in your terminal shouldn't do anything)
1. From the devlog-repo-directory, run `npm link`
1. Verify that the command has been installed globally by:
1. Change to a different directory
1. Run `devlog`

```shell


## Directory Structure

Code is organised into modules which contain one-or-more components. This a great way to ensure maintainable code by encapsulation of behavior logic. A component is basically a self contained app usually in a single file or a folder with each concern as a file: style, template, specs, e2e, and component class. Here's how it looks:
```
devlog/
├──config/ * configuration files live here (e.g. eslint, verify, testUnit)
├──bin/ * source code files should be here
├──dist/ * production-build code should live here
├──reports/ * test reports appear here
├──test/ * unit test specifications live here
├──confit.yml * the project config file generated by 'yo confit'
├──CONTRIBUTING.md * how to contribute to the project
├──README.md * this file
└──package.json * NPM package description file
```


## Verification (Linting) Tasks

Command | Description
:------ | :----------
<pre>npm run lint</pre> | Lint code style and syntax (and fix errors that can be fixed)
<pre>npm run verify</pre> | Check code style and syntax

## Commit Tasks

Command | Description
:------ | :----------
<pre>git status</pre> | Lists the current branch and the status of changed files
<pre>git log</pre> | Displays the commit log (press Q to quit viewing)
<pre>git add .</pre> | Stages all modified & untracked files, ready to be committed
<pre>git cz</pre> | Commit changes to local repository using Commitizen<ul><li>Asks questions about the change to generate a valid conventional commit message</li><li>Can be customised by modifying [config/release/commitMessageConfig.js](config/release/commitMessageConfig.js)</li></ul>
<pre>git push</pre> | Push local repository changes to remote repository






# GitFlow Development Process

This project uses the [GitHub Flow](https://guides.github.com/introduction/flow/index.html) workflow.
Expand Down Expand Up @@ -92,46 +120,4 @@ Once merged, Pull Requests preserve a record of the historical changes to your c
By incorporating certain keywords into the text of your Pull Request, you can associate issues with code. When your Pull Request is merged, the related issues are also closed. For example, entering the phrase Closes #32 would close issue number 32 in the repository. For more information, check out our help article.


## Build Tasks

Command | Description
:------ | :----------
<pre>npm run build</pre> | Generate production build into [dist/](dist/) folder
<pre>npm run dev</pre> | Run project in development mode (verify code, and re-verify when code is changed)
<pre>npm start</pre> | Alias for `npm run dev` task


## Test Tasks

Command | Description
:------ | :----------
<pre>npm test</pre> | Alias for `npm run test:unit` task
<pre>npm run test:coverage</pre> | Run instrumented unit tests then verify coverage meets defined thresholds<ul><li>Returns non-zero exit code when coverage does not meet thresholds (as defined in istanbul.js)</li></ul>
<pre>npm run test:unit</pre> | Run unit tests whenever JS source or tests change<ul><li>Uses Mocha</li><li>Code coverage</li><li>Runs continuously (best to run in a separate window)</li></ul>
<pre>npm run test:unit:once</pre> | Run unit tests once<ul><li>Uses Mocha</li><li>Code coverage</li></ul>


## Verification (Linting) Tasks

Command | Description
:------ | :----------
<pre>npm run lint</pre> | Verify code style and syntax<ul><li>Verifies source *and test code* aginst customisable rules (unlike Webpack loaders)</li></ul>
<pre>npm run verify:js</pre> | Verify Javascript code style and syntax
<pre>npm run verify:js:fix</pre> | Verify Javascript code style and syntax and fix any errors that can be fixed automatically
<pre>npm run verify:js:watch</pre> | Verify Javascript code style and syntax and watch files for changes
<pre>npm run verify:watch</pre> | Runs verify task whenever JS or CSS code is changed


## Commit Tasks

Command | Description
:------ | :----------
<pre>git status</pre> | Lists the current branch and the status of changed files
<pre>git log</pre> | Displays the commit log (press Q to quit viewing)
<pre>git add .</pre> | Stages all modified & untracked files, ready to be committed
<pre>git cz</pre> | Commit changes to local repository using Commitizen<ul><li>Asks questions about the change to generate a valid conventional commit message</li><li>Can be customised by modifying [config/release/commitMessageConfig.js](config/release/commitMessageConfig.js)</li></ul>
<pre>git push</pre> | Push local repository changes to remote repository




14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ Log saved to /users/dknuth/devlog/devlog.md
```

## Troubleshooting

### The date-stamp is in the wrong format!

The current version of `devlog` requires Node 14+, which contains the full set of
Internationalisation Components for Unicode (ICU). However, it is possible to
install Node 14+ **without** Full ICU support. In this case, the default locale (en-US?)
is used by Node, even when `devlog` detects the operating system's actual locale.

To fix this, ensure you install Node 14+ **with full ICU support** (the default build).
Alternatively, you can try installing the [full-icu](https://www.npmjs.com/package/full-icu)
package (which has instructions for getting it working).


## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md).
Expand Down
7 changes: 7 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env node
import { DevLog } from '../src/devLog.js';
import { setLogLevel, LOG_LEVEL } from '../src/logger.js';

setLogLevel(LOG_LEVEL.INFO);
const devLog = new DevLog({ args: process.argv, cwd: process.cwd() });
devLog.run();
Loading

0 comments on commit ba0e064

Please sign in to comment.