Writing shell scripts without boilerplate #1340
Answered
by
cspotcode
cspotcode
asked this question in
Official Recipes
-
For example, the following will work in an empty directory without any node_modules or other configuration files: # The latest npm v7 installs peer dependencies by default, so this is all you need
$ npm install -g ts-node Create the following file and give it execute permission: #!/usr/bin/env ts-node
import fs from 'fs';
// hey this is line 4
const source = fs.readFileSync(__filename, 'utf8');
console.log(source.split('\n')[3]);
// Uncomment this to prove that typechecking works
// const num: number = source;
// Requires a modern `target` and `lib`, but `ts-node` will set these automatically on modern node versions
const bigint = 100n;
console.dir(bigint); Run it: $ ./foo.ts
// hey this is line 4
100n |
Beta Was this translation helpful? Give feedback.
Answered by
cspotcode
May 23, 2021
Replies: 1 comment
-
If the information above can be improved in any way, please ask questions here and we will update it accordingly. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
cspotcode
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the information above can be improved in any way, please ask questions here and we will update it accordingly.