initial commit

This commit is contained in:
sguenter
2023-09-29 17:45:29 +02:00
commit 40cae008d8
13 changed files with 667 additions and 0 deletions

55
bin/build.js Normal file
View File

@@ -0,0 +1,55 @@
const path = require("path");
const fs = require('fs');
const tmpFile = "./tmp/script.js";
function findNames(dir, excluded) {
let names = {};
if (excluded.includes(dir)) {
return names;
}
let files = fs.readdirSync(dir);
files.forEach(file => {
let stats = fs.statSync(dir + file);
if (stats.isDirectory()) {
let nameObject = findNames(dir + file + '/', excluded);
names = Object.assign(names, nameObject);
} else if ((file.endsWith(".ts") ) && !excluded.includes(dir + file)) {
names[file.substring(0, file.length - 3)] = dir + file.substring(0, file.length - 3);
}
else if ((file.endsWith(".mjs") ) && !excluded.includes(dir + file)) {
names[file.substring(0, file.length - 4)] = dir + file.substring(0, file.length - 4);
}
});
return names;
}
async function buildEntryPoints(fileOption, target) {
const cutLengthFront = 0;
target = target || tmpFile;
const resultDir = path.resolve(process.cwd(), path.dirname(target));
let names = {};
fileOption.input.forEach(dir => {
Object.assign(names, findNames(dir + "/", []));
});
let imports = '';
for (let k in names) {
imports += "export * from './" + path.relative(resultDir, path.resolve(process.cwd(), names[k].substring(cutLengthFront))) + "';\n";
}
if (!fs.existsSync(resultDir)) {
fs.mkdirSync(resultDir);
}
fs.writeFileSync(target, imports);
}
buildEntryPoints({
input: [
path.resolve(process.cwd(), "src/"),
],
}, "./src/hotkeys.ts");

39
bin/release.sh Executable file
View File

@@ -0,0 +1,39 @@
#! /bin/bash
# Exit when a command fails
set -e
REPOSITORY=git@github.com:Ainias/js-helper.git
if [[ -z "$1" ]]; then
echo "versioname not given!"
exit;
fi;
versionName=$1
versionExists="$(git ls-remote $REPOSITORY refs/tags/"$versionName"| tr -d '\n')"
if [ -n "$versionExists" ]; then
echo "Version existiert bereits!";
exit 1;
fi;
WORKING_DIR=$(pwd)
TMPDIR=$(mktemp -d)
cd "$TMPDIR";
git clone $REPOSITORY project
cd project
npm install
npm run build
git add -u
git commit -m "pre-version-commit for version $versionName" || echo "no commit needed"
npm version "$versionName"
npm publish
git push
cd "$WORKING_DIR"
git pull;
echo "$TMPDIR"

101
bin/updateCopies.js Normal file
View File

@@ -0,0 +1,101 @@
const path = require("path");
const exec = require('child_process').exec;
const fs = require('fs');
const packageName = require("../package.json").name;
let pathsToProjects = [
"/Users/sguenter/Projekte/Privat/dnd",
// "/home/silas/Projekte/web/nextjsTest/poc-nextjs",
// "/home/silas/Projekte/web/project-echo",
// "/home/silas/Projekte/web/smd-mail",
// "/home/silas/Projekte/web/dnd",
// "/home/silas/Projekte/web/bat",
// "/home/silas/Projekte/web/typeorm-sync",
// "/home/silas/Projekte/web/typeorm-sync-nextjs",
// "/home/silas/Projekte/web/worktime",
// "/home/silas/Projekte/web/TaskList",
// "/home/silas/Projekte/web/hoffnungsfest",
// "/home/silas/Projekte/web/geometry",
// "/home/silas/Projekte/web/react-bootstrap-mobile",
// "/home/silas/Projekte/web/react-bootstrap-mobile",
// "/home/silas/Projekte/chrome/dmscreen",
// "/home/silas/Projekte/web/smd-mail",
// "/home/silas/Projekte/web/prayercircle",
// "/home/silas/Projekte/Web/stories",
// "/home/silas/Projekte/web/cordova-sites",
// "/home/silas/Projekte/web/cordova-sites-easy-sync",
// "/home/silas/Projekte/Web/cordova-sites-user-management",
// "/home/silas/Projekte/i9/mbb",
// "/home/silas/Projekte/Web/bible-lexicon",
// "/var/www/i9/mbb",
// "/home/silas/PhpstormProjects/cordova-sites-user-management",
// "/home/silas/PhpstormProjects/project-echo",
];
const deleteFolderRecursive = function(path) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function(file, index){
let curPath = path + "/" + file;
if (fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};
async function execPromise(command) {
return new Promise((resolve, reject) => {
console.log("executing " + command + "...");
exec(command, (err, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
if (err) {
reject([err, stdout, stderr]);
} else {
resolve([stdout, stderr]);
}
});
});
}
execPromise("npm pack").then(async (std) => {
let thisPath = process.cwd();
let name = std[0].trim();
let pathToTar = path.resolve(thisPath, name);
if (!fs.existsSync("tmp")) {
fs.mkdirSync("tmp");
}
process.chdir("tmp");
await execPromise("tar -xvzf " + pathToTar + " -C ./");
process.chdir("package");
fs.unlinkSync("package.json");
let promise = Promise.resolve();
pathsToProjects.forEach((project) => {
promise = promise.then(async () => {
let resultDir = path.resolve(project, "node_modules", packageName);
console.log(resultDir, fs.existsSync(resultDir));
if (!fs.existsSync(resultDir)) {
fs.mkdirSync(resultDir);
}
return execPromise("cp -r ./* "+resultDir);
});
});
await promise;
process.chdir(thisPath);
fs.unlinkSync(name);
deleteFolderRecursive("tmp");
// fs.unlinkSync("tmp");
console.log("done!");
}).catch(e => {
console.error(e);
});