Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/node-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 'dhis2-node lint'

on: push

jobs:
check:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12.x

- name: Install
run: yarn install --frozen-lockfile

- name: Run linters
run: |
npx d2-style js check
npx d2-style text check
env:
CI: true
47 changes: 47 additions & 0 deletions .github/workflows/node-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: 'dhis2-node publish'

on:
push:
branches:
# match branches in:
# https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#branches
- master
- next
- next-major
- alpha
- beta
- '[0-9]+.x'
- '[0-9]+.x.x'
- '[0-9]+.[0-9]+.x'

env:
GIT_AUTHOR_NAME: '@dhis2-bot'
GIT_AUTHOR_EMAIL: 'apps@dhis2.org'
GIT_COMMITTER_NAME: '@dhis2-bot'
GIT_COMMITTER_EMAIL: 'apps@dhis2.org'
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
GH_TOKEN: ${{secrets.GH_TOKEN}}

jobs:
publish:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12.x

- name: Install
run: yarn install --frozen-lockfile

- name: Smoke
run: ./packages/main/bin/d2 debug system

- name: Test
run: yarn test

- name: Publish to NPM
run: npx @dhis2/cli-utils release --publish npm
env:
CI: true
21 changes: 21 additions & 0 deletions .github/workflows/node-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'dhis2-node test'

on: push

jobs:
unit:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12.x

- name: Install
run: yarn install --frozen-lockfile

