Added content

This commit is contained in:
Gutek8134 2023-08-10 22:14:06 +02:00
parent 1c99d06845
commit 589e5ed950
13 changed files with 6568 additions and 1 deletions

View file

@ -13,4 +13,4 @@ Also, note that we do not currently accept NSFW scripts.
The following are links to more AID scripts located externally. The following are links to more AID scripts located externally.
* More soon! Please send PRs. - More soon! Please send PRs.

View file

@ -0,0 +1,45 @@
# Local Typescript Developer Toolkit
As title suggests, it's not a script per se, but a set of preset tools for creating one in typescript and transpiling into 4 JS files.
## Why should I use it?
Why not? But really, type safety and unit tests can let you pick up and avoid errors much earlier in writing your code. Moreover, most IDEs will help you more, since now they will know the type of your variables.
## Perquisites
1. node.js
2. Python 3
3. run `npm install` in the location of this file
## How to use
Write your `.ts` files in the folder according to expected output file. If you want to add a subdirectory, see [adding a subdirectory](#adding-a-subdirectory). Once you are done, I recommend creating tests in the `Source/Modules/Tests` folder, using jest, with `.tests.ts` or `.test.ts` extension.
If you want to use proxies for other objects (history, info, etc.), leave their files in `Source/Modules`. This way they won't be transpiled with the things you want to.
Once you are done, you can run tests with `npm test`, and transpile with `npm run build`.
If `Source/build` directory will not be created, or will be empty, but `Source/build-intermediate` will have `.js` files inside, you can manually run `combine files.py`. You may have to run it as administrator/root.
## Known issues
- When using `export default`, file name must be the exactly the same (case dependent) as exported element.
## Adding a subdirectory
If you want to add a subdirectory for, let's say, commands, you have to include it into Python script by:
1. Call `combineFilesInPath` under other calls in `main`
2. Append it to another file
If you want to see an example made by me, `combine_files_example.py` shows how I added Input Modifier/Commands and inserted it to the beginning of the end file.
## MIT License
Copyright 2023 Gutek8134
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1,3 @@
{
"extends": "../tsconfig.json"
}

View file

@ -0,0 +1,3 @@
{
"extends": "../tsconfig.json"
}

View file

@ -0,0 +1,3 @@
{
"extends": "../tsconfig.json"
}

View file

@ -0,0 +1,3 @@
{
"extends": "../tsconfig.json"
}

View file

@ -0,0 +1,119 @@
import re
from os import listdir
from os.path import isfile
from pathlib import Path
IMPORT_REGEX_PATTERN: re.Pattern[str] = re.compile(
r'(^const (?P<namespace>\w+) = require\(.+\);$)', re.I | re.M)
CONTEXT_MODIFIER_INTERMEDIATE_FILES_PATH = "./build-intermediate/Context Modifier"
INPUT_MODIFIER_INTERMEDIATE_FILES_PATH = "./build-intermediate/Input Modifier"
OUTPUT_MODIFIER_INTERMEDIATE_FILES_PATH = "./build-intermediate/Output Modifier"
SHARED_LIBRARY_INTERMEDIATE_FILES_PATH = "./build-intermediate/Shared Library"
BUILD_PATH = "./build"
CONTEXT_MODIFIER_BUILD_FILE_NAME = "contextModifier.js"
INPUT_MODIFIER_BUILD_FILE_NAME = "inputModifier.js"
OUTPUT_MODIFIER_BUILD_FILE_NAME = "outputModifier.js"
SHARED_LIBRARY_BUILD_FILE_NAME = "sharedLibrary.js"
# Shortening access path as "constants"
COMMANDS_INTERMEDIATE_FILES_PATH = "./build-intermediate/Input Modifier/Commands"
COMMANDS_BUILD_FILE_NAME = "commands.intermediate.js"
def stripBeginning(fileContent: str) -> str:
lines: list[str] = fileContent.splitlines()
return "\n".join(lines[2:])
def removeExports(fileContent: str) -> str:
lines: list[str] = fileContent.splitlines()
for line in lines.copy():
if re.search(r"exports\.(\w+) = (?:void 0|\1)|exports.default = \w+", line) is not None:
lines.remove(line)
return "\n".join(lines)
def removeImportNamespacesAndImports(fileContent: str) -> str:
namespaces: list[str] = []
match: re.Match | None = re.search(IMPORT_REGEX_PATTERN, fileContent)
while match is not None:
fileContent = fileContent[:match.start()] + fileContent[match.end()+1:]
namespaces.append(match.group("namespace"))
match = re.search(IMPORT_REGEX_PATTERN, fileContent)
fileContent = fileContent.replace("exports.", "")
for namespace in namespaces:
fileContent = fileContent.replace(
f"{namespace}.default", namespace[:-2])
fileContent = fileContent.replace(namespace + ".", "")
return fileContent
def prepareFileContents(fileContents: str) -> str:
return \
removeImportNamespacesAndImports(
removeExports(
stripBeginning(fileContents)
)
)
def combineFilesInPath(inPath: str, outFileName: str) -> None:
with open(f"{BUILD_PATH}/{outFileName}", "w") as outFile:
for name in listdir(inPath):
if isfile(f"{inPath}/{name}"):
with open(f"{inPath}/{name}", "r") as inFile:
outFile.write(prepareFileContents(inFile.read())+"\n\n")
def main():
buildDirPath: Path = Path(BUILD_PATH)
if not buildDirPath.exists():
buildDirPath.mkdir()
combineFilesInPath(
CONTEXT_MODIFIER_INTERMEDIATE_FILES_PATH,
CONTEXT_MODIFIER_BUILD_FILE_NAME
)
combineFilesInPath(
INPUT_MODIFIER_INTERMEDIATE_FILES_PATH,
INPUT_MODIFIER_BUILD_FILE_NAME
)
combineFilesInPath(
OUTPUT_MODIFIER_INTERMEDIATE_FILES_PATH,
OUTPUT_MODIFIER_BUILD_FILE_NAME
)
combineFilesInPath(
SHARED_LIBRARY_INTERMEDIATE_FILES_PATH,
SHARED_LIBRARY_BUILD_FILE_NAME
)
# Combining Input Modifier/Commands files into single commands.intermediate.js
combineFilesInPath(
COMMANDS_INTERMEDIATE_FILES_PATH,
COMMANDS_BUILD_FILE_NAME
)
# Inserting content of commands.intermediate.js at the beginning of input modifier
with open(f"{BUILD_PATH}/{INPUT_MODIFIER_BUILD_FILE_NAME}", "r") as inputModifierFile:
cache = inputModifierFile.read()
with open(f"{BUILD_PATH}/{INPUT_MODIFIER_BUILD_FILE_NAME}", "w") as inputModifierFile:
with open(f"{BUILD_PATH}/{COMMANDS_BUILD_FILE_NAME}") as commandsFile:
inputModifierFile.write(commandsFile.read()+cache)
# Adding modifier call
for modifierFileName in (CONTEXT_MODIFIER_BUILD_FILE_NAME, INPUT_MODIFIER_BUILD_FILE_NAME, OUTPUT_MODIFIER_BUILD_FILE_NAME):
with open(f"{BUILD_PATH}/{modifierFileName}", "a") as modifierFile:
modifierFile.write("modifier(text);")
# Deleting commands.intermediate.js
commandsFilePath: Path = Path(f"{BUILD_PATH}/{COMMANDS_BUILD_FILE_NAME}")
if commandsFilePath.exists() and commandsFilePath.is_file():
commandsFilePath.unlink()
if __name__ == "__main__":
main()

View file

@ -0,0 +1,17 @@
export const state: {
//Used in modifiers other than Input
in: string;
ctxt: string;
out: string;
message:
| string
| { text: string; visibleTo: string[] }
| { text: string; visibleTo: string[] }[];
memory: { context: string; frontMemory: string; authorsNote: string };
} = {
in: "",
ctxt: "",
out: "",
message: "",
memory: { context: "", frontMemory: "", authorsNote: "" },
};

View file

@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "CommonJS",
"allowUnreachableCode": false,
"exactOptionalPropertyTypes": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"strict": true,
"outDir": "../build-intermediate",
"target": "ES6"
},
"exclude": ["./Tests"]
}

