Skip to content

Commit

Permalink
Release version 1.0.0-rc.1
Browse files Browse the repository at this point in the history
 - Log more specific errors when an operation fails.
 - Compress LevelDB after packing it.
 - Fix NeDB operations throwing a TypeError.
 - Rename conflicting --id option to --in.
 - Rename --od to --out.
 - Write source files to compendiumName/_source for NeDB unpack operations.
 - Always unpack to single primary Documents with bundled embedded Documents.
 - Improve JSDoc.
 - Improve NeDB pack type inference.
 - Exit with non-zero exit code where appropriate.
 - Append newline character to the end of unpacked JSON files.
 - Refactor codebase to conform to Foundry VTT project style.
 - Add .editorconfig and .eslintrc.json to enforce code style.
 - Add .npmignore to strip development-only files from final NPM package.
  • Loading branch information
Fyorl committed Aug 22, 2023
1 parent 95f7615 commit ea44157
Show file tree
Hide file tree
Showing 12 changed files with 3,227 additions and 816 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
charset = utf-8
209 changes: 209 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
{
"env": {
"es2022": true,
"node": true
},
"parserOptions": {
"requireConfigFile": false
},
"plugins": [
"jsdoc"
],
"rules": {
"array-bracket-spacing": ["warn", "never"],
"array-callback-return": "warn",
"arrow-spacing": "warn",
"comma-dangle": ["warn", "never"],
"comma-style": "warn",
"computed-property-spacing": "warn",
"constructor-super": "error",
"default-param-last": "warn",
"dot-location": ["warn", "property"],
"eol-last": ["error", "always"],
"eqeqeq": ["warn", "smart"],
"func-call-spacing": "warn",
"func-names": ["warn", "never"],
"getter-return": "warn",
"lines-between-class-members": "warn",
"new-parens": ["warn", "always"],
"no-alert": "warn",
"no-array-constructor": "warn",
"no-class-assign": "warn",
"no-compare-neg-zero": "warn",
"no-cond-assign": "warn",
"no-const-assign": "error",
"no-constant-condition": "warn",
"no-constructor-return": "warn",
"no-delete-var": "warn",
"no-dupe-args": "warn",
"no-dupe-class-members": "warn",
"no-dupe-keys": "warn",
"no-duplicate-case": "warn",
"no-duplicate-imports": ["warn", {"includeExports": true}],
"no-empty": ["warn", {"allowEmptyCatch": true}],
"no-empty-character-class": "warn",
"no-empty-pattern": "warn",
"no-func-assign": "warn",
"no-global-assign": "warn",
"no-implicit-coercion": ["warn", {"allow": ["!!"]}],
"no-implied-eval": "warn",
"no-import-assign": "warn",
"no-invalid-regexp": "warn",
"no-irregular-whitespace": "warn",
"no-iterator": "warn",
"no-lone-blocks": "warn",
"no-lonely-if": "warn",
"no-loop-func": "warn",
"no-misleading-character-class": "warn",
"no-mixed-operators": "warn",
"no-multi-str": "warn",
"no-multiple-empty-lines": "warn",
"no-new-func": "warn",
"no-new-object": "warn",
"no-new-symbol": "warn",
"no-new-wrappers": "warn",
"no-nonoctal-decimal-escape": "warn",
"no-obj-calls": "warn",
"no-octal": "warn",
"no-octal-escape": "warn",
"no-promise-executor-return": "warn",
"no-proto": "warn",
"no-regex-spaces": "warn",
"no-script-url": "warn",
"no-self-assign": "warn",
"no-self-compare": "warn",
"no-setter-return": "warn",
"no-sequences": "warn",
"no-template-curly-in-string": "warn",
"no-this-before-super": "error",
"no-unexpected-multiline": "warn",
"no-unmodified-loop-condition": "warn",
"no-unneeded-ternary": "warn",
"no-unreachable": "warn",
"no-unreachable-loop": "warn",
"no-unsafe-negation": ["warn", {"enforceForOrderingRelations": true}],
"no-unsafe-optional-chaining": ["warn", {"disallowArithmeticOperators": true}],
"no-unused-expressions": "warn",
"no-useless-backreference": "warn",
"no-useless-call": "warn",
"no-useless-catch": "warn",
"no-useless-computed-key": ["warn", {"enforceForClassMembers": true}],
"no-useless-concat": "warn",
"no-useless-constructor": "warn",
"no-useless-rename": "warn",
"no-useless-return": "warn",
"no-var": "warn",
"no-void": "warn",
"no-whitespace-before-property": "warn",
"prefer-numeric-literals": "warn",
"prefer-object-spread": "warn",
"prefer-regex-literals": "warn",
"prefer-spread": "warn",
"rest-spread-spacing": ["warn", "never"],
"semi-spacing": "warn",
"semi-style": ["warn", "last"],
"space-unary-ops": ["warn", {"words": true, "nonwords": false}],
"switch-colon-spacing": "warn",
"symbol-description": "warn",
"template-curly-spacing": ["warn", "never"],
"unicode-bom": ["warn", "never"],
"use-isnan": ["warn", {"enforceForSwitchCase": true, "enforceForIndexOf": true}],
"valid-typeof": ["warn", {"requireStringLiterals": true}],
"wrap-iife": ["warn", "inside"],

"arrow-parens": ["warn", "as-needed", {"requireForBlockBody": false}],
"capitalized-comments": ["warn", "always", {
"ignoreConsecutiveComments": true,
"ignorePattern": "noinspection"
}],
"comma-spacing": "warn",
"dot-notation": "warn",
"indent": ["warn", 2, {"SwitchCase": 1}],
"key-spacing": "warn",
"keyword-spacing": ["warn", {"overrides": {"catch": {"before": true, "after": false}}}],
"max-len": ["warn", {
"code": 120,
"ignoreTrailingComments": true,
"ignoreUrls": true,
"ignoreStrings": true,
"ignoreTemplateLiterals": true
}],
"no-extra-boolean-cast": ["warn", {"enforceForLogicalOperands": true}],
"no-extra-semi": "warn",
"no-multi-spaces": ["warn", {"ignoreEOLComments": true}],
"no-tabs": "warn",
"no-throw-literal": "error",
"no-trailing-spaces": "warn",
"no-useless-escape": "warn",
"nonblock-statement-body-position": ["warn", "beside"],
"one-var": ["warn", "never"],
"operator-linebreak": ["warn", "before", {
"overrides": {"=": "after", "+=": "after", "-=": "after"}
}],
"prefer-template": "warn",
"quote-props": ["warn", "as-needed", {"keywords": false}],
"quotes": ["warn", "double", {"avoidEscape": true, "allowTemplateLiterals": false}],
"semi": "warn",
"space-before-blocks": ["warn", "always"],
"space-before-function-paren": ["warn", {
"anonymous": "never",
"named": "never",
"asyncArrow": "always"
}],
"spaced-comment": "warn",
"jsdoc/check-access": "warn",
"jsdoc/check-alignment": "warn",
"jsdoc/check-examples": "off",
"jsdoc/check-indentation": "off",
"jsdoc/check-line-alignment": "off",
"jsdoc/check-param-names": "warn",
"jsdoc/check-property-names": "warn",
"jsdoc/check-syntax": "off",
"jsdoc/check-tag-names": ["warn", { "definedTags": ["category"] }],
"jsdoc/check-types": "warn",
"jsdoc/check-values": "warn",
"jsdoc/empty-tags": "warn",
"jsdoc/implements-on-classes": "warn",
"jsdoc/match-description": "off",
"jsdoc/newline-after-description": "off",
"jsdoc/no-bad-blocks": "warn",
"jsdoc/no-defaults": "off",
"jsdoc/no-types": "off",
"jsdoc/no-undefined-types": "off",
"jsdoc/require-description": "warn",
"jsdoc/require-description-complete-sentence": "off",
"jsdoc/require-example": "off",
"jsdoc/require-file-overview": "off",
"jsdoc/require-hyphen-before-param-description": ["warn", "never"],
"jsdoc/require-jsdoc": "warn",
"jsdoc/require-param": "warn",
"jsdoc/require-param-description": "off",
"jsdoc/require-param-name": "warn",
"jsdoc/require-param-type": "warn",
"jsdoc/require-property": "warn",
"jsdoc/require-property-description": "off",
"jsdoc/require-property-name": "warn",
"jsdoc/require-property-type": "warn",
"jsdoc/require-returns": "off",
"jsdoc/require-returns-check": "warn",
"jsdoc/require-returns-description": "off",
"jsdoc/require-returns-type": "warn",
"jsdoc/require-throws": "off",
"jsdoc/require-yields": "warn",
"jsdoc/require-yields-check": "warn",
"jsdoc/valid-types": "off"
},
"settings": {
"jsdoc": {
"preferredTypes": {
".<>": "<>",
"object": "Object",
"Object": "object"
},
"mode": "typescript",
"tagNamePreference": {
"augments": "extends"
}
}
}
}
14 changes: 14 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# IDE
.idea/
.nova/
.vs/
.vscode/
*.code-workspace
*.iml

