diff --git a/lib/analyze-commits.js b/lib/analyze-commits.js index ba63155..045a52a 100644 --- a/lib/analyze-commits.js +++ b/lib/analyze-commits.js @@ -1,4 +1,4 @@ -const eik = require('@eik/cli'); +import eik from '@eik/cli'; const I_VERSION_UPDATE = 'Version: ✅ Updated Eik version from v%s to v%s.'; const I_VERSION_NOT_NEEDED = @@ -15,13 +15,13 @@ const E_VERSIONING_ERROR = /** * Semantic Release "Analyze Commits" hook * Responsible for determining the type of the next release (major, minor or patch). If multiple plugins with a analyzeCommits step are defined, the release type will be the highest one among plugins output. - * See https://github.com/semantic-release/semantic-release/blob/master/docs/usage/plugins.md#plugins + * See https://semantic-release.gitbook.io/semantic-release/usage/plugins * * @param {object} options * @param {object} context * @param {object} state */ -module.exports = async function analyzeCommits(options, context, state) { +export default async function analyzeCommits(options, context, state) { const { version: currentVersion, server, type, name } = state.eikJSON; // attempt to version Eik assets @@ -73,4 +73,4 @@ module.exports = async function analyzeCommits(options, context, state) { throw err; } -}; +} diff --git a/lib/generate-notes.js b/lib/generate-notes.js index f823778..4bd2be4 100644 --- a/lib/generate-notes.js +++ b/lib/generate-notes.js @@ -1,16 +1,16 @@ -const { join } = require('path'); -const { typeSlug } = require('@eik/common-utils'); +import { join } from 'path'; +import { typeSlug } from '@eik/common-utils'; /** * Semantic Release "generate notes" hook * "Responsible for generating the content of the release note. If multiple plugins with a generateNotes step are defined, the release notes will be the result of the concatenation of each plugin output." - * See https://github.com/semantic-release/semantic-release/blob/master/docs/usage/plugins.md#plugins + * See https://semantic-release.gitbook.io/semantic-release/usage/plugins * * @param {object} options * @param {object} context * @param {object} state */ -module.exports = async function generateNotes(options, context, state) { +export default async function generateNotes(options, context, state) { if (!state.publishNeeded) return; const { name, server, type } = state.eikJSON; @@ -22,4 +22,4 @@ module.exports = async function generateNotes(options, context, state) { const nameURL = new URL(join(slug, name), server).href; return `(${dateString}) Version [${version}](${versionURL}) of Eik package [${name}](${nameURL}) published to [${server}](${server})`; -}; +} diff --git a/lib/main.js b/lib/main.js index efee3ad..4001f38 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,10 +1,10 @@ -const verifyConditions = require('./verify-conditions'); -const analyzeCommits = require('./analyze-commits'); -const verifyRelease = require('./verify-release'); -const generateNotes = require('./generate-notes'); -const prepare = require('./prepare'); -const publish = require('./publish'); -const success = require('./success'); +import verifyConditions from './verify-conditions.js'; +import analyzeCommits from './analyze-commits.js'; +import verifyRelease from './verify-release.js'; +import generateNotes from './generate-notes.js'; +import prepare from './prepare.js'; +import publish from './publish.js'; +import success from './success.js'; class State { eikToken = ''; @@ -15,7 +15,7 @@ class State { const state = new State(); -module.exports = { +export default { verifyConditions: (options, ctx) => verifyConditions(options, ctx, state), analyzeCommits: (options, ctx) => analyzeCommits(options, ctx, state), verifyRelease: (options, ctx) => verifyRelease(options, ctx, state), diff --git a/lib/prepare.js b/lib/prepare.js index dac98d2..b7e5503 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -1,17 +1,17 @@ -const json = require('@eik/cli/utils/json'); +import json from '@eik/cli/utils/json/index.js'; const VERSION_WRITTEN = 'Version: ✅ v%s written back to eik.json file.'; /** * Semantic Release "prepare" hook * "Responsible for preparing the release, for example creating or updating files such as package.json, CHANGELOG.md, documentation or compiled assets and pushing a commit." - * See https://github.com/semantic-release/semantic-release/blob/master/docs/usage/plugins.md#plugins + * See https://semantic-release.gitbook.io/semantic-release/usage/plugins * * @param {object} options * @param {object} context * @param {object} state */ -module.exports = async function prepare(options, context, state) { +export default async function prepare(options, context, state) { if (!state.publishNeeded) return; if (state.eikJSON.version !== state.versionToPublish) { @@ -21,4 +21,4 @@ module.exports = async function prepare(options, context, state) { { cwd: context.cwd }, ); } -}; +} diff --git a/lib/publish.js b/lib/publish.js index 91b99de..9c006b4 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -1,4 +1,4 @@ -const eik = require('@eik/cli'); +import eik from '@eik/cli'; const PUBLISHED = 'Publish: ✅ Published %s file(s) to Eik server %s'; const E_PUBLISH_FAILED = @@ -7,13 +7,13 @@ const E_PUBLISH_FAILED = /** * Semantic Release "publish" hook * "Responsible for publishing the release." - * See https://github.com/semantic-release/semantic-release/blob/master/docs/usage/plugins.md#plugins + * See https://semantic-release.gitbook.io/semantic-release/usage/plugins * * @param {object} options * @param {object} context * @param {object} state */ -module.exports = async function publish(options, context, state) { +export default async function publish(options, context, state) { if (!state.publishNeeded) return; try { @@ -41,4 +41,4 @@ module.exports = async function publish(options, context, state) { context.logger.log(E_PUBLISH_FAILED); throw err; } -}; +} diff --git a/lib/success.js b/lib/success.js index 0f69e21..780c122 100644 --- a/lib/success.js +++ b/lib/success.js @@ -1,6 +1,5 @@ -const { join } = require('path'); -const { default: fetch } = require('node-fetch'); -const { typeSlug } = require('@eik/common-utils'); +import { join } from 'node:path'; +import { typeSlug } from '@eik/common-utils'; const PUBLISH_SUCCESS = 'Publish: ✅ Successfully published package %s (v%s) to %s.'; @@ -10,13 +9,13 @@ const PUBLISH_FAILURE = /** * Semantic Release "success" hook * "Responsible for notifying of a new release." - * See https://github.com/semantic-release/semantic-release/blob/master/docs/usage/plugins.md#plugins + * See https://semantic-release.gitbook.io/semantic-release/usage/plugins * * @param {object} options * @param {object} context * @param {object} state */ -module.exports = async function success(options, context, state) { +export default async function success(options, context, state) { if (!state.publishNeeded) return; const { logger } = context; const { server, name, type } = state.eikJSON; @@ -35,4 +34,4 @@ module.exports = async function success(options, context, state) { result.status, ); } -}; +} diff --git a/lib/verify-conditions.js b/lib/verify-conditions.js index ce42c2b..c32a3eb 100644 --- a/lib/verify-conditions.js +++ b/lib/verify-conditions.js @@ -1,6 +1,6 @@ -const AggregateError = require('aggregate-error'); -const eik = require('@eik/cli'); -const { configStore } = require('@eik/common-config-loader'); +import eik from '@eik/cli'; +import { configStore } from '@eik/common-config-loader'; +import AggregateError from 'aggregate-error'; const E_TOKEN_MISSING = 'Verify: ❌ EIK_TOKEN environment variable not found'; const E_LEVEL_INVALID = @@ -11,13 +11,13 @@ const LEVELS = ['major', 'minor', 'patch']; /** * Semantic Release "verify conditions" hook * "Verify all the conditions to proceed with the release." - * See https://github.com/semantic-release/semantic-release/blob/master/docs/usage/plugins.md#plugins + * See https://semantic-release.gitbook.io/semantic-release/usage/plugins * * @param {object} options * @param {object} context * @param {object} state */ -module.exports = async function verifyConditions(options, context, state) { +export default async function verifyConditions(options, context, state) { const errors = []; // verify EIK_TOKEN present in the environment @@ -46,4 +46,4 @@ module.exports = async function verifyConditions(options, context, state) { if (errors.length > 0) { throw new AggregateError(errors); } -}; +} diff --git a/lib/verify-release.js b/lib/verify-release.js index df8642a..f26fa5a 100644 --- a/lib/verify-release.js +++ b/lib/verify-release.js @@ -1,4 +1,4 @@ -const eik = require('@eik/cli'); +import eik from '@eik/cli'; const E_NO_FILES = `Verify: ❌ No files detected for upload. Did you run bundling first (if needed)? Is the "files" field of eik.json correct?`; const E_VERIFY_FAIL = 'Verify: ❌ Verification checks failed to complete'; @@ -7,13 +7,13 @@ const FOUND_FILES = 'Verify: ✅ Found %d file(s) to publish'; /** * Semantic Release "verify release" hook * "Responsible for verifying the parameters (version, type, dist-tag etc...) of the release that is about to be published." - * See https://github.com/semantic-release/semantic-release/blob/master/docs/usage/plugins.md#plugins + * See https://semantic-release.gitbook.io/semantic-release/usage/plugins * * @param {object} options * @param {object} context * @param {object} state */ -module.exports = async function verifyRelease(options, context, state) { +export default async function verifyRelease(options, context, state) { if (!state.publishNeeded) return; try { @@ -40,4 +40,4 @@ module.exports = async function verifyRelease(options, context, state) { context.logger.log(E_VERIFY_FAIL); throw err; } -}; +} diff --git a/test/main.js b/test/main.test.js similarity index 80% rename from test/main.js rename to test/main.test.js index a879971..f9f7307 100644 --- a/test/main.js +++ b/test/main.test.js @@ -1,7 +1,5 @@ -'use strict'; - -const plugin = require('../lib/main.js'); -const tap = require('tap'); +import tap from 'tap'; +import plugin from '../lib/main.js'; tap.test('Simple test', (t) => { t.type(plugin.verifyConditions, 'function');