View file

@ -0,0 +1,97 @@
import re
from os import listdir
from os.path import isfile
from pathlib import Path
IMPORT_REGEX_PATTERN: re.Pattern[str] = re.compile(
r'(^const (?P<namespace>\w+) = require\(.+\);$)', re.I | re.M)
CONTEXT_MODIFIER_INTERMEDIATE_FILES_PATH = "./build-intermediate/Context Modifier"
INPUT_MODIFIER_INTERMEDIATE_FILES_PATH = "./build-intermediate/Input Modifier"
OUTPUT_MODIFIER_INTERMEDIATE_FILES_PATH = "./build-intermediate/Output Modifier"
SHARED_LIBRARY_INTERMEDIATE_FILES_PATH = "./build-intermediate/Shared Library"
BUILD_PATH = "./build"
CONTEXT_MODIFIER_BUILD_FILE_NAME = "contextModifier.js"
INPUT_MODIFIER_BUILD_FILE_NAME = "inputModifier.js"
OUTPUT_MODIFIER_BUILD_FILE_NAME = "outputModifier.js"
SHARED_LIBRARY_BUILD_FILE_NAME = "sharedLibrary.js"
def stripBeginning(fileContent: str) -> str:
lines: list[str] = fileContent.splitlines()
return "\n".join(lines[2:])
def removeExports(fileContent: str) -> str:
lines: list[str] = fileContent.splitlines()
for line in lines.copy():
if re.search(r"exports\.(\w+) = (?:void 0|\1)|exports.default = \w+", line) is not None:
lines.remove(line)
return "\n".join(lines)
def removeImportNamespacesAndImports(fileContent: str) -> str:
namespaces: list[str] = []
match: re.Match | None = re.search(IMPORT_REGEX_PATTERN, fileContent)
while match is not None:
fileContent = fileContent[:match.start()] + fileContent[match.end()+1:]
namespaces.append(match.group("namespace"))
match = re.search(IMPORT_REGEX_PATTERN, fileContent)
fileContent = fileContent.replace("exports.", "")
for namespace in namespaces:
fileContent = fileContent.replace(
f"{namespace}.default", namespace[:-2])
fileContent = fileContent.replace(namespace + ".", "")
return fileContent
def prepareFileContents(fileContents: str) -> str:
return \
removeImportNamespacesAndImports(
removeExports(
stripBeginning(fileContents)
)
)
def combineFilesInPath(inPath: str, outFileName: str) -> None:
with open(f"{BUILD_PATH}/{outFileName}", "w") as outFile:
for name in listdir(inPath):
if isfile(f"{inPath}/{name}"):
with open(f"{inPath}/{name}", "r") as inFile:
outFile.write(prepareFileContents(inFile.read())+"\n\n")
def main():
buildDirPath: Path = Path(BUILD_PATH)
if not buildDirPath.exists():
buildDirPath.mkdir()
combineFilesInPath(
CONTEXT_MODIFIER_INTERMEDIATE_FILES_PATH,
CONTEXT_MODIFIER_BUILD_FILE_NAME
)
combineFilesInPath(
INPUT_MODIFIER_INTERMEDIATE_FILES_PATH,
INPUT_MODIFIER_BUILD_FILE_NAME
)
combineFilesInPath(
OUTPUT_MODIFIER_INTERMEDIATE_FILES_PATH,
OUTPUT_MODIFIER_BUILD_FILE_NAME
)
combineFilesInPath(
SHARED_LIBRARY_INTERMEDIATE_FILES_PATH,
SHARED_LIBRARY_BUILD_FILE_NAME
)
for modifierFileName in (CONTEXT_MODIFIER_BUILD_FILE_NAME, INPUT_MODIFIER_BUILD_FILE_NAME, OUTPUT_MODIFIER_BUILD_FILE_NAME):
with open(f"{BUILD_PATH}/{modifierFileName}", "a") as modifierFile:
modifierFile.write("modifier(text);")
if __name__ == "__main__":
main()

