fix: build

This commit is contained in:
2023-03-14 18:04:29 +01:00
parent 3792a14e90
commit fd740b3091
185 changed files with 21932 additions and 71486 deletions

View File

@@ -1,102 +1,3 @@
{
"root": true,
"ignorePatterns": [
"projects/**/*"
],
"overrides": [
{
"files": [
"*.ts"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"project": [
"tsconfig.json"
],
"createDefaultProgram": true
},
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"plugin:prettier/recommended",
"plugin:jsdoc/recommended",
"plugin:unicorn/recommended"
],
"plugins": [
"eslint-plugin-unicorn",
"eslint-plugin-jsdoc",
"prettier"
],
"settings": {
"jsdoc": {
"mode": "typescript"
}
},
"rules": {
"unicorn/filename-case": "error",
"unicorn/no-array-callback-reference": "off",
"unicorn/no-useless-undefined": "off",
"unicorn/prefer-node-protocol": "off",
"unicorn/no-process-exit": "off",
"unicorn/prevent-abbreviations": [
"error",
{
"replacements": {
"ref": false,
"i": false
}
}
],
"unicorn/no-nested-ternary": "off",
"unicorn/better-regex": "off",
"jsdoc/no-types": "error",
"jsdoc/require-param": "off",
"jsdoc/require-param-description": "error",
"jsdoc/check-param-names": "error",
"jsdoc/require-returns": "off",
"jsdoc/require-param-type": "off",
"jsdoc/require-returns-type": "off",
"jsdoc/check-tag-names": [
"error",
{
"definedTags": ["internal"]
}
],
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"args": "after-used",
"argsIgnorePattern": "^_"
}
],
"@typescript-eslint/lines-between-class-members": [
"error",
"always"
],
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-non-null-assertion": "off",
"prettier/prettier": [
"error",
{
"tabWidth": 2,
"printWidth": 110,
"useTabs": false,
"semi": true,
"singleQuote": true,
"quoteProps": "consistent",
"trailingComma": "all",
"bracketSpacing": false,
"arrowParens": "avoid",
"endOfLine": "lf"
}
]
}
}
]
"extends": "@openstapps"
}

View File

@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('./lib/cli.js')

File diff suppressed because it is too large Load Diff

View File

