diff --git a/index.js b/index.js index 7617396..cc4b454 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,9 @@ -const verifyPackage = require("./lib/verify"); -const preparePackage = require("./lib/prepare"); +import verifyPackage from "./lib/verify.js"; +import preparePackage from "./lib/prepare.js"; let verified; -async function verifyConditions(pluginConfig, context) { +export async function verifyConditions(pluginConfig, context) { const { options } = context; if (options.prepare) { const preparePlugin = castArray(options.prepare).find(config => config.path && config.path === "@iam1337/create-unitypackage") || {}; @@ -17,13 +17,11 @@ async function verifyConditions(pluginConfig, context) { verified = true; } -async function prepare(pluginConfig, context) { +export async function prepare(pluginConfig, context) { if (!verified) { verifyPackage(pluginConfig, context); verified = true; } preparePackage(pluginConfig, context); -} - -module.exports = { verifyConditions, prepare }; \ No newline at end of file +} \ No newline at end of file diff --git a/lib/definitions/errors.js b/lib/definitions/errors.js index ad4e878..d3f59bd 100644 --- a/lib/definitions/errors.js +++ b/lib/definitions/errors.js @@ -1,24 +1,31 @@ -const pkg = require("../../package.json"); +import { createRequire } from "node:module"; +const require = createRequire(import.meta.url); +const pkg = require("../../package.json"); const [homepage] = pkg.homepage.split("#"); const linkify = (file) => `${homepage}/blob/master/${file}`; -module.exports = { - EINVALIDPACKAGEROOT: ({ packageRoot }) => ({ +export function EINVALIDPACKAGEROOT ({ packageRoot }) { + return { message: "Invalid `packageRoot` option.", details: `The [packageRoot option](${linkify('README.md#packageRoot')}) option, must be a non empty \`String\`. Your configuration for the \`packageRoot\` option is \`${packageRoot}\`.` - }), + } +} - EINVALIDPROJECTEROOT: ({ projectRoot }) => ({ +export function EINVALIDPROJECTEROOT ({ projectRoot }) +{ + return { message: "Invalid `projectRoot` option.", details: `The [projectRoot option](${linkify('README.md#projectRoot')}) option, if defined must be a non empty \`String\`. Your configuration for the \`projectRoot\` option is \`${projectRoot}\`.` - }), + } +} - EINVALIDOUTPUT: ({ output }) => ({ +export function EINVALIDOUTPUT ({ output }) { + return { message: "Invalid `output` option.", details: `The [output option](${linkify('README.md#output')}) option, must be a non empty \`String\` and must end with \`.unitypackage\`. Your configuration for the \`output\` option is \`${output}\`.` - }), -}; \ No newline at end of file + } +} \ No newline at end of file diff --git a/lib/get-error.js b/lib/get-error.js index 972d66a..4fe0694 100644 --- a/lib/get-error.js +++ b/lib/get-error.js @@ -1,7 +1,7 @@ -const SemanticReleaseError = require('@semantic-release/error'); -const ERROR_DEFINITIONS = require('./definitions/errors'); +import SemanticReleaseError from "@semantic-release/error"; +import * as ERROR_DEFINITIONS from "./definitions/errors.js"; -module.exports = (code, ctx = {}, context) => { +export default function getError(code, ctx = {}, context) { const { message, details } = ERROR_DEFINITIONS[code](ctx); return new SemanticReleaseError(message, code, details); -}; \ No newline at end of file +} \ No newline at end of file diff --git a/lib/prepare.js b/lib/prepare.js index 0150798..2abf65f 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -1,6 +1,8 @@ -const glob = require("glob"); +import glob from "glob"; +import createUnityPackage from "unitypackage"; -module.exports = ({packageRoot, projectRoot, output}, context) => { +export default function preparePackage({packageRoot, projectRoot, output}, context) +{ const { logger } = context; const metaFiles = [`${packageRoot}.meta`]; @@ -8,7 +10,5 @@ module.exports = ({packageRoot, projectRoot, output}, context) => { metaFiles.push(file); }); - let createUnityPackage = import("unitypackage").default; - logger.log("T: " + createUnityPackage); createUnityPackage(metaFiles, projectRoot, output, logger.log); -}; \ No newline at end of file +} \ No newline at end of file diff --git a/lib/resolve-config.js b/lib/resolve-config.js index 4a92864..08779de 100644 --- a/lib/resolve-config.js +++ b/lib/resolve-config.js @@ -1,7 +1,9 @@ -const { isNil } = require("lodash"); +import {isNil} from "lodash-es"; -module.exports = ({ packageRoot, projectRoot, output }) => ({ - packageRoot, - projectRoot: isNil(projectRoot) ? "./" : projectRoot, - output -}); \ No newline at end of file +export default function resolveConfig({ packageRoot, projectRoot, output }) { + return { + packageRoot, + projectRoot: isNil(projectRoot) ? "./" : projectRoot, + output + } +} \ No newline at end of file diff --git a/lib/verify.js b/lib/verify.js index e9548c2..297db82 100644 --- a/lib/verify.js +++ b/lib/verify.js @@ -1,7 +1,7 @@ -const { isString, isNil } = require("lodash"); -const AggregateError = require("aggregate-error"); -const getError = require("./get-error"); -const resolveConfig = require("./resolve-config"); +import {isNil, isString} from "lodash-es"; +import AggregateError from "aggregate-error"; +import getError from "./get-error.js"; +import resolveConfig from "./resolve-config.js"; const isNonEmptyString = (value) => !isNil(value) && isString(value) && value.trim(); const isEndWithUnitypackage = (value) => isNonEmptyString(value) && value.endsWith(".unitypackage"); @@ -12,11 +12,11 @@ const VALIDATORS = { output: isEndWithUnitypackage }; -module.exports = (pluginConfig, context) => { +export default function preparePackage(pluginConfig, context) { const options = resolveConfig(pluginConfig); const errors = Object.entries(options).reduce( (errors, [option, value]) => !VALIDATORS[option](value) - ? [...errors, getError(`EINVALID${option.toUpperCase()}`, { [option]: value }, context)] + ? [...errors, getError(`EINVALID${option.toUpperCase()}`, {[option]: value}, context)] : errors, [] ); @@ -24,4 +24,4 @@ module.exports = (pluginConfig, context) => { if (errors.length > 0) { throw new AggregateError(errors); } -}; \ No newline at end of file +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ad7f0b9..231f9d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,22 +1,23 @@ { "name": "@iam1337/create-unitypackage", - "version": "1.0.5", + "version": "1.0.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@iam1337/create-unitypackage", - "version": "1.0.5", + "version": "1.0.6", "license": "MIT", "dependencies": { "@semantic-release/error": "^3.0.0", "aggregate-error": "^3.0.0", "glob": "^7.1.0", + "json": "^11.0.0", "lodash": "^4.17.21", "unitypackage": "^1.0.7" }, "peerDependencies": { - "semantic-release": ">=11.0.0" + "semantic-release": ">=19.0.0" } }, "node_modules/@babel/code-frame": { @@ -1824,6 +1825,17 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/json": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/json/-/json-11.0.0.tgz", + "integrity": "sha512-N/ITv3Yw9Za8cGxuQqSqrq6RHnlaHWZkAFavcfpH/R52522c26EbihMxnY7A1chxfXJ4d+cEFIsyTgfi9GihrA==", + "bin": { + "json": "lib/json.js" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/json-parse-better-errors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", @@ -7766,6 +7778,11 @@ "argparse": "^2.0.1" } }, + "json": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/json/-/json-11.0.0.tgz", + "integrity": "sha512-N/ITv3Yw9Za8cGxuQqSqrq6RHnlaHWZkAFavcfpH/R52522c26EbihMxnY7A1chxfXJ4d+cEFIsyTgfi9GihrA==" + }, "json-parse-better-errors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", diff --git a/package.json b/package.json index 094f328..4e125f6 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "type": "git", "url": "git+https://github.com/Iam1337/create-unitypackage.git" }, + "type": "module", "license": "MIT", "author": "dr. ext", "keywords": [ @@ -28,8 +29,9 @@ "@semantic-release/error": "^3.0.0", "aggregate-error": "^3.0.0", "glob": "^7.1.0", - "lodash": "^4.17.21", - "unitypackage": "^1.0.7" + "lodash-es": "^4.17.21", + "unitypackage": "^1.0.7", + "json": "^11.0.0" }, "peerDependencies": { "semantic-release": ">=19.0.0"