View file

@ -0,0 +1,195 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/
export default {
// All imported modules in your tests should be mocked automatically
//automock: true,
// Stop running tests after `n` failures
// bail: 0,
// The directory where Jest should store its cached dependency information
// cacheDirectory: "C:\\Users\\gutek\\AppData\\Local\\Temp\\jest",
// Automatically clear mock calls, instances, contexts and results before every test
clearMocks: true,
// Indicates whether the coverage information should be collected while executing the test
// collectCoverage: false,
// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,
// The directory where Jest should output its coverage files
// coverageDirectory: undefined,
// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],
// Indicates which provider should be used to instrument code for coverage
coverageProvider: "v8",
// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],
// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,
// A path to a custom dependency extractor
// dependencyExtractor: undefined,
// Make calling deprecated APIs throw helpful error messages
// errorOnDeprecated: false,
// The default configuration for fake timers
// fakeTimers: {
// "enableGlobally": false
// },
// Force coverage collection from ignored files using an array of glob patterns
// forceCoverageMatch: [],
// A path to a module which exports an async function that is triggered once before all test suites
// globalSetup: undefined,
// A path to a module which exports an async function that is triggered once after all test suites
// globalTeardown: undefined,
// A set of global variables that need to be available in all test environments
// globals: {},
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",
// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
// "node_modules"
// ],
// An array of file extensions your modules use
// moduleFileExtensions: [
// "js",
// "mjs",
// "cjs",
// "jsx",
// "ts",
// "tsx",
// "json",
// "node"
// ],
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
// moduleNameMapper: {},
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],
// Activates notifications for test results
// notify: false,
// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",
// A preset that is used as a base for Jest's configuration
preset: "ts-jest",
// Run tests from one or more projects
// projects: undefined,
// Use this configuration option to add custom reporters to Jest
// reporters: undefined,
// Automatically reset mock state before every test
// resetMocks: false,
// Reset the module registry before running each individual test
// resetModules: false,
// A path to a custom resolver
// resolver: undefined,
// Automatically restore mock state and implementation before every test
// restoreMocks: false,
// The root directory that Jest should scan for tests and modules within
// rootDir: undefined,
// A list of paths to directories that Jest should use to search for files in
// roots: [
// "<rootDir>"
// ],
// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",
// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],
// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],
// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],
// The test environment that will be used for testing
testEnvironment: "node",
// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},
// Adds a location field to test results
// testLocationInResults: false,
// The glob patterns Jest uses to detect test files
testMatch: [
"**/Tests?/**/*.tests?.[jt]s?(x)",
"**/?(*.)+(spec|test).[tj]s?(x)",
],
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],
// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],
// This option allows the use of a custom results processor
// testResultsProcessor: undefined,
// This option allows use of a custom test runner
// testRunner: "jest-circus/runner",
// A map from regular expressions to paths to transformers
// transform: undefined,
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "\\\\node_modules\\\\",
// "\\.pnp\\.[^\\\\]+$"
// ],
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,
// Indicates whether each individual test should be reported during the run
verbose: true,
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],
// Whether to use watchman for file crawling
// watchman: true,
};

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,16 @@
{
"name": "local-typescript-developer-toolkit",
"scripts": {
"test": "npx jest -i",
"build": "npx tsc --p ./Source/Modules; cd ./Source; python 'combine files.py';"
},
"author": "Gutek8134",
"license": "MIT",
"dependencies": {
"@types/jest": "^29.5.3",
"jest": "^29.6.2",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
}
}