-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Showing
11 changed files
with
176 additions
and
100 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
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 |
---|---|---|
@@ -1,51 +1,61 @@ | ||
import fs from 'fs' | ||
|
||
import { ParseCLI } from '../helpers/ParseCLI.js' | ||
import { PLV8ifyCLI } from '../impl/PLV8ifyCLI.js' | ||
|
||
export async function generateCommand( | ||
CLI: ReturnType<typeof ParseCLI.getCommand> | ||
) { | ||
const { | ||
bundler, | ||
writeBundlerOutput, | ||
inputFilePath, | ||
outputFolderPath, | ||
scopePrefix, | ||
pgFunctionDelimiter, | ||
fallbackReturnType, | ||
mode, | ||
defaultVolatility, | ||
} = CLI.config | ||
|
||
fs.mkdirSync(outputFolderPath, { recursive: true }) | ||
|
||
const plv8ify = new PLV8ifyCLI(bundler) | ||
plv8ify.init(inputFilePath) | ||
|
||
const bundledJs = await plv8ify.build({ | ||
mode, | ||
inputFile: inputFilePath, | ||
scopePrefix, | ||
}) | ||
|
||
// Optionally, write ESBuild output file | ||
if (writeBundlerOutput) { | ||
plv8ify.write(`${outputFolderPath}/output.js`, bundledJs) | ||
} | ||
|
||
// Emit SQL files for each exported function in the input TS file | ||
const sqlFiles = plv8ify.getPLV8SQLFunctions({ | ||
mode, | ||
scopePrefix, | ||
defaultVolatility, | ||
bundledJs, | ||
pgFunctionDelimiter, | ||
fallbackReturnType, | ||
outputFolder: outputFolderPath, | ||
}) | ||
|
||
sqlFiles.forEach((sqlFile) => { | ||
plv8ify.write(sqlFile.filename, sqlFile.sql) | ||
}) | ||
import { Effect } from 'effect' | ||
import { PLV8ify } from 'src/interfaces/PLV8ify.js' | ||
|
||
import { Config } from '../helpers/ParseCLI.js' | ||
|
||
export function generateCommand() { | ||
const bundledJs = Effect.all([Config, PLV8ify]).pipe( | ||
Effect.tap(([config, plv8ify]) => { | ||
const commandConfig = config.getCommand() | ||
const { inputFilePath } = commandConfig.config | ||
plv8ify.init(inputFilePath) | ||
}), | ||
Effect.flatMap(([config, plv8ify]) => { | ||
const commandConfig = config.getCommand() | ||
const { mode, inputFilePath, scopePrefix } = commandConfig.config | ||
const bundledJs = Effect.promise(() => | ||
plv8ify.build({ | ||
mode, | ||
inputFile: inputFilePath, | ||
scopePrefix, | ||
}) | ||
) | ||
return bundledJs | ||
}) | ||
) | ||
|
||
return bundledJs.pipe( | ||
Effect.flatMap((bundledJs) => { | ||
return Effect.all([Config, PLV8ify]).pipe( | ||
Effect.flatMap(([config, plv8ify]) => { | ||
const commandConfig = config.getCommand() | ||
const { | ||
mode, | ||
scopePrefix, | ||
defaultVolatility, | ||
pgFunctionDelimiter, | ||
fallbackReturnType, | ||
outputFolderPath, | ||
writeBundlerOutput, | ||
} = commandConfig.config | ||
const sqlFiles = plv8ify.getPLV8SQLFunctions({ | ||
mode, | ||
scopePrefix, | ||
defaultVolatility, | ||
bundledJs, | ||
pgFunctionDelimiter, | ||
fallbackReturnType, | ||
outputFolder: outputFolderPath, | ||
}) | ||
|
||
return Effect.succeed({ | ||
writeBundlerOutput, | ||
outputFolderPath, | ||
sqlFiles, | ||
bundledJs, | ||
}) | ||
}) | ||
) | ||
}) | ||
) | ||
} |
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 |
---|---|---|
@@ -1,9 +1,21 @@ | ||
import { Effect } from 'effect' | ||
import { createRequire } from 'module' | ||
|
||
const require = createRequire(import.meta.url) | ||
|
||
class VersionCmdError extends Error { | ||
readonly _tag = 'VersionCmdError' | ||
} | ||
|
||
export function versionCommand() { | ||
const pkg = require('../../package.json') | ||
console.log(`Version: ${pkg.version}`) | ||
process.exit(0) | ||
return Effect.try({ | ||
try: () => { | ||
// TODO: require can fail, this effect is not pure | ||
const pkg = require('../../package.json') | ||
console.log(`Version: ${pkg.version}`) | ||
}, | ||
catch: (e) => { | ||
return new VersionCmdError(`${e}`) | ||
}, | ||
}) | ||
} |
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
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,20 @@ | ||
import fs from 'fs' | ||
|
||
export function writeFile(filePath: string, content: string) { | ||
try { | ||
fs.unlinkSync(filePath) | ||
} catch (e) {} | ||
fs.writeFileSync(filePath, content) | ||
} | ||
|
||
type Runtime = 'node' | 'bun' | ||
|
||
export function getRuntime(): Runtime { | ||
if (typeof Bun !== 'undefined') { | ||
return 'bun' | ||
} | ||
if (typeof process !== 'undefined') { | ||
return 'node' | ||
} | ||
throw new Error('Unknown runtime') | ||
} |
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
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
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
Oops, something went wrong.