Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade cli-style #596

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
38 changes: 38 additions & 0 deletions .github/workflows/dhis2-verify-commits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: 'dhis2: verify (commits)'

on:
pull_request:
types: ['opened', 'edited', 'reopened', 'synchronize']

jobs:
lint-pr-title:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn'
- run: yarn install --frozen-lockfile
- id: commitlint
run: echo ::set-output name=config_path::$(node -e "process.stdout.write(require('@dhis2/cli-style').config.commitlint)")
- uses: JulienKode/[email protected]
with:
configuration-path: ${{ steps.commitlint.outputs.config_path }}

lint-commits:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn'
- run: yarn install --frozen-lockfile
- id: commitlint
run: echo ::set-output name=config_path::$(node -e "process.stdout.write(require('@dhis2/cli-style').config.commitlint)")
- uses: wagoid/commitlint-github-action@v5
with:
configFile: ${{ steps.commitlint.outputs.config_path }}
206 changes: 71 additions & 135 deletions CHANGELOG.md

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
],
"license": "BSD-3-Clause",
"devDependencies": {
"@dhis2/cli-style": "^9.0.1",
"@dhis2/cli-utils-docsite": "^3.1.2",
"@dhis2/cli-style": "^10.5.1",
"@dhis2/cli-utils-docsite": "^3.2.0",
"tape": "^4.13.2",
"tape-await": "^0.1.2"
},
Expand All @@ -26,5 +26,8 @@
"name": "DHIS2 CLI",
"description": "A unified CLI for DHIS2 development workflows."
}
},
"resolutions": {
"@ls-lint/ls-lint": "2.0.1"
}
}
2 changes: 1 addition & 1 deletion packages/app/src/commands/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ const { namespace } = require('@dhis2/cli-helpers-engine')

