move stuff to common and half figured out the install script

This commit is contained in:
Benjamin Kyd
2023-02-02 00:34:50 +00:00
parent 3e508fb613
commit 27a774acfe
78 changed files with 80 additions and 938 deletions

52
bootstrap.js vendored
View File

@@ -1,6 +1,11 @@
import fs from 'fs';
import opsys from 'os';
import path from 'path';
import { parseArgs } from 'node:util';
import subProcess from 'child_process';
import { log } from 'console';
const home = opsys.homedir() + '/';
const VERSION_MAJOR = 1;
const VERSION_MINOR = 0;
@@ -58,13 +63,54 @@ subProcess.spawnSync('./' + targetInstallScript, [], {
console.log('Successfully installed OS deps...');
const parentDir = 'common';
const targetDir = host;
const parentDir = 'common/';
const childDir = host + '/';
// we want to create a symlink between home/ & host/ to ~/
// we want to create a symlink between common/ & {host}/ to ~/
// for every file stored in this repo, beforeso we need
// to create a .bak/ of the origionals as this might
// well cause some issues...
const copyRecursiveSync = (src, dest) => {
const exists = fs.existsSync(src);
const stats = exists && fs.statSync(src);
const isDirectory = exists && stats.isDirectory();
if (isDirectory) {
fs.mkdirSync(dest);
fs.readdirSync(src).forEach(function(childItemName) {
copyRecursiveSync(path.join(src, childItemName),
path.join(dest, childItemName));
});
} else {
// recirsively make dest
const newDir = dest.split('/').splice(-1).join();
console.log(dir, newDir);
if (!fs.existsSync(newDir))
fs.mkdirSync(newDir, { recursive: true, overwrite: true });
fs.copyFileSync(src, dest, fs.constants.COPYFILE_FICLONE);
}
};
// since we can recursively copy we only need the top level directories
const basePaths = fs.readdirSync(parentDir);
const childPaths = fs.readdirSync(childDir);
// start by making the backup
const backupDir = home + 'dotfiles.bak/'; // TODO: make this a cmd option
console.log(`Backing up current dotfiles to ${backupDir}`);
if (!fs.existsSync(backupDir))
fs.mkdirSync(backupDir);
const allPaths = Array.from(new Set(basePaths.concat(childPaths)));
for (const path of allPaths) {
const copyTarget = home + path;
const backupTarget = backupDir + path;
console.log(`Moving ${copyTarget} to ${backupTarget}`);
copyRecursiveSync(copyTarget, backupTarget);
}
// we prioritise targetDir over parentDir