Skip to content

Commit

Permalink
build: update build to export separated modules for index and cli
Browse files Browse the repository at this point in the history
By updating the gobstones-scripts dependency and ejecting the rollup configuration, along with
changes in the package.json, now a separated cli module is exported. Thi is the module to export
only from cli baed applications, and only in the cli part of it.

fix #22
  • Loading branch information
alanrodas committed Nov 23, 2023
1 parent e182829 commit 9f9e32e
Show file tree
Hide file tree
Showing 106 changed files with 511 additions and 315 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
## <small>0.4.6 (2023-11-21)</small>
## <small>0.4.7 (2023-11-23)</small>


* build: update gobstones-core to latest version of scripts ([2949b1c](https://github.com/gobstones/gobstones-core/commit/2949b1c)), closes [#19](https://github.com/gobstones/gobstones-core/issues/19)


## <small>0.4.6 (2023-11-21)</small>

- build: update gobstones-core to latest version of scripts ([2949b1c](https://github.com/gobstones/gobstones-core/commit/2949b1c)), closes [#19](https://github.com/gobstones/gobstones-core/issues/19)

## <small>0.4.6 (2023-11-21)</small>

Expand Down
2 changes: 1 addition & 1 deletion docs/assets/navigation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/assets/search.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/Events.EventEmitter.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/Expectations.Expectation.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/Expectations.FinishedExpectation.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/Expectations.JoinedExpectation.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/Expectations.Matchers.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/GobstonesLang.Board.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/GobstonesLang.BoardError.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/GobstonesLang.Cell.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/GobstonesLang.Color.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/GobstonesLang.Direction.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/GobstonesLang.InvalidBoardDescription.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/GobstonesLang.InvalidCellReading.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/GobstonesLang.InvalidSizeChange.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/GobstonesLang.InvalidStonesAmount.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/GobstonesLang.LocationFallsOutsideBoard.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/SourceReader.DefinedSourcePosition.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/SourceReader.EndOfInputSourcePosition.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/SourceReader.EndOfStringSourcePosition.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/SourceReader.ErrorAtEndOfInputBy.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/SourceReader.ErrorAtEndOfStringBy.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/SourceReader.ErrorNoInput.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/SourceReader.ErrorUnmatchingPositionsBy.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/SourceReader.KnownSourcePosition.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/SourceReader.SourcePosition.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/SourceReader.SourceReader.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/SourceReader.SourceReaderError.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/SourceReader.SourceReaderErrorBy.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/SourceReader.StringSourcePosition.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/SourceReader.UnknownSourcePosition.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/classes/Translator.Translator.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/Types.BiMap.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/classes/cli.CLIApp.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/classes/cli.CLICommandBuilder.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/docs/globals.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/functions/Expectations.and.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/functions/Expectations.expect.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/functions/Expectations.or.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/functions/Functions.deepEquals.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/functions/Functions.deepStringAssign.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/functions/Functions.flatten.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/functions/Functions.matrix.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/functions/Functions.unflatten.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/functions/cli.cli-1.html

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions docs/functions/cli.readJSON.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/index.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/Expectations.IArrayExpectation.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/Expectations.IFinishedExpectation.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/Expectations.IGenericExpectation.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/Expectations.INumberExpectation.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/Expectations.IObjectExpectation.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/Expectations.IStringExpectation.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/Expectations.MatcherCall.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/Functions.FlattenOptions.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/Functions.UnflattenOptions.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/GobstonesLang.BoardDefinition.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/GobstonesLang.BoardEvents.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/GobstonesLang.CellDataDefinition.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/GobstonesLang.CellEvents.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/GobstonesLang.CellInfo.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/SourceReader.SourceReaderLocale.html

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions docs/interfaces/cli.CLIAppOptions.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/cli.CLIGeneralFlags.html

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions docs/interfaces/cli.CLIGeneralTexts.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/modules/Events.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/modules/Expectations.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/modules/Functions.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/modules/GobstonesLang.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/modules/SourceReader.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/modules/Translator.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/modules/Types.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/modules/Types_WithRequired.html

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions docs/modules/cli.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/types/Events.DefaultEventSignature.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/types/Events.EventSignature.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/types/GobstonesLang.BoardInfo.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/types/GobstonesLang.CellLocation.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/types/GobstonesLang.CellReadingActionAttempt.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/types/GobstonesLang.InvalidSizeChangeAttempt.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/types/GobstonesLang.LocationChangeActionAttempt.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/types/GobstonesLang.OnBoardHeadMovedCallback.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/types/GobstonesLang.OnBoardSizeChangedCallback.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/types/GobstonesLang.OnCellStonesChanged.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/types/GobstonesLang.StonesChangeActionAttempt.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/types/SourceReader.SourceInput.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/types/Types.Subset.html

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions docs/types/Types_WithRequired.WithRequired.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/types/cli.cli.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/variables/GobstonesLang.identifier.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/variables/GobstonesLang.lowerId.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/variables/GobstonesLang.nonAlphabeticId.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/variables/GobstonesLang.number.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/variables/GobstonesLang.sigiledNonAlphabeticId.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/variables/GobstonesLang.upperId.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/variables/SourceReader.SourceReaderIntl.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/variables/SourceReader.availableLocales.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/variables/SourceReader.en.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/variables/SourceReader.es.html

Large diffs are not rendered by default.

32 changes: 28 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gobstones/gobstones-core",
"version": "0.4.6",
"version": "0.4.7",
"description": "A set of utility types, interfaces and classes that are used through all the Gobstones Platform repositories.",
"repository": "https://github.com/gobstones/gobstones-core",
"homepage": "https://gobstones.github.io/gobstones-core",
Expand All @@ -11,8 +11,32 @@
"module": "./dist/esm/index.mjs",
"typings": "./dist/esm/typings/index.d.ts",
"exports": {
"require": "./dist/cjs/index.cjs",
"import": "./dist/esm/index.mjs"
".": {
"import": {
"types": "./dist/esm/typings/index.d.ts",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/cjs/typings/index.d.ts",
"default": "./dist/cjs/index.cjs"
}
},
"./cli": {
"import": {
"types": "./dist/esm/cli/typings/cli.d.ts",
"default": "./dist/esm/cli/cli.mjs"
},
"require": {
"types": "./dist/cjs/cli/typings/cli.d.ts",
"default": "./dist/cjs/cli/cli.cjs"
}
}
},
"typesVersions": {
"*": {
"cli": ["./dist/esm/typings/cli.d.ts"],
".": ["./dist/esm/typings/index.d.ts"]
}
},
"packageManager": "[email protected]",
"scripts": {
Expand All @@ -37,7 +61,7 @@
"commander": "^11.1.0"
},
"devDependencies": {
"@gobstones/gobstones-scripts": "^0.5.3",
"@gobstones/gobstones-scripts": "^0.5.4",
"husky": "^8.0.2"
}
}
60 changes: 60 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');

const commonjs = require('@rollup/plugin-commonjs');
const typescript = require('@rollup/plugin-typescript');

const { config } = require('@gobstones/gobstones-scripts');

const packageJson = JSON.parse(fs.readFileSync('./package.json').toString());

export default [
{
input: 'src/index.ts',
output: [
{
sourcemap: true,
file: packageJson.exports['.'].import.default,
format: 'esm'
},
{
sourcemap: true,
file: packageJson.exports['.'].require.default,
format: 'cjs'
}
],
preserveSymlinks: true,
plugins: [
typescript({
tsconfig: config.configurationFiles[config.loadedOptions.type].tsConfigFile,
declarationDir: './typings'
}),
commonjs()
],
external: [/@gobstones\/.*/]
},
{
input: 'src/cli.ts',
output: [
{
sourcemap: true,
file: packageJson.exports['./cli'].import.default,
format: 'esm'
},
{
sourcemap: true,
file: packageJson.exports['./cli'].require.default,
format: 'cjs'
}
],
preserveSymlinks: true,
plugins: [
typescript({
tsconfig: config.configurationFiles[config.loadedOptions.type].tsConfigFile,
declarationDir: './typings'
}),
commonjs()
],
external: [/@gobstones\/.*/, 'commander', 'fs']
}
];
4 changes: 2 additions & 2 deletions src/Translations/Translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import { flatten } from '../Functions/flatten';

/**
* A Translation consist of an object that hold the state of the current
* A Translator consist of an object that hold the state of the current
* locale being used, and allows for switching between different locales
* and obtain translated strings.
*
* The translation expects a locale to be given as the language definition,
* The translator expects a locale to be given as the language definition,
* and, if constructed with the flatten options, flattens it to allow
* dot notation access to the different strings in the locale object.
*
Expand Down
23 changes: 23 additions & 0 deletions src/Types/WithRequired.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* A type modifier that allows to construct a generic type that
* requires only one property of a given type.
*
* @example
* Conider that we have a type
* ```
* type User = {
* id: string
* name?: string
* email?: string
* }
* ```
*
* Then we can create a type like so:
* ```
* type UserWithName = WithRequired<User, 'name'>
* ```
*
* @param T The base type.
* @param K the name of the property to require in the new type.
*/
export type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
2 changes: 1 addition & 1 deletion src/Types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

export * from './BiMap';
export * from './Subset';
export * from '../Functions/deepStringAssign';
export * from './WithRequired';
74 changes: 57 additions & 17 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,36 @@
import commander, { program } from 'commander';

import { Translator } from './Translations';
import { WithRequired } from './Types';
import fs from 'fs';

/**
* The general texts that a CLI app uses.
* This include the description texts (Or a description key if a {@link Translator} is provided)
* that are used a the description of the different parts of the CLI.
* The `name` and the `versionNumber` are expected to be the app name (No translation
* is used, as the name should be the same through all the app), and the `versionNumber`
* should be the version is the major.minor.patch.
*
* @group API: Options
*/
export interface CLIGeneralTexts {
/** The application name */
name: string;
/** The application version number in semVer */
versionNumber: string;
/** A text displayed when showing the application's help */
help: string;
/** The language used by the application */
language?: string;
/** The error message displayed when using a wrong language */
languageError?: string;
/** Text used by the tool */
tool: string;
/** The text displayed when showing the version of the application */
version: string;
}

/**
* The general flags that a CLI app accepts, when configured to used them.
* Note that currently the default flags cannot be changed.
Expand Down Expand Up @@ -47,22 +75,14 @@ export interface CLIAppOptions {
* is used, as the name should be the same through all the app), and the `versionNumber`
* should be the version is the major.minor.patch.
*/
texts: {
name: string;
versionNumber: string;
help: string;
language?: string;
languageError?: string;
tool: string;
version: string;
};
texts: CLIGeneralTexts;

/**
* A {@link Translator} used to translate the tool to different locales, both when
* called with a language flag, and automatically at startup by auto-detecting
* the user language by checking OS Environment variables.
*/
translator?: Translator<any>;
translator?: Translator<Record<string, any>>;

/**
* The flag names to use in this application, if the flags differ in any way from
Expand All @@ -75,7 +95,7 @@ export interface CLIAppOptions {
* * input file for a command: -i, --in
* * output file for a command: -o, --out
*/
flags: CLIGeneralFlags;
flags?: CLIGeneralFlags;
}

/**
Expand All @@ -101,20 +121,16 @@ export class CLICommandBuilder {
protected currentArgs: any[];
protected currentOptions: any;
protected onReadErrorMsg: string;
protected options: CLIAppOptions;
protected options: WithRequired<CLIAppOptions, 'flags'>;
protected isSubcommand: boolean;

public constructor(
cmdrProgram: commander.Command,
options: CLIAppOptions,
isSubcommand: boolean = false
) {
this.program = cmdrProgram;
this.options = Object.assign({}, options);
this.isSubcommand = isSubcommand;

// Set default flags, or use custom ones
this.options.flags = options.flags ?? {
const defaultFlags = {
help: {
short: CLICommandBuilder.SHORT_HELP_FLAG,
long: CLICommandBuilder.LONG_HELP_FLAG
Expand All @@ -136,6 +152,13 @@ export class CLICommandBuilder {
long: CLICommandBuilder.LONG_OUTPUT_FLAG
}
};

this.program = cmdrProgram;
this.options = Object.assign({ ...defaultFlags }, options) as WithRequired<
CLIAppOptions,
'flags'
>;
this.isSubcommand = isSubcommand;
}

/**
Expand Down Expand Up @@ -508,3 +531,20 @@ export type cli = CLIApp;
* @group API: Main
*/
export const cli = (options: CLIAppOptions): CLIApp => new CLIApp(options);

/**
* Retrieves an object with the data from a JSON file
* after reading the same from the command line.
* This function is useful here as most times you will
* want to retrieve data from the package.json file.
*
* @param fileLocation The location of the file to read.
*/
export function readJSON(fileLocation: string): any {
try {
const fileContents = fs.readFileSync(fileLocation);
return JSON.parse(fileContents.toString());
} catch {
return {};
}
}

0 comments on commit 9f9e32e

Please sign in to comment.