# GH Actions
.github

# Code Style
.editorconfig
.eslintrc.json
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## 1.0.0

### Fixes
- (DJ4ddi) Log more specific errors when an operation fails.
- (DJ4ddi) Compress LevelDB after packing it.
- Fixed NeDB operations throwing a TypeError.

### Breaking Changes
- (DJ4ddi) Renamed `--inputDirectory` shorthand option from `--id` to `--in` to fix conflict with package ID `--id` option.
- Renamed `--outputDirectory` shorthand option from `--od` to `--out` to better align with the above change.
- NeDB unpack operations now write source data to the same directory as LevelDB unpack operations by default (`packs/{compendiumName}/_source`). This fixes an issue whereby sequential NeDB unpack operations would mix all their output together into the same `packs/_source` directory, and allows for better inter-operability with LevelDB operations.
- Corresponding to the above change, NeDB pack operations by default will look for source files under `packs/{compendiumName}/_source` instead of `packs/_source`.
- Unpack operations are now consistent between NeDB and LevelDB: Both will unpack primary Document entries to a single file, with all embedded Documents included, rather than LevelDB unpack operations writing every embedded Document to its own file.

### Improvements
- Improved JSDoc annotations across the project.
- Improved NeDB document type inference to check the manifest of the package the compendium belongs to rather than searching all packages for a compendium with a matching name.
- The CLI should be slightly better-behaved and exit with a non-zero error code if it does encounter an error in most cases.
- When writing JSON files, a newline character is appended to the end of the file to make it more git-friendly.

