Skip to content

Commit 8554d19

Browse files
committed
chore: update imports and add IntentCliFileTransformer
- Updated import paths in the intent file to use new aliasing. - Added a new IntentCliFileTransformer class for handling intent configuration transformations. - Bumped version of @intentjs/cli to 0.0.20. - Introduced a new constant for the intent CLI file.
1 parent 5601774 commit 8554d19

File tree

8 files changed

+47
-3
lines changed

8 files changed

+47
-3
lines changed

integrations/sample-app/intent

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ import '@intentjs/ts-node/esm';
2020
/**
2121
* Import console commands entrypoint
2222
*/
23-
await import('./bin/console.js');
23+
await import('#bin/console');

integrations/sample-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"homepage": "https://github.com/intentjs/new-app-starter",
1717
"imports": {
18+
"#bin/*": "./bin/*.js",
1819
"#http/*": "./app/http/*.js",
1920
"#models/*": "./app/models/*.js",
2021
"#services/*": "./app/services/*.js",

packages/cli/commands/build.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ConfigurationLoader } from "../lib/configuration/configuration-loader.js";
2+
import { IntentCliFileTransformer } from "../lib/configuration/intent-cli.js";
23
import { INTENT_CONFIG_FILE_NAME } from "../lib/constants.js";
34
import { AssetsManager } from "../lib/dev-server/assets/assets-manager.js";
45
import { defaultSwcOptionsFactory } from "../lib/dev-server/swc/default-options.js";
@@ -38,6 +39,9 @@ export class BuildCommand {
3839
const assetsManager = new AssetsManager();
3940
await assetsManager.handle(TS_CONFIG, INTENT_CONFIG);
4041

42+
const intentCliFileTransformer = new IntentCliFileTransformer();
43+
await intentCliFileTransformer.load(TS_CONFIG);
44+
4145
const SWC_OPTIONS = defaultSwcOptionsFactory(TS_CONFIG, INTENT_CONFIG);
4246
await this.swcFileTransformer.handle(TS_CONFIG, INTENT_CONFIG, SWC_OPTIONS);
4347
}

packages/cli/commands/start-server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { INTENT_CONFIG_FILE_NAME } from "../lib/configuration/constant.js";
1212
import fsExtra from "fs-extra";
1313
import { DevServer } from "../lib/dev-server/dev-server.js";
1414
import { AssetsManager } from "../lib/dev-server/assets/assets-manager.js";
15+
import { IntentCliFileTransformer } from "../lib/configuration/intent-cli.js";
1516

1617
const { mkdirSync } = fsExtra;
1718
export class StartServerCommand {
@@ -45,6 +46,9 @@ export class StartServerCommand {
4546
{ watch, debug, typeCheck: !isTruthy(disableTypeCheck) }
4647
);
4748

49+
const intentCliFileTransformer = new IntentCliFileTransformer();
50+
await intentCliFileTransformer.load(TS_CONFIG);
51+
4852
const assetsManager = new AssetsManager();
4953
const assetsOnUpdateHook = await assetsManager.handle(
5054
TS_CONFIG,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { INTENT_LOG_PREFIX } from "../utils/log-helpers.js";
2+
import pc from "picocolors";
3+
import { SwcTransformer } from "../dev-server/swc/swc-transformer.js";
4+
import { ParsedCommandLine } from "typescript";
5+
import { INTENT_CLI_FILE } from "../constants.js";
6+
import { readFileSync, writeFileSync } from "fs";
7+
8+
export class IntentCliFileTransformer {
9+
private swcTransformer = new SwcTransformer();
10+
11+
async load(TS_CONFIG: ParsedCommandLine): Promise<void> {
12+
try {
13+
const tempIntentRcPath = await this.swcTransformer.transpileTemp(
14+
INTENT_CLI_FILE,
15+
"intent",
16+
TS_CONFIG
17+
);
18+
19+
const code = readFileSync(tempIntentRcPath, "utf-8");
20+
21+
const newCode = code.replace(
22+
/import\s+['"]@intentjs\/ts-node\/esm['"];?/g,
23+
""
24+
);
25+
26+
writeFileSync(tempIntentRcPath, newCode);
27+
} catch (e) {
28+
console.log(e);
29+
console.log(INTENT_LOG_PREFIX, pc.red(e.message));
30+
process.exit();
31+
}
32+
}
33+
}

packages/cli/lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const INTENT_CONFIG_FILE_NAME = "intentrc.ts";
22
export const TSCONFIG_JSON = "tsconfig.json";
3+
export const INTENT_CLI_FILE = "intent";

packages/cli/lib/dev-server/swc/swc-file-transformer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ export class SwcFileTransformer {
6161
: codeFilePath;
6262
writeFileSync(osSpecificFilePath, code);
6363

64-
options.sourceMaps &&
64+
if (options.sourceMaps) {
6565
this.writeSourceMap(isWindows, distFilePath, map);
66+
}
6667

6768
resolve(1);
6869
})

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@intentjs/cli",
3-
"version": "0.0.19",
3+
"version": "0.0.21",
44
"description": "Helper commands for building Intent application.",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)