Compare commits

..

32 Commits

Author SHA1 Message Date
03625bfca4 1.2.35 2022-06-02 00:23:45 +02:00
cc92e3e9ca fix(core): update 2022-06-02 00:23:45 +02:00
c1e66d498a 1.2.34 2022-05-25 10:55:36 +02:00
bfbb802e88 fix(core): update 2022-05-25 10:55:35 +02:00
655fd8b92e 1.2.33 2022-05-25 10:11:15 +02:00
a240cdfde1 fix(core): update 2022-05-25 10:11:14 +02:00
2af7682cf0 1.2.32 2022-03-24 18:47:16 +01:00
c62619bd27 fix(core): update 2022-03-24 18:47:16 +01:00
ffaf54f1de 1.2.31 2022-03-13 00:02:20 +01:00
2c6b955819 fix(core): update 2022-03-13 00:02:20 +01:00
9bb13e1ede 1.2.30 2022-03-13 00:01:40 +01:00
d9bd5e5340 fix(core): update 2022-03-13 00:01:40 +01:00
b76de3e04d 1.2.29 2022-03-12 22:54:05 +01:00
808726d1df fix(core): update 2022-03-12 22:54:04 +01:00
d011f10b9b 1.2.28 2022-03-12 21:59:15 +01:00
d1baa20aad fix(core): update 2022-03-12 21:59:14 +01:00
71779693d7 1.2.27 2022-03-12 21:52:14 +01:00
1113251aea fix(core): update 2022-03-12 21:52:14 +01:00
e41cd896bb 1.2.26 2022-03-12 19:13:56 +01:00
ba44007fb2 fix(core): update 2022-03-12 19:13:56 +01:00
8d1362f14b 1.2.25 2022-03-12 18:54:20 +01:00
61ceb03962 fix(core): update 2022-03-12 18:54:19 +01:00
ab3ec90245 1.2.24 2022-03-12 18:50:18 +01:00
b51cda08c4 fix(core): update 2022-03-12 18:50:17 +01:00
b8332e1de4 1.2.23 2022-03-12 14:52:42 +01:00
da9a73bc79 fix(core): update 2022-03-12 14:52:42 +01:00
26bf39abae 1.2.22 2022-03-12 14:43:54 +01:00
b66b2083ab fix(core): update 2022-03-12 14:43:54 +01:00
e40c0151bc 1.2.21 2022-03-11 18:09:35 +01:00
fe97fcd193 fix(core): update 2022-03-11 18:09:35 +01:00
5174d9ccc6 1.2.20 2022-03-11 17:56:09 +01:00
e89c3eda66 fix(core): update 2022-03-11 17:56:08 +01:00
10 changed files with 346 additions and 723 deletions

2
cli.js
View File

@ -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();

View File

@ -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();

919
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,30 +1,31 @@
{ {
"name": "@gitzone/tsrun", "name": "@gitzone/tsrun",
"version": "1.2.19", "version": "1.2.35",
"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.29", "@gitzone/tsbuild": "^2.1.63",
"@types/node": "^17.0.21", "@pushrocks/smartcli": "^3.0.14",
"node-fetch": "^3.2.2", "@types/node": "^17.0.38",
"tslint": "^6.1.2", "node-fetch": "^3.2.5"
"tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartfile": "^9.0.6", "@pushrocks/smartfile": "^9.0.6",
"ts-node": "^10.7.0", "@pushrocks/smartshell": "^2.0.30",
"typescript": "^4.6.2" "ts-node": "^10.8.0",
"typescript": "^4.7.2"
}, },
"private": false, "private": false,
"files": [ "files": [

View File

@ -2,9 +2,13 @@ const textToPost: string = 'Test runs!';
console.log(textToPost); console.log(textToPost);
const run = async () => { const run = async () => {
// lets test esm const smartcli = await import('@pushrocks/smartcli');
console.warn('remember to enable esm checks once TypeScript 4.5 is released.') const smartcliInstance = new smartcli.Smartcli();
// const nodeFetch = await import('node-fetch'); console.log(process.argv)
smartcliInstance.addCommand('sayhello').subscribe(async argvArg => {
console.log('hello there');
})
smartcliInstance.startParse();
} }
run(); run();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@gitzone/tsrun',
version: '1.2.35',
description: 'run typescript programs efficiently'
}

View File

@ -1,31 +1,42 @@
import * as path from 'path'; import * as plugins from './plugins.js';
import * as tsNode from 'ts-node'; const __dirname = plugins.path.dirname(plugins.url.fileURLToPath(import.meta.url));
import { CompilerOptions } from 'typescript';
const defaultTsNodeOptions: tsNode.CreateOptions = { export const runPath = async (pathArg: string, fromFileUrl?: string) => {
compilerOptions: { pathArg = fromFileUrl
lib: ['dom'], ? plugins.path.join(plugins.path.dirname(plugins.url.fileURLToPath(fromFileUrl)), pathArg)
target: <any>'es2020', // Script Target should be a string -> 2 is for ES2015 : pathArg;
experimentalDecorators: true, await runCli(pathArg);
esModuleInterop: true,
strictNullChecks: false,
moduleResolution: <any>'node12',
module: <any>'es2020',
importsNotUsedAsValues: <any>'preserve',
} as CompilerOptions,
skipIgnore: true,
}; };
tsNode.register(defaultTsNodeOptions); export const runCli = async (pathArg?: string) => {
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); // we want to have command line arguments available in the child process.
process.argv.splice(2, 1); // when we have a path sepcified through a function there is one argeument less to pay respect to.
// console.log(process.argv); // thus when pathArg is specifed -> we only splice 2
import(pathToLoad); pathArg ? process.argv.splice(0, 2) : 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;
})
: ''
}`
);
}; };

21
ts/loader.ts Normal file
View File

@ -0,0 +1,21 @@
import * as plugins from './plugins.js';
import type { CompilerOptions } from 'typescript';
const defaultTsNodeOptions: plugins.tsNode.CreateOptions = {
compilerOptions: {
lib: ['dom'],
target: <any>'es2022', // Script Target should be a string -> 2 is for ES2015
experimentalDecorators: true,
useDefineForClassFields: false,
esModuleInterop: true,
strictNullChecks: false,
moduleResolution: <any>'nodenext',
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
View 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
View File

@ -0,0 +1,7 @@
{
"compilerOptions": {
"module": "ES2022",
"target": "ES2020",
"moduleResolution": "Node12"
}
}