@@ -1,51 +1,43 @@
{
"name": "@openstapps/core-tools",
"version": "0.34.0",
"description": "Tools to convert and validate StAppsCore",
"keywords": [
"converter",
"core",
"StApps",
"StAppsCore",
"validator"
],
"repository": {
"type": "git",
"url": "git@gitlab.com:openstapps/core-tools.git"
},
"version": "2.1.0",
"license": "GPL-3.0-only",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"bin": {
"openstapps-core-tools": "./lib/cli.js"
},
"repository": "git@gitlab.com:openstapps/core-tools.git",
"author": "Karl-Philipp Wulfert <krlwlfrt@gmail.com>",
"contributors": [
"Anselm Stordeur <anselmstordeur@gmail.com>",
"Jovan Krunić <jovan.krunic@gmail.com>",
"Rainer Killinger <mail-openstapps@killinger.co>",
"Michel Jonathan Schmitz",
"Rainer Killinger <mail-openstapps@killinger.co>",
"Thea Schöbl <dev@theaninova.de>"
],
"prettier": "@openstapps",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"bin": {
"openstapps-core-tools": "app.js"
},
"scripts": {
"build": "npm run lint && npm run compile",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
"check-configuration": "openstapps-configuration",
"compile": "rimraf lib && tsc && prepend lib/cli.js '#!/usr/bin/env node\n'",
"compile": "rimraf lib && tsc",
"documentation": "typedoc --out docs --readme README.md --includeVersion --validation.invalidLink true --entryPointStrategy expand src",
"plantuml-start": "docker run --name plantuml-server -d -p 8080:8080 registry.gitlab.com/openstapps/core-tools:latest",
"lint": "eslint -c .eslintrc.json --ignore-path .eslintignore --ext .ts src/",
"lint:fix": "eslint --fix -c .eslintrc.json --ignore-path .eslintignore --ext .ts src/",
"plantuml-restart": "docker restart plantuml-server",
"plantuml-start": "docker run --name plantuml-server -d -p 8080:8080 registry.gitlab.com/openstapps/core-tools:latest",
"plantuml-stop": "docker stop plantuml-server",
"version": "npm run changelog",
"prepublishOnly": "npm ci && npm run build",
"preversion": "npm run prepublishOnly",
"push": "git push && git push origin \"v$npm_package_version\"",
"test": "mocha --require ts-node/register test/*.spec.ts",
"lint:fix": "eslint --fix -c .eslintrc.json --ignore-path .eslintignore --ext .ts src/",
"lint": "eslint -c .eslintrc.json --ignore-path .eslintignore --ext .ts src/"
"version": "npm run changelog"
},
"dependencies": {
"@openstapps/logger": "1.1.1",
"@openstapps/collection-utils": "workspace:*",
"@openstapps/logger": "workspace:*",
"ajv": "8.12.0",
"better-ajv-errors": "1.2.0",
"chai": "4.3.7",
@@ -56,10 +48,9 @@
"flatted": "3.2.7",
"fs-extra": "10.1.0",
"glob": "8.1.0",
"got": "11.8.6",
"got": "12.6.0",
"humanize-string": "3.0.0",
"json-schema": "0.4.0",
"lodash": "4.17.21",
"mustache": "4.2.0",
"openapi-types": "12.1.0",
"plantuml-encoder": "1.4.0",
@@ -69,16 +60,17 @@
"ts-node": "10.9.1"
},
"devDependencies": {
"@openstapps/configuration": "0.34.0",
"@openstapps/configuration": "workspace:*",
"@openstapps/eslint-config": "workspace:*",
"@openstapps/prettier-config": "workspace:*",
"@testdeck/mocha": "0.3.3",
"@types/chai": "4.3.4",
"@types/fs-extra": "9.0.13",
"@types/glob": "8.0.1",
"@types/json-schema": "7.0.11",
"@types/lodash": "4.14.191",
"@types/mocha": "10.0.1",
"@types/mustache": "4.2.2",
"@types/node": "14.18.36",
"@types/node": "18.15.3",
"@types/rimraf": "3.0.2",
"@typescript-eslint/eslint-plugin": "5.49.0",
"@typescript-eslint/parser": "5.49.0",
@@ -89,10 +81,16 @@
"eslint-plugin-unicorn": "45.0.2",
"mocha": "10.2.0",
"nock": "13.3.0",
"prepend-file-cli": "1.0.6",
"prettier": "2.8.3",
"rimraf": "3.0.2",
"rimraf": "4.4.0",
"typedoc": "0.22.18",
"typescript": "4.4.4"
}
},
"keywords": [
"StApps",
"StAppsCore",
"converter",
"core",
"validator"
]
}

View File

