Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
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
|
#!/usr/bin/env node
|
||||||
process.env.CLI_CALL = 'true';
|
process.env.CLI_CALL = 'true';
|
||||||
const cliTool = require('./dist_ts/index');
|
const cliTool = await import('./dist_ts/index.js');
|
||||||
cliTool.runCli();
|
cliTool.runCli();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
process.env.CLI_CALL = 'true';
|
process.env.CLI_CALL = 'true';
|
||||||
require('@gitzone/tsrun');
|
await import('@gitzone/tsrun');
|
||||||
const cliTool = require('./ts/index');
|
const cliTool = await import('./ts/index.js');
|
||||||
cliTool.runCli();
|
cliTool.runCli();
|
||||||
|
1029
package-lock.json
generated
1029
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",
|
"name": "@gitzone/tsrun",
|
||||||
"version": "1.2.13",
|
"version": "1.2.27",
|
||||||
"description": "run typescript programs efficiently",
|
"description": "run typescript programs efficiently",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsrun": "./cli.js"
|
"tsrun": "./cli.js"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tsbuild && node ./cli.js test/test.ts)",
|
"test": "(tsbuild && node ./cli.js test/test.js sayhello)",
|
||||||
"format": "(gitzone format)",
|
"format": "(gitzone format)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.24",
|
"@gitzone/tsbuild": "^2.1.43",
|
||||||
"@types/node": "^15.12.4",
|
"@pushrocks/smartcli": "^3.0.14",
|
||||||
|
"@types/node": "^17.0.21",
|
||||||
|
"node-fetch": "^3.2.2",
|
||||||
"tslint": "^6.1.2",
|
"tslint": "^6.1.2",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartfile": "^8.0.10",
|
"@pushrocks/smartfile": "^9.0.6",
|
||||||
"ts-node": "^10.0.0",
|
"@pushrocks/smartshell": "^2.0.30",
|
||||||
"typescript": "^4.3.4"
|
"ts-node": "^10.7.0",
|
||||||
|
"typescript": "4.7.0-dev.20220311"
|
||||||
},
|
},
|
||||||
"private": false,
|
"private": false,
|
||||||
"files": [
|
"files": [
|
||||||
|
12
test/test.ts
12
test/test.ts
@ -1,2 +1,14 @@
|
|||||||
const textToPost: string = 'Test runs!';
|
const textToPost: string = 'Test runs!';
|
||||||
console.log(textToPost);
|
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();
|
63
ts/index.ts
63
ts/index.ts
@ -1,39 +1,40 @@
|
|||||||
import * as path from 'path';
|
import * as plugins from './plugins.js';
|
||||||
import * as tsNode from 'ts-node';
|
|
||||||
import { CompilerOptions } from 'typescript';
|
|
||||||
|
|
||||||
const defaultTsNodeOptions: tsNode.CreateOptions = {
|
import { dirname } from 'path';
|
||||||
compilerOptions: {
|
import { fileURLToPath } from 'url';
|
||||||
lib: ['es2017'],
|
|
||||||
target: <any>'es2017', // Script Target should be a string -> 2 is for ES2015
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
experimentalDecorators: true,
|
|
||||||
esModuleInterop: true,
|
export const runPath = async (pathArg: string) => {
|
||||||
} as CompilerOptions,
|
await runCli(pathArg);
|
||||||
skipIgnore: true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (process.argv.includes('--web')) {
|
export const runCli = async (pathArg?: string) => {
|
||||||
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 () => {
|
|
||||||
// contents of argv array
|
// contents of argv array
|
||||||
// process.argv[0] -> node Executable
|
// process.argv[0] -> node Executable
|
||||||
// process.argv[1] -> tsrun 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.splice(0, 3); // this ensures transparent arguments for the child process
|
||||||
process.argv.shift();
|
|
||||||
import(pathToLoad);
|
// 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;
|
20
ts/plugins.ts
Normal file
20
ts/plugins.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// node native
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
|
export {
|
||||||
|
path
|
||||||
|
}
|
||||||
|
|
||||||
|
// @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