-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd80f98
commit 2e7e6bc
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import path from "path"; | ||
import {loadEnv, type ResolvedConfig} from "vite"; | ||
import {readFileSync} from "fs"; | ||
import {fileURLToPath} from "url"; | ||
|
||
import type {Ci4} from "./types/plugin"; | ||
import {highlightVersion} from "./utils/decorate"; | ||
import {frameworkVersion, pluginVersion} from "./utils/version"; | ||
|
||
const ci4: Ci4 = (_config: string | string[]) => { | ||
let config: ResolvedConfig; | ||
|
||
return { | ||
name: "ci4", | ||
enforce: "post", | ||
config: (userConfig) => { | ||
return userConfig; | ||
}, | ||
configResolved: (resolveConfig) => { | ||
config = resolveConfig; | ||
}, | ||
configureServer: (server) => { | ||
const envDir = config.envDir || process.cwd(); | ||
const appUrl = | ||
loadEnv(config.mode, envDir, "app.baseURL")["app.baseURL"] ?? "undefined"; | ||
|
||
console.log(loadEnv(config.mode, envDir, "app.baseURL")["app.baseURL"]); | ||
|
||
server.httpServer?.once("listening", () => { | ||
setTimeout(() => { | ||
server.config.logger.info(""); | ||
|
||
frameworkVersion() | ||
.then((version) => { | ||
server.config.logger.info(highlightVersion("CodeIgniter", version)); | ||
|
||
return pluginVersion(); | ||
}) | ||
.then((version) => { | ||
server.config.logger.info(highlightVersion("Plugin ", version)); | ||
|
||
return version; | ||
}); | ||
}, 100); | ||
}); | ||
|
||
return () => | ||
server.middlewares.use((req, res, next) => { | ||
if (req.url === "/index.html") { | ||
res.statusCode = 404; | ||
|
||
res.end( | ||
readFileSync(path.join(dirname(), "index.html")) | ||
.toString() | ||
.replace(/{{ APP_URL }}/g, appUrl) | ||
); | ||
} | ||
|
||
next(); | ||
}); | ||
}, | ||
}; | ||
}; | ||
|
||
function dirname(): string { | ||
return fileURLToPath(new URL(".", import.meta.url)); | ||
} | ||
|
||
export default ci4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type {ConfigEnv, Plugin, UserConfig} from "vite"; | ||
|
||
interface Ci4Plugin extends Plugin { | ||
config: (config: UserConfig, env: ConfigEnv) => UserConfig; | ||
} | ||
|
||
export declare type Ci4 = (_config: string | string[]) => Ci4Plugin; |