### Miscellaneous
- Removed IDE-specific project data from git tracking.
- Refactored codebase to conform with Foundry VTT code style guidelines.
- Added .editorconfig and .eslintrc.json to enforce code style.
- Added .npmignore to strip development-only files from final NPM package.
117 changes: 60 additions & 57 deletions commands/configuration.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,71 @@ import Config from "../config.mjs";

/**
* Get the command object for the configuration command
* @returns {{handler: ((function(*): Promise<void>)|*), builder: builder, describe: string, command: string}}
* @returns {CommandModule}
*/
export function getCommand() {
return {
command: "configure [action] [key] [value]",
describe: "Manage configuration",
builder: (yargs) => {
yargs.positional("action", {
describe: "The action to perform",
type: "string",
choices: ["get", "set", "path", "view"]
})
.positional("key", {
describe: "The configuration key",
type: "string"
})
.positional("value", {
describe: "The configuration value",
type: "string"
});
},
handler: async (argv) => {
return {
command: "configure [action] [key] [value]",
describe: "Manage configuration",
builder: yargs => {
yargs.positional("action", {
describe: "The action to perform",
type: "string",
choices: ["get", "set", "path", "view"]
}).positional("key", {
describe: "The configuration key",
type: "string"
}).positional("value", {
describe: "The configuration value",
type: "string"
});
return yargs;
},
handler: async argv => {

// Handle actions
switch ( argv.action ) {
case "get": {
console.log(Config.instance.get(argv.key));
break;
}
case "set": {
Config.instance.set(argv.key, argv.value);
console.log(`Set ${argv.key} to ${argv.value}`);
break;
}
case "view": {
// Output the current configuration
console.log("Current Configuration:", Config.instance.getAll());
break;
}
case "path": {
// Output the current configuration file path
console.log("Current Configuration File:", Config.instance.configPath);
break;
}
default: {
// Determine if the dataPath and installPath are set
const installPath = Config.instance.get("installPath");
if ( !installPath ) {
console.error("The installation path is not set. Use `configure set installPath <path>` to set it. Install paths look like `C:/Program Files/Foundry Virtual Tabletop`");
}
// Handle actions
switch ( argv.action ) {
case "get": {
console.log(Config.instance.get(argv.key));
break;
}

case "set": {
Config.instance.set(argv.key, argv.value);
console.log(`Set ${argv.key} to ${argv.value}`);
break;
}

case "view": {
// Output the current configuration
console.log("Current Configuration:", Config.instance.getAll());
break;
}

case "path": {
// Output the current configuration file path
console.log("Current Configuration File:", Config.instance.configPath);
break;
}

default: {
// Determine if the dataPath and installPath are set
const installPath = Config.instance.get("installPath");
if ( !installPath ) {
console.error("The installation path is not set. Use `configure set installPath <path>` to set it. "
+ "Install paths look like `C:/Program Files/Foundry Virtual Tabletop`");
}

const dataPath = Config.instance.get("dataPath");
if ( !dataPath ) {
console.error("The data path is not set. Use `configure set dataPath <path>` to set it. Data paths look like `C:/Users/Example/AppData/Local/FoundryVTT`");
}
const dataPath = Config.instance.get("dataPath");
if ( !dataPath ) {
console.error("The data path is not set. Use `configure set dataPath <path>` to set it. "
+ "Data paths look like `C:/Users/Example/AppData/Local/FoundryVTT`");
}

// If both are set, configuration is complete
if ( installPath && dataPath ) {
console.log("Configuration complete!");
}
}
}
// If both are set, configuration is complete
if ( installPath && dataPath ) console.log("Configuration complete!");
}
}
}
}
}
Loading

0 comments on commit ea44157

Please sign in to comment.