Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/access-protection/jitar.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"source": "./dist",
"target": "./build"
"source": "./build",
"target": "./dist"
}
2 changes: 1 addition & 1 deletion examples/access-protection/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions":
{
"rootDir": "./src",
"outDir": "./dist"
"outDir": "./build"
},
"include": ["./src"]
}
4 changes: 2 additions & 2 deletions examples/data-transportation/jitar.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"source": "./dist",
"target": "./build"
"source": "./build",
"target": "./dist"
}
2 changes: 1 addition & 1 deletion examples/data-transportation/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions":
{
"rootDir": "./src",
"outDir": "./dist"
"outDir": "./build"
},
"include": ["./src"]
}
4 changes: 2 additions & 2 deletions examples/error-handling/jitar.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"source": "./dist",
"target": "./build"
"source": "./build",
"target": "./dist"
}
2 changes: 1 addition & 1 deletion examples/error-handling/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions":
{
"rootDir": "./src",
"outDir": "./dist"
"outDir": "./build"
},
"include": ["./src"]
}
4 changes: 2 additions & 2 deletions examples/health-checks/jitar.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"source": "./dist",
"target": "./build"
"source": "./build",
"target": "./dist"
}
2 changes: 1 addition & 1 deletion examples/health-checks/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions":
{
"rootDir": "./src",
"outDir": "./dist"
"outDir": "./build"
},
"include": ["./src"]
}
4 changes: 2 additions & 2 deletions examples/hello-world/jitar.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"source": "./dist",
"target": "./build"
"source": "./build",
"target": "./dist"
}
2 changes: 1 addition & 1 deletion examples/hello-world/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions":
{
"rootDir": "./src",
"outDir": "./dist"
"outDir": "./build"
},
"include": ["./src"]
}
4 changes: 2 additions & 2 deletions examples/load-balancing/jitar.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"source": "./dist",
"target": "./build"
"source": "./build",
"target": "./dist"
}
2 changes: 1 addition & 1 deletion examples/load-balancing/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions":
{
"rootDir": "./src",
"outDir": "./dist"
"outDir": "./build"
},
"include": ["./src"]
}
4 changes: 2 additions & 2 deletions examples/middleware/jitar.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"source": "./dist",
"target": "./build"
"source": "./build",
"target": "./dist"
}
2 changes: 1 addition & 1 deletion examples/middleware/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions":
{
"rootDir": "./src",
"outDir": "./dist"
"outDir": "./build"
},
"include": ["./src"]
}
4 changes: 2 additions & 2 deletions examples/multi-version/jitar.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"source": "./dist",
"target": "./build"
"source": "./build",
"target": "./dist"
}
2 changes: 1 addition & 1 deletion examples/multi-version/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions":
{
"rootDir": "./src",
"outDir": "./dist"
"outDir": "./build"
},
"include": ["./src"]
}
4 changes: 2 additions & 2 deletions examples/resources/jitar.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": "./dist",
"target": "./build",
"source": "./build",
"target": "./dist",
"segments": "./segments",
"resources": "./resources"
}
2 changes: 1 addition & 1 deletion examples/resources/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions":
{
"rootDir": "./src",
"outDir": "./dist"
"outDir": "./build"
},
"include": ["./src"]
}
4 changes: 2 additions & 2 deletions examples/segmentation/jitar.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"source": "./dist",
"target": "./build",
"source": "./build",
"target": "./dist",
"segments": "./segments"
}
2 changes: 1 addition & 1 deletion examples/segmentation/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions":
{
"rootDir": "./src",
"outDir": "./dist"
"outDir": "./build"
},
"include": ["./src"]
}
23 changes: 11 additions & 12 deletions packages/analysis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ For more information about Jitar:
* [Visit our website](https://jitar.dev)
* [Read the documentation](https://docs.jitar.dev).

## Known limitations
## TOOLS

1. Declaration of multiple values is not supported
Two tools are provided:

```ts
// Supported
const a = 1;
export { a }
* **Reflector** - Extensive reflection (modules, classes, functions, objects and instances)
* **Parser** - Code parsing (modules, statements, imports, exports, variables, functions and classes)

// Unsupported (will be supported)
const b = 2, c = 3;
export { b, c }
```
Both tools return a shared based on the ECMAScript specification, but tailored to the Jitar runtime.

## KNOWN LIMITATIONS

The limitations below belong to the parser.

2. Generator as object properties are not supported
1. Generator as object properties are not supported

```ts
// Supported
Expand All @@ -45,7 +44,7 @@ class Bar
}
```

3. Destructuring not fully supported
2. Destructuring not fully supported

```ts
// Supported
Expand Down
7 changes: 7 additions & 0 deletions packages/build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ For more information about Jitar:

* [Visit our website](https://jitar.dev)
* [Read the documentation](https://docs.jitar.dev).

## CONTENT

Two tools are provided:

* **BuildHelper** - Generates and returns module and segment code on request.
* **BuildManager** - Rewrites the whole application to the target folder.
22 changes: 21 additions & 1 deletion packages/build/src/BuildHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import type { RuntimeConfiguration } from '@jitar/configuration';
import { Files, LocalFileManager } from '@jitar/sourcing';

import { Application, ApplicationReader } from './source';
import { LocalModuleGenerator, RemoteModuleGenerator } from './target';
import { LocalModuleGenerator, RemoteModuleGenerator, SegmentGenerator } from './target';
import { FileHelper } from './utils';

import ApplicationNotRead from './errors/ApplicationNotRead';
import ApplicationModuleNotFound from './errors/ApplicationModuleNotFound';
import ApplicationSegmentNotFound from './errors/ApplicationSegmentNotFound';

import ProjectFileManager from './ProjectFileManager';

Expand Down Expand Up @@ -91,4 +92,23 @@ export default class BuildHelper

return generator.generate();
}

generateSegmentCode(segmentName: string): string
{
if (this.#application === undefined)
{
throw new ApplicationNotRead();
}

const segment = this.#application.segmentation.getSegment(segmentName);

if (segment === undefined)
{
throw new ApplicationSegmentNotFound(segmentName);
}

const generator = new SegmentGenerator(segment);

return generator.generate();
}
}
25 changes: 17 additions & 8 deletions packages/build/src/BuildManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { ApplicationReader } from './source';
import { ApplicationBuilder } from './target';
import { FileHelper } from './utils';

import BuildFailed from './errors/BuildFailed';

import ProjectFileManager from './ProjectFileManager';

export default class BuildManager
Expand Down Expand Up @@ -43,16 +45,23 @@ export default class BuildManager

async build(): Promise<void>
{
const sourceFileManager = this.#fileManager.source;
const resourceFileManager = this.#fileManager.resource;
const segmentFileManager = this.#fileManager.segment;
try
{
const sourceFileManager = this.#fileManager.source;
const resourceFileManager = this.#fileManager.resource;
const segmentFileManager = this.#fileManager.segment;

const moduleFiles = await sourceFileManager.filterWithIgnores(Files.MODULE_PATTERN, this.#fileManager.sourceIgnores);
const resourceFiles = await resourceFileManager.filter(Files.RESOURCE_PATTERN);
const segmentFiles = await segmentFileManager.filter(Files.SEGMENT_PATTERN);
const moduleFiles = await sourceFileManager.filterWithIgnores(Files.MODULE_PATTERN, this.#fileManager.sourceIgnores);
const resourceFiles = await resourceFileManager.filter(Files.RESOURCE_PATTERN);
const segmentFiles = await segmentFileManager.filter(Files.SEGMENT_PATTERN);

const applicationModel = await this.#applicationReader.read(moduleFiles, resourceFiles, segmentFiles);
const applicationModel = await this.#applicationReader.read(moduleFiles, resourceFiles, segmentFiles);

return this.#applicationBuilder.build(applicationModel);
await this.#applicationBuilder.build(applicationModel);
}
catch (error: unknown)
{
throw new BuildFailed(error);
}
}
}
8 changes: 8 additions & 0 deletions packages/build/src/errors/ApplicationSegmentNotFound.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export default class ApplicationSegmentNotFound extends Error
{
constructor(segmentName: string)
{
super(`Application segment not found '${segmentName}'`);
}
}
8 changes: 8 additions & 0 deletions packages/build/src/errors/BuildFailed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export default class BuildFailed extends Error
{
constructor(cause: unknown)
{
super('Build failed', { cause });
}
}
2 changes: 1 addition & 1 deletion packages/build/src/source/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

export { Application, ApplicationReader } from './application';
export { Module } from './module';
export { Segment, SegmentModule, SegmentImplementation, Segmentation } from './segment';
export { Segment, SegmentModule, SegmentMember, SegmentClass, SegmentImplementation, Segmentation } from './segment';
export { ResourcesList } from './resource';
8 changes: 3 additions & 5 deletions packages/build/src/source/module/Reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import { Parser } from '@jitar/analysis';
import type { FileManager } from '@jitar/sourcing';

import FileNotLoaded from './errors/FileNotLoaded';

import ReadingModuleFailed from './errors/ReadingModuleFailed';
import Module from './models/Module';
import Repository from './models/Repository';

import LocationRewriter from './LocationRewriter';

export default class Reader
Expand Down Expand Up @@ -44,9 +44,7 @@ export default class Reader
}
catch (error: unknown)
{
const message = error instanceof Error ? error.message : String(error);

throw new FileNotLoaded(filename, message);
throw new ReadingModuleFailed(filename, error);
}
}

Expand Down
8 changes: 0 additions & 8 deletions packages/build/src/source/module/errors/FileNotLoaded.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export default class ReadingModuleFailed extends Error
{
constructor(filename: string, cause: unknown)
{
super(`Failed reading module from '${filename}'`, { cause });
}
}
Loading
Loading