- name: Test
run: yarn test
env:
CI: true
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- - - `d2 create app`
- - [`d2 style`↗️](https://cli-style.dhis2.nu ':ignore')
- - `d2 utils`
- - [`d2 utils release`](commands/d2-utils-release)
- - - [`d2 utils docsite`↗️](https://cli-utils-docsite.dhis2.nu ':ignore')
-  
- [Changelog](CHANGELOG)
30 changes: 30 additions & 0 deletions docs/commands/d2-utils-release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Introduction

`d2 utils release` allows you to publish libraries and applications to
various package repositories.

# Usage

Internally the `release` command utilizes [semantic
release](https://github.com/semantic-release/semantic-release), so
understanding how that tool operates is helpful.

Simply put, every time a commit appears on the `master` branch, the
fully automated release process begins, and the commit is released.

# Advanced usage

## Distribution channels

We support the default channels recommended by semantic release, and
there is a [good
walkthrough](https://github.com/semantic-release/semantic-release/blob/master/docs/recipes/distribution-channels.md)
of them available on their docs.

Our [GH Actions
workflow](https://github.com/dhis2/workflows/blob/master/ci/node-publish.yml#L5)
is kept in sync with those defaults.

It is possible to e.g. only use the `master` branch for releases by
restricting the `on.push.branches` list in the workflow file in the
local repo.
16 changes: 15 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# fo
# Install the CLI

```
yarn global add @dhis2/cli

# or

npm install --global @dhis2/cli
```

# Verify that it is available on PATH

```
d2 --version
```
2 changes: 0 additions & 2 deletions packages/app/src/commands/i18n/modernize.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
* --log-missing-keys
*/
const path = require('path')
const fs = require('fs')
const chalk = require('chalk')
Comment on lines -14 to -15
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint rule: no unused


const { reporter } = require('@dhis2/cli-helpers-engine')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const createNewTranslationFiles = ({
appendToExistingFiles,
}) => {
for (const language in translations) {
if (translations.hasOwnProperty(language)) {
if (Object.prototype.hasOwnProperty.call(translations, language)) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint rule: no access to prototype built-ins

if (
languagesToTransform.length &&
languagesToTransform.indexOf(language) === -1
Expand Down Expand Up @@ -88,7 +88,12 @@ const createNewTranslationFiles = ({
}

for (const key in languageTranslations) {
if (languageTranslations.hasOwnProperty(key)) {
if (
Object.prototype.hasOwnProperty.call(
languageTranslations,
key
)
) {
if (!translations[primaryLanguage][key]) {
logMissingKeys &&
reporter.info(
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/helpers/modernize/deleteLegacyFiles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require('fs')

const { reporter } = require('@dhis2/cli-helpers-engine')

/**
Expand All @@ -16,7 +17,7 @@ const deleteLegacyFiles = ({ translationFiles, languagesToTransform }) => {
languagesToTransform.indexOf(language) !== -1
) {
try {
const filePathToDelete = path.join(inDir, file)
const filePathToDelete = file
Comment on lines -19 to +20
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint rule: no undefined variables

fs.unlinkSync(filePathToDelete)
reporter.debug(`Deleted old file:`)
reporter.debug(`"${filePathToDelete}"`)
Expand Down
2 changes: 1 addition & 1 deletion packages/cluster/src/commands/db_cmds/restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const run = async function(argv) {
process.exit(1)
}

const rest = await tryCatchAsync(
const res = await tryCatchAsync(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint rule: no unused variables

Also a bug where res is accessed later, but the variable is named rest.

'db::restore',
restore({
cacheLocation,
Expand Down
20 changes: 8 additions & 12 deletions packages/cluster/src/commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,17 @@ const run = async function(argv) {
await Promise.all(
clusters.map(async cluster => {
const status = await getStatus(cluster)
cluster.status = formatStatus(status)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint rule: possible race condition (mutating source while looping)

table.push([
chalk.blue(cluster.name),
cluster.port,
cluster.channel,
cluster.dhis2Version,
cluster.dbVersion,
formatStatus(status),
])
})
)

clusters.forEach(cluster =>
table.push([
chalk.blue(cluster.name),
cluster.port,
cluster.channel,
cluster.dhis2Version,
cluster.dbVersion,
cluster.status,
])
)

reporter.print(table)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/cluster/src/helpers/db/restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const downloadDatabase = async ({ cache, dbVersion, update, url }) => {
}
}

const restoreFromFile = async ({ cacheLocation, dbFile, dbVersion, name }) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint rule: no unused variables

const restoreFromFile = async ({ cacheLocation, dbFile, name }) => {
reporter.info(`Restoring database (this may take some time)...`)
reporter.debug(`Restoring from database dump ${chalk.bold(dbFile)}`)

Expand Down Expand Up @@ -63,5 +63,5 @@ module.exports = async ({
update,
})

await restoreFromFile({ cacheLocation, dbFile, dbVersion, name })
await restoreFromFile({ cacheLocation, dbFile, name })
}
2 changes: 1 addition & 1 deletion packages/create/src/builders/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { reporter, chalk } = require('@dhis2/cli-helpers-engine')

const buildApp = async ({ name, ...argv }) => {
const buildApp = async () => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint rule: no unused variables

reporter.info(
`Hold your horses! DHIS2 application bootstrapping with ${chalk.bold(
'd2 create app'
Expand Down
15 changes: 2 additions & 13 deletions packages/create/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const handler = async ({ type, name, ...argv }) => {
}
type = type.toLowerCase()
switch (type) {
case 'cli':
case 'cli': {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint rule: lexical scope needed to use const in case

reporter.info(`Creating CLI module in ${name}...`)
const data = await cliBuilder({ name, ...argv })
const dest = path.join(process.cwd(), data.basename)
Expand All @@ -23,8 +23,8 @@ const handler = async ({ type, name, ...argv }) => {
reporter.debug(' dest:', dest)
reporter.debug(' data: ', data)
await installTemplate(src, dest, data)

break
}
case 'app':
await require('./builders/app')({ name, ...argv })
break
Expand All @@ -35,17 +35,6 @@ const handler = async ({ type, name, ...argv }) => {
const command = {
command: 'create <type> [name]',
desc: 'Create various DHIS2 components from templates',
builder: yargs => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint rule: no unused variables

// yargs.positional('type', {
// describe: 'The type of thing to create',
// choices: ['cli', 'app'],
// type: 'string'
// });
// yargs.positional('name', {
// describe: 'The name of the directory in which to create the thing',
// type: 'string'
// });
},
handler,
}

Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/commands/debug/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const run = ({ _, $0, raw, ...argv }) => {
const run = ({ raw, ...argv }) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint rule: no unused variables

const out = JSON.stringify(argv, undefined, raw ? undefined : 2)
console.log(out)
}
Expand Down
12 changes: 5 additions & 7 deletions packages/utils/src/cmds/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,18 @@ const handler = async ({ publish }) => {
'@semantic-release/github',
]

// `options` and `config` should be made configurable
/* rely on defaults for configuration, except for plugins as they
* need to be custom.
*
* https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md
*/
const options = {
branches: 'master',
version: 'v${version}',
plugins: plugins.filter(n => !!n),
}

const config = {
env: {
...process.env,
GIT_AUTHOR_NAME: '@dhis2-bot',
GIT_AUTHOR_EMAIL: 'apps@dhis2.org',
GIT_COMMITTER_NAME: '@dhis2-bot',
GIT_COMMITTER_EMAIL: 'apps@dhis2.org',
NPM_CONFIG_ALLOW_SAME_VERSION: 'true', // Ensure we still publish even though we've already updated the package versions
},
}
Expand Down
Loading