libmodulor 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v0.7.0 (2025-03-07)
4
+
5
+ **Added**
6
+
7
+ - Make `npx libmodulor CreateProject` more generic : you can now customize the `initialCommit` (default is `chore: initial commit`), the `pkgManagerBin` (default is `yarn`, works with `npm`, `pnpm`, `bun`, etc.), the `scmBin` (default is `git`)
8
+
9
+ **Fixed**
10
+
11
+ - Derandomize UC input before snapshotting in tests : after the upgrade to TS 5.8, snapshotting a UC including a File as input would break as a new `state` property has appeared with a dynamic `lastModified` property
12
+
13
+ **Misc**
14
+
15
+ - Move the documentation with concepts, examples, guides and references to https://libmodulor.c100k.eu
16
+
3
17
  ## v0.6.1 (2025-02-28)
4
18
 
5
19
  **Fixed**
package/README.md CHANGED
@@ -5,39 +5,17 @@
5
5
 
6
6
  An opinionated TypeScript library to create business oriented applications.
7
7
 
8
- Applications created with `libmodulor` have **6 main properties** :
9
-
10
- - Strictly typed with explicit business data types
11
- - Fully typed e2e without code generation
12
- - Auto documented
13
- - Auto tested
14
- - Multi platforms/runtimes
15
- - Runnable anywhere
16
-
17
8
  > [!WARNING]
18
9
  > The project is still in active development. Although already used in pilot projects, it's not suitable for all production scenarios yet.
19
10
  > Being developed by only one person, it may keep going for years or stop at any time.
20
11
  > In the meantime, it's still a "research project" that needs improvement. Thus, it will be subject to BREAKING CHANGES as long as the version is not `1.0.0`.
21
- > All that said, the end goal is really to have a **production-grade library** to help everyone build **quality projects faster**. If you want to help in any way or have questions, feel free to contact me (cf. `author` in `package.json`).
22
-
23
- > [!NOTE]
24
- > At the beginning, the whole documentation will be on GitHub, starting from this file, to make it easier to have the big picture, maintain and <kbd>cmd</kbd> + <kbd>F</kbd>. At some point, I'll consider having a beautiful documentation website like all the cool kids.
25
-
26
- ---
12
+ > All that said, the end goal is really to have a **production-grade library** to help everyone build **quality projects faster**.
27
13
 
28
14
  ## 🚀 Getting Started
29
15
 