@@ -12,7 +12,6 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {first, last, tail, filter} from 'lodash';
import {
ArrayTypeNode,
ClassDeclaration,
@@ -44,22 +43,22 @@ import {LightweightComment} from './types/lightweight-comment';
/** @internal */
export function extractComment(node: ts.Node): LightweightComment | undefined {
const jsDocument = last(
const jsDocuments =
// @ts-expect-error jsDoc exists in reality
node.jsDoc as
| Array<{
comment?: string;
tags?: Array<{comment?: string; tagName?: {escapedText?: string}}>;
}>
| undefined,
);
| undefined;
const jsDocument = jsDocuments?.[jsDocuments.length - 1]
const comment = jsDocument?.comment?.split('\n\n');
return jsDocument === undefined
? undefined
: cleanupEmpty({
shortSummary: first(comment),
description: tail(comment)?.join('\n\n'),
shortSummary: comment?.[0],
description: comment?.[comment.length - 1],
tags: jsDocument?.tags?.map(tag =>
cleanupEmpty({
name: tag.tagName?.escapedText ?? 'UNRESOLVED_NAME',
@@ -81,7 +80,7 @@ export function filterNodeTo<T extends ts.Node, S extends T>(
node: NodeArray<T>,
check: (node: T) => node is S,
): S[] {
return filter(node, check);
return node.filter(check);
}
/** @internal */

View File

@@ -13,7 +13,6 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {flatMap, keyBy, isEmpty} from 'lodash';
import {TypeFlags} from 'typescript';
import {LightweightAliasDefinition} from './types/lightweight-alias-definition';
import {LightweightClassDefinition} from './types/lightweight-class-definition';
@@ -21,6 +20,7 @@ import {LightweightDefinition} from './types/lightweight-definition';
import {LightweightDefinitionKind} from './types/lightweight-definition-kind';
import {LightweightProject} from './types/lightweight-project';
import {LightweightType} from './types/lightweight-type';
import {keyBy} from "@openstapps/collection-utils/lib/key-by";
/**
* Creates a printable name of a type
@@ -35,7 +35,7 @@ export function expandTypeValue(type: LightweightType): string | undefined {
if (isUnionOrIntersectionType(type)) {
return type.specificationTypes?.map(expandTypeValue).join(isUnionType(type) ? ' | ' : ' & ');
}
if (isEmpty(type.genericsTypes)) {
if (type.genericsTypes?.length === 0) {
return `${type.value}<${type.genericsTypes?.map(expandTypeValue).join(', ')}>`;
}
@@ -43,7 +43,7 @@ export function expandTypeValue(type: LightweightType): string | undefined {
}
export function definitionsOf(project: LightweightProject): Record<string, LightweightDefinition> {
return keyBy(flatMap(project, Object.values), 'name');
return keyBy(Object.values(project).flatMap(Object.values), it => it.name);
}
export function isPrimitiveType(type: {flags: TypeFlags}): boolean {

View File

@@ -13,7 +13,6 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {flatMap, groupBy, keyBy, mapValues} from 'lodash';
import * as ts from 'typescript';
import {
ClassDeclaration,
@@ -62,6 +61,9 @@ import {LightweightProject} from './types/lightweight-project';
import {LightweightType} from './types/lightweight-type';
import path from 'path';
import {LightweightProperty} from './types/lightweight-property';
import {mapValues} from "@openstapps/collection-utils/lib/map-values";
import {groupBy} from "@openstapps/collection-utils/lib/group-by";
import {keyBy} from "@openstapps/collection-utils/lib/key-by";
/**
* Convert a TypeScript project to a lightweight Type-AST representation of the project
@@ -142,8 +144,8 @@ class LightweightDefinitionBuilder {
private convertClassLike(classLike: ClassDeclaration | InterfaceDeclaration): LightweightClassDefinition {
const heritages = mapValues(
groupBy(classLike.heritageClauses, it => it.token),
heritages => flatMap(heritages, it => it.types),
groupBy([...(classLike.heritageClauses!)], it => it.token.toString()),
heritages => heritages.flatMap(it => it.types),
);
return cleanupEmpty({
@@ -252,7 +254,7 @@ class LightweightDefinitionBuilder {
*/
convert(): LightweightProject {
return mapValues(
keyBy(this.sourceFiles, it => it.fileName),
keyBy([...this.sourceFiles], it => it.fileName),
file =>
keyBy(
[
@@ -268,6 +270,6 @@ class LightweightDefinitionBuilder {
* Same as conversion, but generates a simple list of all definitions.
*/
convertToList(): LightweightDefinition[] {
return flatMap(this.convert(), it => it.values);
return Object.values(this.convert()).flatMap(it => it.values);
}
}

View File

@@ -12,7 +12,6 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {assign, cloneDeep, flatMap, fromPairs, trimEnd} from 'lodash';
import {mapNotNil} from '../../util/collections';
import {definitionsOf, isLightweightClass} from '../ast-util';
import {lightweightProjectFromPath} from '../easy-ast';
@@ -23,8 +22,8 @@ import {LightweightDefinition} from './lightweight-definition';
* Build an index for a lightweight project
*/
function buildIndex(project: LightweightProject): Record<string, string> {
return fromPairs(
flatMap(project, (definitions, file) => Object.keys(definitions).map(definition => [definition, file])),
return Object.fromEntries(
Object.values(project).flatMap((definitions, file) => Object.keys(definitions).map(definition => [definition, file.toString()]))
);
}
@@ -59,7 +58,7 @@ export class LightweightProjectWithIndex {
* Apply inherited classes; default deeply
*/
applyInheritance(classLike: LightweightClassDefinition, deep?: boolean): LightweightDefinition {
return assign(
return Object.assign(
mapNotNil(
[...(classLike.implementedDefinitions ?? []), ...(classLike.extendedDefinitions ?? [])],
extension => {
@@ -67,10 +66,10 @@ export class LightweightProjectWithIndex {
return (deep ?? true) && isLightweightClass(object)
? this.applyInheritance(object)
: cloneDeep(object);
: JSON.parse(JSON.stringify(object));
},
),
cloneDeep(classLike),
JSON.parse(JSON.stringify(classLike)),
);
}
@@ -85,7 +84,7 @@ export class LightweightProjectWithIndex {
return undefined;
}
const module = await import(findCompiledModule ? `${trimEnd(fsPath, 'd.ts')}.js` : fsPath);
const module = await import(findCompiledModule ? `${fsPath.replace(/\.d\.ts$/, '')}.js` : fsPath);
return new module[name]() as T;
}

View File

@@ -22,6 +22,7 @@ import {JavaScriptModule} from './types/pack';
import path from 'path';
const PACK_IDENTIFIER = '/* PACKED BY @openstapps/pack */';
const posixCwd = cwd().replaceAll(path.win32.sep, path.posix.sep)
/**
* Pack cli.js
@@ -93,11 +94,11 @@ async function packCliJs(): Promise<void> {
* Get a list containing the contents of all type definition files
*/
async function getAllTypeDefinitions(): Promise<string[]> {
const fileNames = await globPromisified(path.join(cwd(), '*(lib|src)', '**', '*.d.ts'), {
const fileNames = await globPromisified(path.posix.join(posixCwd, '*(lib|src)', '**', '*.d.ts'), {
ignore: [
path.join(cwd(), 'lib', 'doc', '**', '*.d.ts'),
path.join(cwd(), 'lib', 'test', '**', '*.d.ts'),
path.join(cwd(), 'lib', 'cli.d.ts'),
path.posix.join(posixCwd, 'lib', 'doc', '**', '*.d.ts'),
path.posix.join(posixCwd, 'lib', 'test', '**', '*.d.ts'),
path.posix.join(posixCwd, 'lib', 'cli.d.ts'),
],
});
@@ -142,7 +143,7 @@ async function packTypeDefinitions(): Promise<void> {
}
// match import lines
const match = line.match(/^import {([^}].*)} from '([^'].*)';$/);
const match = line.match(/^import\s+{\s*([^}].*)\s*}\s+from\s+['"]([^'"].*)['"];$/);
if (match !== null) {
const module = match[2];
@@ -204,11 +205,11 @@ ${allDefinitions}`,
* Get all JavaScript modules
*/
async function getAllJavaScriptModules(): Promise<JavaScriptModule[]> {
const fileNames = await globPromisified(path.join(cwd(), 'lib', '**', '*.js'), {
const fileNames = await globPromisified(path.posix.join(posixCwd, 'lib', '**', '*.js'), {
ignore: [
path.join(cwd(), 'lib', 'doc', '**', '*.js'),
path.join(cwd(), 'lib', 'test', '*.js'),
path.join(cwd(), 'lib', 'cli.js'),
path.posix.join(posixCwd, 'lib', 'doc', '**', '*.js'),
path.posix.join(posixCwd, 'lib', 'test', '*.js'),
path.posix.join(posixCwd, 'lib', 'cli.js'),
],
});

View File

@@ -12,13 +12,12 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {omitBy, isNil, reject, isEmpty, isArray, isObject} from 'lodash';
/**
* Filters only defined elements
*/
export function rejectNil<T>(array: Array<T | undefined | null>): T[] {
return reject(array, isNil) as T[];
// eslint-disable-next-line unicorn/no-null
return array.filter(it => it == null) as T[];
}
/**
@@ -33,5 +32,13 @@ export function mapNotNil<T, S>(array: readonly T[], transform: (element: T) =>
*/
// eslint-disable-next-line @typescript-eslint/ban-types
export function cleanupEmpty<T extends object>(object: T): T {
return omitBy(object, it => isNil(it) || ((isObject(it) || isArray(it)) && isEmpty(it))) as T;
const out = {} as T;
for (const key in object) {
const value = object[key]
// eslint-disable-next-line unicorn/no-null
if (value != null && (typeof value !== 'object' || Object.values(value).length > 0)) {
out[key] = value
}
}
return out;
}

View File

@@ -13,7 +13,6 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {readdirSync, statSync} from 'fs';
import {flatMap} from 'lodash';
import path from 'path';
/**
@@ -24,9 +23,9 @@ export function expandPathToFilesSync(sourcePath: string, accept: (fileName: str
const directory = statSync(fullPath);
return directory.isDirectory()
? flatMap(readdirSync(fullPath), fragment =>
? readdirSync(fullPath).flatMap(fragment =>
expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
)
)
: [fullPath].filter(accept);
}