Compare commits
30 Commits
Author | SHA1 | Date | |
---|---|---|---|
d011f10b9b | |||
d1baa20aad | |||
71779693d7 | |||
1113251aea | |||
e41cd896bb | |||
ba44007fb2 | |||
8d1362f14b | |||
61ceb03962 | |||
ab3ec90245 | |||
b51cda08c4 | |||
b8332e1de4 | |||
da9a73bc79 | |||
26bf39abae | |||
b66b2083ab | |||
e40c0151bc | |||
fe97fcd193 | |||
5174d9ccc6 | |||
e89c3eda66 | |||
6d4c9f390a | |||
3fc3421857 | |||
e1803dabfa | |||
282d8b2b93 | |||
76dd9707fe | |||
269e54c717 | |||
dd33a359c3 | |||
0caaac2a67 | |||
14a043be1e | |||
de44be741d | |||
d15500d5a0 | |||
7e99fd703f |
2
cli.js
2
cli.js
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
process.env.CLI_CALL = 'true';
|
||||
const cliTool = require('./dist_ts/index');
|
||||
const cliTool = await import('./dist_ts/index.js');
|
||||
cliTool.runCli();
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
process.env.CLI_CALL = 'true';
|
||||
require('@gitzone/tsrun');
|
||||
const cliTool = require('./ts/index');
|
||||
await import('@gitzone/tsrun');
|
||||
const cliTool = await import('./ts/index.js');
|
||||
cliTool.runCli();
|
||||
|
1033
package-lock.json
generated
1033
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
18
package.json
18
package.json
@ -1,29 +1,33 @@
|
||||
{
|
||||
"name": "@gitzone/tsrun",
|
||||
"version": "1.2.13",
|
||||
"version": "1.2.28",
|
||||
"description": "run typescript programs efficiently",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"tsrun": "./cli.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "(tsbuild && node ./cli.js test/test.ts)",
|
||||
"test": "(tsbuild && node ./cli.js test/test.js sayhello)",
|
||||
"format": "(gitzone format)",
|
||||
"build": "(tsbuild)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.24",
|
||||
"@types/node": "^15.12.4",
|
||||
"@gitzone/tsbuild": "^2.1.43",
|
||||
"@pushrocks/smartcli": "^3.0.14",
|
||||
"@types/node": "^17.0.21",
|
||||
"node-fetch": "^3.2.2",
|
||||
"tslint": "^6.1.2",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartfile": "^8.0.10",
|
||||
"ts-node": "^10.0.0",
|
||||
"typescript": "^4.3.4"
|
||||
"@pushrocks/smartfile": "^9.0.6",
|
||||
"@pushrocks/smartshell": "^2.0.30",
|
||||
"ts-node": "^10.7.0",
|
||||
"typescript": "4.7.0-dev.20220311"
|
||||
},
|
||||
"private": false,
|
||||
"files": [
|
||||
|
12
test/test.ts
12
test/test.ts
@ -1,2 +1,14 @@
|
||||
const textToPost: string = 'Test runs!';
|
||||
console.log(textToPost);
|
||||
|
||||
const run = async () => {
|
||||
const smartcli = await import('@pushrocks/smartcli');
|
||||
const smartcliInstance = new smartcli.Smartcli();
|
||||
console.log(process.argv)
|
||||
smartcliInstance.addCommand('sayhello').subscribe(async argvArg => {
|
||||
console.log('hello there');
|
||||
})
|
||||
smartcliInstance.startParse();
|
||||
}
|
||||
|
||||
run();
|
62
ts/index.ts
62
ts/index.ts
@ -1,39 +1,39 @@
|
||||
import * as path from 'path';
|
||||
import * as tsNode from 'ts-node';
|
||||
import { CompilerOptions } from 'typescript';
|
||||
import * as plugins from './plugins.js';
|
||||
const __dirname = plugins.path.dirname(plugins.url.fileURLToPath(import.meta.url));
|
||||
|
||||
const defaultTsNodeOptions: tsNode.CreateOptions = {
|
||||
compilerOptions: {
|
||||
lib: ['es2017'],
|
||||
target: <any>'es2017', // Script Target should be a string -> 2 is for ES2015
|
||||
experimentalDecorators: true,
|
||||
esModuleInterop: true,
|
||||
} as CompilerOptions,
|
||||
skipIgnore: true,
|
||||
export const runPath = async (pathArg: string, fromFileUrl?: string) => {
|
||||
pathArg = fromFileUrl
|
||||
? plugins.path.join(plugins.path.dirname(plugins.url.fileURLToPath(fromFileUrl)), pathArg)
|
||||
: pathArg;
|
||||
await runCli(pathArg);
|
||||
};
|
||||
|
||||
if (process.argv.includes('--web')) {
|
||||
const previousCompilerOptions = defaultTsNodeOptions.compilerOptions as CompilerOptions;
|
||||
defaultTsNodeOptions.compilerOptions = {
|
||||
...previousCompilerOptions,
|
||||
lib: ['es2016', 'es2017', 'dom'],
|
||||
target: <any>'es2017', // Script Target should be a string -> 2 is for ES2015
|
||||
};
|
||||
}
|
||||
|
||||
if (process.argv.includes('--nocache')) {
|
||||
// currently caching is not used
|
||||
}
|
||||
|
||||
tsNode.register(defaultTsNodeOptions);
|
||||
|
||||
export const runCli = async () => {
|
||||
export const runCli = async (pathArg?: string) => {
|
||||
// contents of argv array
|
||||
// process.argv[0] -> node Executable
|
||||
// process.argv[1] -> tsrun executable
|
||||
const pathToTsFile = process.argv[2];
|
||||
const relativePathToTsFile = pathArg ? pathArg : process.argv[2];
|
||||
const absolutePathToTsFile = plugins.path.isAbsolute(relativePathToTsFile)
|
||||
? relativePathToTsFile
|
||||
: plugins.path.join(process.cwd(), relativePathToTsFile);
|
||||
|
||||
const pathToLoad = path.join(process.cwd(), pathToTsFile);
|
||||
process.argv.shift();
|
||||
import(pathToLoad);
|
||||
process.argv.splice(0, 3); // this ensures transparent arguments for the child process
|
||||
|
||||
// lets setup things for execution
|
||||
const smartshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash',
|
||||
});
|
||||
|
||||
const tsNodeLoaderPath = plugins.path.join(__dirname, 'loader.js');
|
||||
// note: -> reduce on emtpy array does not work
|
||||
// thus check needed before reducing the argv array
|
||||
smartshellInstance.exec(
|
||||
`node --loader ${tsNodeLoaderPath} ${absolutePathToTsFile} ${
|
||||
process.argv.length > 0
|
||||
? process.argv.reduce((prevArg, currentArg) => {
|
||||
return prevArg + ' ' + currentArg;
|
||||
})
|
||||
: ''
|
||||
}`
|
||||
);
|
||||
};
|
||||
|
20
ts/loader.ts
Normal file
20
ts/loader.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import type { CompilerOptions } from 'typescript';
|
||||
|
||||
const defaultTsNodeOptions: plugins.tsNode.CreateOptions = {
|
||||
compilerOptions: {
|
||||
lib: ['dom'],
|
||||
target: <any>'es2020', // Script Target should be a string -> 2 is for ES2015
|
||||
experimentalDecorators: true,
|
||||
esModuleInterop: true,
|
||||
strictNullChecks: false,
|
||||
moduleResolution: <any>'node12',
|
||||
module: <any>'ESNext',
|
||||
importsNotUsedAsValues: <any>'preserve',
|
||||
} as CompilerOptions,
|
||||
esm: true,
|
||||
skipIgnore: true,
|
||||
transpileOnly: true
|
||||
};
|
||||
|
||||
export const { resolve, load, getFormat, transformSource } = plugins.tsNode.createEsmHooks(plugins.tsNode.register(defaultTsNodeOptions)) as any;
|
22
ts/plugins.ts
Normal file
22
ts/plugins.ts
Normal file
@ -0,0 +1,22 @@
|
||||
// node native
|
||||
import * as path from 'path';
|
||||
import * as url from 'url';
|
||||
|
||||
export {
|
||||
path,
|
||||
url
|
||||
}
|
||||
|
||||
// @pushrocks scope
|
||||
import * as smartshell from '@pushrocks/smartshell';
|
||||
|
||||
export {
|
||||
smartshell
|
||||
}
|
||||
|
||||
// third party scope
|
||||
import * as tsNode from 'ts-node';
|
||||
|
||||
export {
|
||||
tsNode
|
||||
}
|
7
tsconfig.json
Normal file
7
tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "ES2022",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "Node12"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user