30
- If you're discovering `libmodulor`, we recommend reading the [📖 Introduction](https://github.com/c100k/libmodulor/blob/v0.6.1/docs/Introduction.md) first. It will give you an overview of what `libmodulor` is and how it works.
31
-
32
- If you want to learn by doing, you can follow the [🚀 Tutorial](https://github.com/c100k/libmodulor/blob/v0.6.1/docs/Tutorial.md). It contains multiple steps showing you the basics of `libmodulor`. We'll build a small Trading app that will allow us to buy an asset from `curl`, a SPA, a CLI, Claude Desktop, an Android mobile app and an iOS mobile app !
33
-
34
- If you're felling adventurous, create a project and start building your own application, with your own apps, use cases, products, targets :
35
-
36
- ```sh
37
- npx libmodulor CreateProject --outPath ~/Downloads --projectName libmodulor-projx
38
- ```
16
+ If you're discovering `libmodulor`, we recommend reading the [📖 Documentation](https://libmodulor.c100k.eu/docs) first. You'll find everything you need to get started : Concepts, Examples and Guides.
39
17
 
40
- Finally, for more advanced uses, check out the [📜 Guides](https://github.com/c100k/libmodulor/blob/v0.6.1/docs/Guides.md).
18
+ When you're ready, [🚀 Create a project](https://libmodulor.c100k.eu/docs/guides/create-project) and build the awesome idea you have in mind.
41
19
 
42
20
  ## 👨‍💻 Contribute
43
21
 
@@ -45,4 +23,4 @@ If you think you can help in any way, feel free to contact me (cf. `author` in `
45
23
 
46
24
  ## ⚖️ License
47
25
 
48
- [LGPL-3.0](https://github.com/c100k/libmodulor/blob/v0.6.1/LICENSE)
26
+ [LGPL-3.0](https://github.com/c100k/libmodulor/blob/v0.7.0/LICENSE)
@@ -11,10 +11,13 @@ export const I18n = {
11
11
  uc_TestApp_label: 'Test app',
12
12
  ucif_appPath_desc: 'The path of the app',
13
13
  ucif_appsPath_desc: 'The path to the directory containing all the apps',
14
- ucif_projectName_desc: "Name of the project conforming to the package.json's spec (i.e. a-z, 0-9, -)",
15
- ucif_outPath_desc: 'Path to a directory where to create the project. Do not include the project name in it. It is created recursively if missing.',
16
- ucif_monkeyTestingTimeoutInMs_desc: 'These tests can take longer than the usual default of 5000ms because they try lots of possibilities',
17
14
  ucif_depsMapping_desc: 'The mapping of dependencies in case some of them need a specific pattern (e.g. one directory above the default)',
15
+ ucif_initialCommit_desc: 'The message of the initial commit',
16
+ ucif_monkeyTestingTimeoutInMs_desc: 'These tests can take longer than the usual default of 5000ms because they try lots of possibilities',
17
+ ucif_outPath_desc: 'Path to a directory where to create the project. Do not include the project name in it. It is created recursively if missing.',
18
+ ucif_pkgManagerBin_desc: "The package manager to use to install the deps and run the dev commands (must conform to npm's API)",
19
+ ucif_projectName_desc: "Name of the project conforming to the package.json's spec (i.e. a-z, 0-9, -)",
20
+ ucif_scmBin_desc: "The source control manager to use to init and commit (must conform to git's API)",
18
21
  ucif_serverPortRangeStart_desc: 'The port number to start with when generating the server to test (incremented by 1) for each app',
19
22
  ucif_skipCoverage_desc: 'Whether to skip coverage or not',
20
23
  ucif_updateSnapshots_desc: "Whether to update the snapshots or not. Typically, update them if the tests fail because the snapshots don't match, the reason being that you changed the implementation",
@@ -1,2 +1,3 @@
1
1
  import type { FileName, Slug } from '../../../../dt/index.js';
2
+ export declare const PACKAGE_JSON: (name: Slug) => string;
2
3
  export declare function projectFiles(name: Slug): Map<FileName, string>;
@@ -26,7 +26,7 @@ const BIOME_JSON = `{
26
26
  }
27
27
  }
28
28
  `;
29
- const PACKAGE_JSON = (name) => `{
29
+ export const PACKAGE_JSON = (name) => `{
30
30
  "name": "${name}",
31
31
  "version": "0.1.0",
32
32
  "type": "module",
@@ -42,7 +42,7 @@ const PACKAGE_JSON = (name) => `{
42
42
  },
43
43
  "devDependencies": {
44
44
  "@biomejs/biome": "^1.9.4",
45
- "@types/node": "^22.13.5",
45
+ "@types/node": "^22.13.8",
46
46
  "@vitest/coverage-v8": "^3.0.7",
47
47
  "buffer": "^6.0.3",
48
48
  "cookie-parser": "^1.4.7",
@@ -51,7 +51,7 @@ const PACKAGE_JSON = (name) => `{
51
51
  "fast-check": "^3.23.2",
52
52
  "helmet": "^8.0.0",
53
53
  "jose": "^6.0.8",
54
- "typescript": "^5.7.3",
54
+ "typescript": "^5.8.2",
55
55
  "vite": "^6.2.0",
56
56
  "vitest": "^3.0.7"
57
57
  }
@@ -1,9 +1,12 @@
1
- import { type DirPath, type Slug } from '../../../../dt/index.js';
1
+ import { type DirPath, type FileName, type FreeTextShort, type Slug } from '../../../../dt/index.js';
2
2
  import type { FSManager, Logger, ShellCommandExecutor } from '../../../../std/index.js';
3
3
  import { type UCDef, type UCInput, type UCInputFieldValue, type UCMain, type UCMainInput } from '../../../../uc/index.js';
4
4
  export interface CreateProjectInput extends UCInput {
5
+ initialCommit: UCInputFieldValue<FreeTextShort>;
5
6
  outPath: UCInputFieldValue<DirPath>;
7
+ pkgManagerBin: UCInputFieldValue<FileName>;
6
8
  projectName: UCInputFieldValue<Slug>;
9
+ scmBin: UCInputFieldValue<FileName>;
7
10
  }
8
11
  export declare class CreateProjectClientMain implements UCMain<CreateProjectInput> {
9
12
  private fsManager;
@@ -11,5 +14,13 @@ export declare class CreateProjectClientMain implements UCMain<CreateProjectInpu
11
14
  private shellCommandExecutor;
12
15
  constructor(fsManager: FSManager, logger: Logger, shellCommandExecutor: ShellCommandExecutor);
13
16
  exec({ uc }: UCMainInput<CreateProjectInput>): Promise<void>;
17
+ private assertBinPresence;
18
+ private commit;
19
+ private createConfigFiles;
20
+ private createDirs;
21
+ private createRootDir;
22
+ private initRepository;
23
+ private installDeps;
24
+ private runDevCmds;
14
25
  }
15
26
  export declare const CreateProjectUCD: UCDef<CreateProjectInput>;
@@ -12,7 +12,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  };
13
13
  import { inject, injectable } from 'inversify';
14
14
  import { APPS_ROOT_PATH, PRODUCTS_ROOT_PATH } from '../../../../convention.js';
15
- import { TDirPath, TSlug, } from '../../../../dt/index.js';
15
+ import { TDirPath, TFileName, TFreeTextShort, TSlug, } from '../../../../dt/index.js';
16
+ import { IllegalArgumentError } from '../../../../error/index.js';
16
17
  import { EverybodyUCPolicy, } from '../../../../uc/index.js';
17
18
  import { projectFiles } from '../lib/project.js';
18
19
  import { Manifest } from '../manifest.js';
@@ -26,55 +27,95 @@ let CreateProjectClientMain = class CreateProjectClientMain {
26
27
  this.shellCommandExecutor = shellCommandExecutor;
27
28
  }
28
29
  async exec({ uc }) {
30
+ const initialCommit = uc.reqVal0('initialCommit');
29
31
  const outPath = uc.reqVal0('outPath');
32
+ const pkgManagerBin = uc.reqVal0('pkgManagerBin');
30
33
  const projectName = uc.reqVal0('projectName');
34
+ const scmBin = uc.reqVal0('scmBin');
35
+ await this.assertBinPresence(pkgManagerBin);
36
+ await this.assertBinPresence(scmBin);
31
37
  const cwd = this.fsManager.path(outPath, projectName);
32
- this.logger.info('Creating root dir : %s', cwd);
33
- await this.fsManager.mkdir(cwd, { recursive: true });
34
- this.logger.info('Initializing git repository');
35
- await this.shellCommandExecutor.exec({
36
- bin: 'git',
37
- opts: { args: ['init'], cwd },
38
- });
39
- this.logger.info('Creating config files');
38
+ // TODO : Rollback the whole thing in case of failure
39
+ await this.createRootDir(cwd);
40
+ await this.initRepository(scmBin, cwd);
41
+ await this.createConfigFiles(projectName, cwd);
42
+ await this.createDirs(cwd);
43
+ await this.installDeps(pkgManagerBin, cwd);
44
+ await this.commit(scmBin, initialCommit, cwd);
45
+ await this.runDevCmds(pkgManagerBin, cwd);
46
+ this.logger.info('Done ! Project ready ! ✅ 🚀');
47
+ }
48
+ async assertBinPresence(bin) {
49
+ try {
50
+ await this.shellCommandExecutor.exec({
51
+ bin: bin,
52
+ opts: { args: ['--version'] },
53
+ });
54
+ }
55
+ catch (err) {
56
+ throw new IllegalArgumentError(`'${bin}' seems missing. Is it installed on your machine ?`);
57
+ }
58
+ }
59
+ async commit(scmBin, initialCommit, cwd) {
60
+ this.logger.info('Committing');
61
+ const cmdArgs = [
62
+ ['branch', '-M', 'master'],
63
+ ['add', '.'],
64
+ ['commit', '-am', initialCommit],
65
+ ];
66
+ for await (const args of cmdArgs) {
67
+ await this.shellCommandExecutor.exec({
68
+ bin: scmBin,
69
+ opts: { args, cwd },
70
+ });
71
+ }
72
+ }
73
+ async createConfigFiles(projectName, cwd) {
40
74
  const files = projectFiles(projectName);
41
75
  for await (const [fileName, content] of files) {
42
76
  const path = this.fsManager.path(cwd, fileName);
43
77
  await this.fsManager.touch(path, content);
44
78
  }
45
- const dirs = [APPS_ROOT_PATH, PRODUCTS_ROOT_PATH];
79
+ }
80
+ async createDirs(cwd) {
46
81
  this.logger.info('Creating apps and products directories');
82
+ const dirs = [APPS_ROOT_PATH, PRODUCTS_ROOT_PATH];
47
83
  for await (const dirPath of dirs) {
48
84
  const path = this.fsManager.path(cwd, ...dirPath);
49
85
  await this.fsManager.mkdir(path, { recursive: true });
50
86
  await this.fsManager.touch(this.fsManager.path(path, '.gitkeep'), '');
51
87
  }
52
- this.logger.info('Installing dependencies');
88
+ }
89
+ async createRootDir(cwd) {
90
+ this.logger.info('Creating root dir : %s', cwd);
91
+ await this.fsManager.mkdir(cwd, { recursive: true });
92
+ }
93
+ async initRepository(scmBin, cwd) {
94
+ const cmd = 'init';
95
+ this.logger.info('Initializing repository : %s %s', scmBin, cmd);
53
96
  await this.shellCommandExecutor.exec({
54
- bin: 'yarn',
55
- opts: { args: ['install'], cwd },
97
+ bin: scmBin,
98
+ opts: { args: [cmd], cwd },
56
99
  });
57
- this.logger.info('Committing');
58
- const cmdArgs = [
59
- ['branch', '-M', 'master'],
60
- ['add', '.'],
61
- ['commit', '-am', '"chore: initial commit"'],
62
- ];
63
- for await (const args of cmdArgs) {
64
- await this.shellCommandExecutor.exec({
65
- bin: 'git',
66
- opts: { args, cwd },
67
- });
68
- }
69
- const devCmds = ['lint', 'test'];
70
- for await (const cmd of devCmds) {
71
- this.logger.info('Testing dev command : yarn %s', cmd);
100
+ }
101
+ async installDeps(pkgManagerBin, cwd) {
102
+ const cmd = 'install';
103
+ this.logger.info('Installing dependencies : %s %s', pkgManagerBin, cmd);
104
+ await this.shellCommandExecutor.exec({
105
+ bin: pkgManagerBin,
106
+ opts: { args: [cmd], cwd },
107
+ });
108
+ }
109
+ async runDevCmds(pkgManagerBin, cwd) {
110
+ const cmd = 'run';
111
+ const scripts = ['lint', 'test'];
112
+ for await (const script of scripts) {
113
+ this.logger.info('Running dev command : %s %s %s', pkgManagerBin, cmd, script);
72
114
  await this.shellCommandExecutor.exec({
73
- bin: 'yarn',
74
- opts: { args: [cmd], cwd },
115
+ bin: pkgManagerBin,
116
+ opts: { args: [cmd, script], cwd },
75
117
  });
76
118
  }
77
- this.logger.info('Done ! Project ready ! ✅ 🚀');
78
119
  }
79
120
  };
80
121
  CreateProjectClientMain = __decorate([
@@ -94,6 +135,14 @@ export const CreateProjectUCD = {
94
135
  io: {
95
136
  i: {
96
137
  fields: {
138
+ initialCommit: {
139
+ cardinality: {
140
+ min: 0,
141
+ },
142
+ type: new TFreeTextShort()
143
+ .setDefaultValue('chore: initial commit')
144
+ .setExamples(['chore: initial commit']),
145
+ },
97
146
  outPath: {
98
147
  cardinality: {
99
148
  min: 0,
@@ -102,9 +151,25 @@ export const CreateProjectUCD = {
102
151
  .setDefaultValue('./')
103
152
  .setExamples([['~', 'Desktop'].join('/')]),
104
153
  },
154
+ pkgManagerBin: {
155
+ cardinality: {
156
+ min: 0,
157
+ },
158
+ type: new TFileName()
159
+ .setDefaultValue('yarn')
160
+ .setExamples(['bun', 'npm', 'pnpm', 'yarn']),
161
+ },
105
162
  projectName: {
106
163
  type: new TSlug(),
107
164
  },
165
+ scmBin: {
166
+ cardinality: {
167
+ min: 0,
168
+ },
169
+ type: new TFileName()
170
+ .setDefaultValue('git')
171
+ .setExamples(['git']),
172
+ },
108
173
  },
109
174
  },
110
175
  },
@@ -21,7 +21,7 @@ let NodeSpawnShellCommandExecutor = class NodeSpawnShellCommandExecutor {
21
21
  proc.stdout.on('data', (chunk) => {
22
22
  stdout += chunk;
23
23
  });
24
- proc.stdout.on('error', (err) => {
24
+ proc.on('error', (err) => {
25
25
  reject(err);
26
26
  });
27
27
  proc.on('close', (code, signal) => {
@@ -42,4 +42,6 @@ export declare class UCExecutor implements Worker<Input, Promise<Output>> {
42
42
  exec<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>({ appManifest, auth, authName, inputFiller, inputFillerName, ucd, }: Input<I, OPI0, OPI1>): Promise<Output<I, OPI0, OPI1>>;
43
43
  overrideUCManager(ucManager: UCManager): void;
44
44
  private execClient;
45
+ private derandomizeInput;
46
+ private derandomizeInputFile;
45
47
  }
@@ -83,6 +83,36 @@ let UCExecutor = class UCExecutor {
83
83
  catch (err) {
84
84
  out.err = err;
85
85
  }
86
+ finally {
87
+ this.derandomizeInput(out.io.i);
88
+ }
89
+ }
90
+ derandomizeInput(input) {
91
+ for (const [k, v] of Object.entries(input)) {
92
+ if (Array.isArray(v)) {
93
+ v.forEach((vv, idx) => {
94
+ if (vv instanceof File) {
95
+ // @ts-ignore
96
+ input[k][idx] = this.derandomizeInputFile(vv);
97
+ }
98
+ });
99
+ }
100
+ else if (v instanceof File) {
101
+ // @ts-ignore
102
+ input[k] = this.derandomizeInputFile(v);
103
+ }
104
+ }
105
+ }
106
+ derandomizeInputFile(file) {
107
+ // Since TypeScript 5.8, a new `lastModified` field has appeared in `File.state: FileState {}` when snapshotting.
108
+ // The problem is that this value is a timestamp that changes everytime we execute the tests.
109
+ // Creating a `specificAssertion` just for that would be cumbersome.
110
+ // Hence the transform of the `File` into a deterministic `Object` for easy snapshotting.
111
+ return {
112
+ name: file.name,
113
+ size: file.size,
114
+ type: file.type,
115
+ };
86
116
  }
87
117
  };
88
118
  UCExecutor = UCExecutor_1 = __decorate([
package/package.json CHANGED
@@ -1,12 +1,22 @@
1
1
  {
2
2
  "name": "libmodulor",
3
3
  "description": "An opinionated TypeScript library to create business oriented applications",
4
- "version": "0.6.1",
4
+ "version": "0.7.0",
5
5
  "license": "LGPL-3.0",
6
6
  "author": "Chafik H'nini <chafik.hnini@gmail.com>",
7
7
  "homepage": "https://github.com/c100k/libmodulor#readme",
8
8
  "bugs": "https://github.com/c100k/libmodulor/issues",
9
- "keywords": ["library", "typescript", "business application", "use case", "app", "product", "target", "auto-test", "auto-documentation"],
9
+ "keywords": [
10
+ "library",
11
+ "typescript",
12
+ "business application",
13
+ "use case",
14
+ "app",
15
+ "product",
16
+ "target",
17
+ "auto-test",
18
+ "auto-documentation"
19
+ ],
10
20
  "type": "module",
11
21
  "module": "./dist/esm/index.js",
12
22
  "exports": {
@@ -54,9 +64,16 @@
54
64
  }
55
65
  },
56
66
  "bin": "./dist/esm/products/Helper/index.js",
67
+ "scripts": {
68
+ "lint": "biome check --write .",
69
+ "lint:ci": "biome check"
70
+ },
71
+ "devDependencies": {
72
+ "@biomejs/biome": "^1.9.4"
73
+ },
57
74
  "peerDependencies": {
58
75
  "@hono/node-server": "^1.13.8",
59
- "@modelcontextprotocol/sdk": "^1.6.0",
76
+ "@modelcontextprotocol/sdk": "^1.6.1",
60
77
  "@stricli/core": "^1.1.1",
61
78
  "buffer": "^6.0.3",
62
79
  "cookie-parser": "^1.4.7",
@@ -74,7 +91,7 @@
74
91
  "react-native": "^0.78.0",
75
92
  "reflect-metadata": "^0.2.2",
76
93
  "sqlite3": "^5.1.7",
77
- "typescript": "^5.7.3",
94
+ "typescript": "^5.8.2",
78
95
  "vite": "^6.2.0",
79
96
  "vitest": "^3.0.7"
80
97
  },
@@ -1,16 +0,0 @@
1
- ---
2
- name: Generic Issue
3
- about: Describe this issue template's purpose here.
4
- title: ''
5
- labels: ''
6
- assignees: ''
7
-
8
- ---
9
-
10
- ## Problem
11
-
12
- <!-- State the problem clearly with as much details as you can. It can be a new feature request or a bug. Either way, there should be a clear problem -->
13
-
14
- ## Potential Solution(s)
15
-
16
- <!-- If you have ideas, feel free to suggest them, we love it. We'll discuss the solutions and find the best one for everyone -->
@@ -1,19 +0,0 @@
1
- # To get started with Dependabot version updates, you'll need to specify which
2
- # package ecosystems to update and where the package manifests are located.
3
- # Please see the documentation for all configuration options:
4
- # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
-
6
- version: 2
7
- updates:
8
- - package-ecosystem: "npm"
9
- directory: "/"
10
- schedule:
11
- interval: "weekly"
12
- ignore:
13
- - dependency-name: "inversify"
14
- versions: ["7.x"]
15
- groups:
16
- dev:
17
- dependency-type: "development"
18
- prod:
19
- dependency-type: "production"