Added ability to build and install cli binary so that templates can be executed directly
This commit is contained in:
parent
8220e097df
commit
8b1efa29c4
@ -4,7 +4,7 @@ import { spawn } from 'node:child_process';
|
|||||||
|
|
||||||
import { file } from 'tmp-promise';
|
import { file } from 'tmp-promise';
|
||||||
|
|
||||||
import { renderFile } from './src/template_engine.js';
|
import { renderFile } from './src/template_engine.mjs';
|
||||||
|
|
||||||
|
|
||||||
if (process.argv.length <= 2) {
|
if (process.argv.length <= 2) {
|
4
dist/.gitignore
vendored
Normal file
4
dist/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Preserve directory, but ignore contents
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
!.gitignore
|
1
example_templates/readme_example.n0m
Normal file → Executable file
1
example_templates/readme_example.n0m
Normal file → Executable file
@ -1,3 +1,4 @@
|
|||||||
|
#!/usr/bin/env n0m
|
||||||
$ #!/bin/sh
|
$ #!/bin/sh
|
||||||
$ title='My Restaurant Randomizer';
|
$ title='My Restaurant Randomizer';
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
|
@ -1 +1 @@
|
|||||||
export { TemplateEngine, renderFile } from './src/template_engine.js';
|
export { TemplateEngine, renderFile } from './src/template_engine.mjs';
|
4905
package-lock.json
generated
4905
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@ -2,15 +2,26 @@
|
|||||||
"name": "n0m-template-engine",
|
"name": "n0m-template-engine",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"module": "index.mjs",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node cli.js",
|
"start": "node cli.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"make": "npx webpack && npx pkg .",
|
||||||
|
"install": "sudo cp ./dist/n0m-template-engine /usr/local/bin/n0m"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tmp-promise": "^3.0.3"
|
"tmp-promise": "^3.0.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"pkg": "^5.8.0",
|
||||||
|
"webpack": "^5.74.0",
|
||||||
|
"webpack-cli": "^4.10.0"
|
||||||
|
},
|
||||||
|
"bin": "dist/cli.js",
|
||||||
|
"pkg": {
|
||||||
|
"targets": [ "node18-linux" ],
|
||||||
|
"outputPath": "dist"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { TokenStream } from './token_stream.js';
|
import { TokenStream } from './token_stream.mjs';
|
||||||
|
|
||||||
export class TemplateEngine {
|
export class TemplateEngine {
|
||||||
async render(fileName) {
|
async render(fileName) {
|
@ -1,5 +1,5 @@
|
|||||||
import { CharacterStream } from './character_stream.js';
|
import { CharacterStream } from './character_stream.mjs';
|
||||||
import { TemplateSyntaxError } from './errors/template_syntax_error.js';
|
import { TemplateSyntaxError } from './errors/template_syntax_error.mjs';
|
||||||
|
|
||||||
export class TokenStream {
|
export class TokenStream {
|
||||||
static OPEN_INLINE = '<%';
|
static OPEN_INLINE = '<%';
|
15
webpack.config.mjs
Normal file
15
webpack.config.mjs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import * as url from 'url';
|
||||||
|
import path from 'path';
|
||||||
|
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
||||||
|
|
||||||
|
export default {
|
||||||
|
mode: 'development',
|
||||||
|
target: 'node',
|
||||||
|
entry: path.join(__dirname, 'cli.mjs'),
|
||||||
|
experiments: {
|
||||||
|
topLevelAwait: true
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
filename: 'cli.js'
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user