module.exports = namespace('i18n', {
description: 'Handle translations in apps',
builder: yargs => yargs.commandDir('i18n'),
builder: (yargs) => yargs.commandDir('i18n'),
})
2 changes: 1 addition & 1 deletion packages/app/src/helpers/modernize/checkRequirements.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const checkMainTranslationFilePresent = (
primaryLanguage,
translationFiles
) => {
const mainTranslationFile = translationFiles.find(file =>
const mainTranslationFile = translationFiles.find((file) =>
file.match(`i18n_module_${primaryLanguage}.properties`)
)
const mainTranslationFilePath = path.join(inDir, mainTranslationFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const createNewTranslationFiles = ({
} else {
newContents += `msgid ""\n`
const newLines = splitTranslation(originalTranslation)
newLines.forEach(translationPart => {
newLines.forEach((translationPart) => {
newContents += `"${unescape(translationPart)}"\n`
})
}
Expand All @@ -125,7 +125,7 @@ const createNewTranslationFiles = ({
} else {
newContents += `msgstr ""\n`
const newLines = splitTranslation(translation)
newLines.forEach(translationPart => {
newLines.forEach((translationPart) => {
newContents += `"${unescape(translationPart)}"\n`
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/helpers/modernize/deleteLegacyFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { reporter } = require('@dhis2/cli-helpers-engine')
* @returns {void}
*/
const deleteLegacyFiles = ({ translationFiles, languagesToTransform }) => {
translationFiles.forEach(file => {
translationFiles.forEach((file) => {
const language = file.replace(/i18n_module_|.properties/g, '')

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const generateTranslationMappings = ({
})
const lines = contents
.split('\n')
.filter(line => line !== '' && !line[0].match(/\s*#/))
.filter((line) => line !== '' && !line[0].match(/\s*#/))

if (
languagesToTransform.length &&
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/helpers/modernize/getTemplates.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs')
const path = require('path')

const getTemplateMainLanguage = creationDate => {
const getTemplateMainLanguage = (creationDate) => {
const template = fs.readFileSync(
path.join(__dirname, 'main_language.template'),
{ encoding: 'utf8' }
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/helpers/modernize/getTranslationFileNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const fs = require('fs')
const {
checkIODirectories,
checkMainTranslationFilePresent,
} = require('./checkRequirements')
} = require('./checkRequirements.js')

const fileIsOldTranslationFile = fileName => fileName.match(/\.properties$/)
const fileIsOldTranslationFile = (fileName) => fileName.match(/\.properties$/)

/**
* @param {Object} args
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/helpers/modernize/splitTranslation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const LENGTH_TO_SPLIT_LINE_AT = 77
* The translation needs to be split by whitespaces first in order to create the
* correct structure of the new translation
*/
const splitTranslation = translation =>
const splitTranslation = (translation) =>
translation.split(' ').reduce((parts, curSplit) => {
const latestPart = parts[parts.length - 1]
const latestPartEscaped = escape(latestPart)
Expand All @@ -27,7 +27,7 @@ const splitTranslation = translation =>
return parts
}

curSplitEscaped.match(/.{1,76}(?=(%5Cu))?/g).forEach(escapedSplit => {
curSplitEscaped.match(/.{1,76}(?=(%5Cu))?/g).forEach((escapedSplit) => {
parts.push(unescape(escapedSplit))
})

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { namespace, createModuleLoader } = require('@dhis2/cli-helpers-engine')

module.exports = namespace('app', {
description: 'Front-end application and library commands',
builder: yargs => {
builder: (yargs) => {
const loader = createModuleLoader({
parentModule: __filename,
})
Expand Down
4 changes: 2 additions & 2 deletions packages/cluster/src/commands/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const {
makeComposeProject,
makeEnvironment,
resolveConfiguration,
} = require('../common')
} = require('../common.js')

const run = async function (argv) {
const { name, _ } = argv
const cfg = await resolveConfiguration(argv)

const args = _.slice(_.findIndex(x => x === 'compose') + 1)
const args = _.slice(_.findIndex((x) => x === 'compose') + 1)
reporter.debug('Passing arguments to docker-compose', args)

const cacheLocation = await initDockerComposeCache({
Expand Down
2 changes: 1 addition & 1 deletion packages/cluster/src/commands/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { namespace } = require('@dhis2/cli-helpers-engine')

const command = namespace('db', {
desc: 'Manage the database in a DHIS2 Docker cluster',
builder: yargs =>
builder: (yargs) =>
yargs.commandDir('db_cmds').parserConfiguration({
'parse-numbers': false,
}),
Expand Down
7 changes: 5 additions & 2 deletions packages/cluster/src/commands/db_cmds/backup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const { reporter, tryCatchAsync } = require('@dhis2/cli-helpers-engine')
const { initDockerComposeCache, resolveConfiguration } = require('../../common')
const { backup } = require('../../helpers/db')
const {
initDockerComposeCache,
resolveConfiguration,
} = require('../../common.js')
const { backup } = require('../../helpers/db.js')

const run = async function (argv) {
const { name, getCache, path, fat } = argv
Expand Down
7 changes: 5 additions & 2 deletions packages/cluster/src/commands/db_cmds/restore.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const { reporter, tryCatchAsync } = require('@dhis2/cli-helpers-engine')
const { initDockerComposeCache, resolveConfiguration } = require('../../common')
const { restore } = require('../../helpers/db')
const {
initDockerComposeCache,
resolveConfiguration,
} = require('../../common.js')
const { restore } = require('../../helpers/db.js')

const run = async function (argv) {
const { name, getCache } = argv
Expand Down
2 changes: 1 addition & 1 deletion packages/cluster/src/commands/down.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {
makeComposeProject,
makeEnvironment,
cleanCache,
} = require('../common')
} = require('../common.js')

const run = async function (argv) {
const { name, clean, getCache } = argv
Expand Down
8 changes: 4 additions & 4 deletions packages/cluster/src/commands/list.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { reporter, exec, chalk } = require('@dhis2/cli-helpers-engine')
const Table = require('cli-table3')
const { makeComposeProject, listClusters } = require('../common')
const { makeComposeProject, listClusters } = require('../common.js')

const getStatus = async cluster =>
const getStatus = async (cluster) =>
// TODO: check the status of the other services, not just `core`
await exec({
cmd: 'docker',
Expand All @@ -18,7 +18,7 @@ const getStatus = async cluster =>
captureOut: true,
})

const formatStatus = status => {
const formatStatus = (status) => {
status = status.trim()

if (status.length === 0) {
Expand Down Expand Up @@ -49,7 +49,7 @@ const run = async function (argv) {
})

await Promise.all(
clusters.map(async cluster => {
clusters.map(async (cluster) => {
const status = await getStatus(cluster)
table.push([
chalk.blue(cluster.name),
Expand Down
2 changes: 1 addition & 1 deletion packages/cluster/src/commands/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
makeComposeProject,
makeEnvironment,
resolveConfiguration,
} = require('../common')
} = require('../common.js')

const run = async function (argv) {
const { service, name } = argv
Expand Down
4 changes: 2 additions & 2 deletions packages/cluster/src/commands/restart.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const {
makeComposeProject,
makeEnvironment,
resolveConfiguration,
} = require('../common')
const defaults = require('../defaults')
} = require('../common.js')
const defaults = require('../defaults.js')

const run = async function (argv) {
const { name, service } = argv
Expand Down
2 changes: 1 addition & 1 deletion packages/cluster/src/commands/status.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { exec, reporter } = require('@dhis2/cli-helpers-engine')
const { makeComposeProject } = require('../common')
const { makeComposeProject } = require('../common.js')

const run = async function ({ name, ...argv }) {
try {
Expand Down
6 changes: 3 additions & 3 deletions packages/cluster/src/commands/up.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const {
makeEnvironment,
makeComposeProject,
resolveConfiguration,
} = require('../common')
const defaults = require('../defaults')
const { restore } = require('../helpers/db')
} = require('../common.js')
const defaults = require('../defaults.js')
const { restore } = require('../helpers/db.js')

const run = async function (argv) {
const { name, seed, seedFile, update, getCache } = argv
Expand Down
27 changes: 15 additions & 12 deletions packages/cluster/src/common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path')
const { reporter } = require('@dhis2/cli-helpers-engine')
const defaults = require('./defaults')
const defaults = require('./defaults.js')

const clusterDir = 'clusters'
const dockerComposeCacheName = 'docker-compose'
Expand Down Expand Up @@ -111,10 +111,10 @@ function dockerImageUsingJib(version) {

const segments = version
.split('.')
.map(s => s.trim())
.filter(s => s.length > 0) // to remove empty segments we get with versions like "2."
.map(n => parseInt(n, 10))
.filter(n => !Number.isNaN(n))
.map((s) => s.trim())
.filter((s) => s.length > 0) // to remove empty segments we get with versions like "2."
.map((n) => parseInt(n, 10))
.filter((n) => !Number.isNaN(n))
if (segments.length < 2) {
throw new Error(
`Invalid version format: '${version}'. Must be 'master' or '2.major.minor.patch'. 'patch' being optional.`
Expand Down Expand Up @@ -206,7 +206,7 @@ async function resolveConfiguration(argv = {}) {
module.exports.cleanCache = async ({ cache, name }) =>
await cache.purge(path.join(clusterDir, name))

module.exports.makeEnvironment = cfg => {
module.exports.makeEnvironment = (cfg) => {
const env = {
DHIS2_HOME: cfg.dhis2Home,
DHIS2_CORE_NAME: cfg.name,
Expand All @@ -227,20 +227,23 @@ module.exports.makeEnvironment = cfg => {

// This has to match the normalization done by docker-compose to reliably get container statuses
// from https://github.com/docker/compose/blob/c8279bc4db56f49cf2e2b80c8734ced1c418b856/compose/cli/command.py#L154
const normalizeName = name => name.replace(/[^-_a-z0-9]/g, '')
const normalizeName = (name) => name.replace(/[^-_a-z0-9]/g, '')

module.exports.makeComposeProject = name => `d2-cluster-${normalizeName(name)}`
module.exports.makeComposeProject = (name) =>
`d2-cluster-${normalizeName(name)}`

module.exports.listClusters = async argv => {
module.exports.listClusters = async (argv) => {
const cache = argv.getCache()

const exists = await cache.exists(clusterDir)
if (!exists) return []
if (!exists) {
return []
}

const stat = await cache.stat(clusterDir)
const promises = Object.keys(stat.children)
.filter(name => cache.exists(path.join(clusterDir, name)))
.map(name => resolveConfiguration({ name, getCache: argv.getCache }))
.filter((name) => cache.exists(path.join(clusterDir, name)))
.map((name) => resolveConfiguration({ name, getCache: argv.getCache }))
return await Promise.all(promises)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cluster/src/helpers/db/backup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path')
const { reporter, exec, chalk } = require('@dhis2/cli-helpers-engine')
const { makeComposeProject } = require('../../common')
const { makeComposeProject } = require('../../common.js')

module.exports = async ({ cacheLocation, name, path: dbPath, fat }) => {
const destinationFile = path.resolve(dbPath)
Expand Down
4 changes: 2 additions & 2 deletions packages/cluster/src/helpers/db/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
module.exports.backup = require('./backup')
module.exports.restore = require('./restore')
module.exports.backup = require('./backup.js')
module.exports.restore = require('./restore.js')
2 changes: 1 addition & 1 deletion packages/cluster/src/helpers/db/restore.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path')
const { reporter, exec, chalk } = require('@dhis2/cli-helpers-engine')
const { makeComposeProject, substituteVersion } = require('../../common')
const { makeComposeProject, substituteVersion } = require('../../common.js')

const downloadDatabase = async ({ cache, dbVersion, update, url }) => {
const ext = '.sql.gz' //dbUrl.endsWith('.gz') ? '.gz' : '.sql'
Expand Down
2 changes: 1 addition & 1 deletion packages/cluster/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { namespace } = require('@dhis2/cli-helpers-engine')
const command = namespace('cluster', {
desc: 'Manage DHIS2 Docker clusters',
aliases: 'c',
builder: yargs =>
builder: (yargs) =>
yargs.commandDir('commands').parserConfiguration({
'parse-numbers': false,
}),
Expand Down
Loading
Loading