mirror of
https://github.com/dzeiocom/dotfiles.git
synced 2025-06-06 08:09:54 +00:00
Refactored everythings
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
parent
d0f8f945f3
commit
9c65463684
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,7 +1,5 @@
|
||||
build/
|
||||
.vscode/
|
||||
backups/
|
||||
dist/
|
||||
node_modules/
|
||||
*.js
|
||||
yarn-error.log
|
||||
package-lock.json
|
||||
|
10
.npmignore
Normal file
10
.npmignore
Normal file
@ -0,0 +1,10 @@
|
||||
.vscode/
|
||||
node_modules/
|
||||
src/
|
||||
.editorconfig
|
||||
.gitignore
|
||||
package-lock.json
|
||||
tsconfig.json
|
||||
yarn.lock
|
||||
yarn-error.log
|
||||
.npmignore
|
37
README.md
Normal file
37
README.md
Normal file
@ -0,0 +1,37 @@
|
||||
# DZEIO dotfiles 😄
|
||||
|
||||
Create and manage your dotfiles simply using the binary
|
||||
|
||||
```
|
||||
yarn global add @dzeio/dotfiles
|
||||
dotfiles
|
||||
```
|
||||
|
||||
and follow the software 💃
|
||||
|
||||
## Modules
|
||||
|
||||
Each Programs are modules so you can simply add new modules in the `modules/` folder.
|
||||
|
||||
a Future update will allllow to add external modules via `yarn`/`npm`
|
||||
|
||||
```
|
||||
Dzeio dotfiles
|
||||
Initial installation:
|
||||
- Initialize empty // install the default files in $config/.config/dzeio-dotfiles
|
||||
- Restore from git Repository (git **MUST** be installed on the system) // clone the repository in the folder
|
||||
```
|
||||
|
||||
```
|
||||
Dzeio Main Menu:
|
||||
- Save
|
||||
- Restore
|
||||
- Options
|
||||
- Exit
|
||||
```
|
||||
|
||||
```
|
||||
Dzeio Save/Restore Menu:
|
||||
- Quick save
|
||||
- Manual save
|
||||
```
|
20
Statics.ts
20
Statics.ts
@ -1,20 +0,0 @@
|
||||
import { Presets, MultiBar } from "cli-progress";
|
||||
|
||||
export default class Statics {
|
||||
|
||||
private static _multibar: MultiBar
|
||||
|
||||
public static set multibar(bar: MultiBar) {
|
||||
this._multibar = bar
|
||||
}
|
||||
|
||||
public static get multibar() {
|
||||
if (!this._multibar) this._multibar = new MultiBar({
|
||||
format: `{obj}: {percentage}% (${'{bar}'.cyan}) {action}: {el}`,
|
||||
clearOnComplete: false,
|
||||
hideCursor: true,
|
||||
synchronousUpdate: false
|
||||
}, Presets.shades_classic)
|
||||
return this._multibar
|
||||
}
|
||||
}
|
51
package.json
51
package.json
@ -1,30 +1,25 @@
|
||||
{
|
||||
"name": "dotfiles",
|
||||
"version": "0.1.0",
|
||||
"main": "build/cli.js",
|
||||
"bin": {
|
||||
"dotfiles": "./build/cli.js"
|
||||
},
|
||||
"license": "MIT",
|
||||
"private": false,
|
||||
"scripts": {
|
||||
"start": "ts-node index.ts",
|
||||
"build": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"clear": "^0.1.0",
|
||||
"cli-color": "^2.0.0",
|
||||
"cli-progress": "^3.3.1",
|
||||
"colors": "^1.4.0",
|
||||
"enquirer": "^2.3.2",
|
||||
"listr": "^0.14.3",
|
||||
"ora": "^4.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/cli-progress": "^3.4.0",
|
||||
"@types/node": "^13.1.1",
|
||||
"ts-node": "^8.5.4",
|
||||
"ts-node-dev": "^1.0.0-pre.44",
|
||||
"typescript": "^3.7.4"
|
||||
}
|
||||
"name": "@dzeio/dotfiles",
|
||||
"version": "1.0.0",
|
||||
"main": "./dist/cjs/cli.js",
|
||||
"types": "./dist/types/cli.d.ts",
|
||||
"bin": {
|
||||
"dotfiles": "./dist/cjs/cli.js"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"start": "ts-node src/cli.ts",
|
||||
"build": "tsc",
|
||||
"prepublishOnly": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"colors": "^1.4.0",
|
||||
"enquirer": "^2.3.2",
|
||||
"listr": "^0.14.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^13.1.1",
|
||||
"ts-node": "^8.5.4",
|
||||
"typescript": "^3.7.4"
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,6 @@ async function processFile(src: string, dest: string) {
|
||||
export async function confirmOverride(filename: string): Promise<boolean> {
|
||||
const doOverride = new Options().getConfig().override
|
||||
if (typeof doOverride === "boolean" ) return doOverride
|
||||
Statics.multibar.stop()
|
||||
clear()
|
||||
const resp = await new Confirm({
|
||||
name: "override",
|
||||
@ -146,14 +145,22 @@ export async function processCommand(command: string, location: string, filename
|
||||
|
||||
|
||||
export async function getModules(): Promise<Array<string>> {
|
||||
return ['Fish', 'HyperJS', 'Nano', 'OhMyFish', 'VSCode', 'Yarn']
|
||||
const res = []
|
||||
let els = await fs.readdir("./modules")
|
||||
for (const el of els) {
|
||||
res.push(
|
||||
el.substr(0, el.length-3)
|
||||
)
|
||||
console.log(`${__dirname}/modules`)
|
||||
|
||||
try {
|
||||
let els = await fs.readdir(`${__dirname}/modules`)
|
||||
for (const el of els) {
|
||||
res.push(
|
||||
el.substr(0, el.length-3)
|
||||
)
|
||||
}
|
||||
return res
|
||||
} catch {
|
||||
console.log(`${__dirname}/modules`)
|
||||
throw new Error(`${__dirname}/modules`)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
export function capitalize(str: string) {
|
@ -1,6 +1,7 @@
|
||||
import { getUserHome, getModules } from "./Functions"
|
||||
import fs, {promises as fsp} from "fs"
|
||||
import { getModules } from "./Functions"
|
||||
import fs, { promises as fsp } from "fs"
|
||||
import 'colors'
|
||||
import Statics from './Statics'
|
||||
|
||||
const { MultiSelect, Select } = require('enquirer')
|
||||
|
||||
@ -11,13 +12,20 @@ interface p {
|
||||
|
||||
export default class Options {
|
||||
|
||||
private configFolder = `${getUserHome()}/.config/dzeio-dotfiles/`
|
||||
private configFolder = Statics.folder
|
||||
private configFile = `config.yml`
|
||||
|
||||
private location: string
|
||||
|
||||
private config: p
|
||||
|
||||
private static defaultReadme = `
|
||||
# Dotfiles
|
||||
|
||||
_This dotfiles was generated using https://www.npmjs.com/package/@dzeio/dotfiles_
|
||||
`
|
||||
|
||||
|
||||
public constructor() {
|
||||
this.location = `${this.configFolder}/${this.configFile}`
|
||||
try {
|
||||
@ -26,6 +34,7 @@ export default class Options {
|
||||
} catch {
|
||||
fs.mkdirSync(this.configFolder)
|
||||
this.config = this.defaultConfig()
|
||||
fs.writeFileSync(`${this.configFolder}/README.md`, Options.defaultReadme)
|
||||
this.save()
|
||||
}
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
import ModuleInterface from "./ModuleInterface"
|
||||
import ModuleInterface from "./interfaces/ModuleInterface"
|
||||
import { copy, processCommand } from "./Functions"
|
||||
import FileInterface from "./FileInterface"
|
||||
import FileInterface from "./interfaces/FileInterface"
|
||||
import Requirements from "./Prerequises"
|
||||
import Logger from "./Logger"
|
||||
import ListI, { ListrInterface } from "./interfaces/Listr"
|
||||
import Statics from "./Statics"
|
||||
const Listr: ListI = require('listr')
|
||||
|
||||
export default abstract class SimpleModule implements ModuleInterface {
|
||||
@ -23,7 +24,7 @@ export default abstract class SimpleModule implements ModuleInterface {
|
||||
|
||||
public async save(): Promise<ListI> {
|
||||
|
||||
const directory = `./backups/${this.moduleName}`
|
||||
const directory = `${Statics.folder}/backups/${this.moduleName}`
|
||||
const subTasks: ListrInterface[] = []
|
||||
|
||||
for (const file of this.files) {
|
8
src/Statics.ts
Normal file
8
src/Statics.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { getUserHome } from "./Functions";
|
||||
|
||||
export default class Statics {
|
||||
|
||||
public static get folder(): string {
|
||||
return `${getUserHome()}/.config/dzeio-dotfiles`
|
||||
}
|
||||
}
|
@ -1,16 +1,22 @@
|
||||
#!/usr/bin/env node
|
||||
console.clear()
|
||||
|
||||
const pkg = require('../package.json')
|
||||
|
||||
console.log(`[${pkg.name}] version ${pkg.version}`)
|
||||
|
||||
import Logger from './Logger'
|
||||
import ModuleInterface from './ModuleInterface'
|
||||
import ModuleInterface from './interfaces/ModuleInterface'
|
||||
import Options from './Options'
|
||||
import { getModules } from './Functions'
|
||||
import ListI, { ListrInterface } from './interfaces/Listr'
|
||||
import Statics from './Statics'
|
||||
|
||||
const logger = Logger.getInstance()
|
||||
const options = new Options()
|
||||
|
||||
function getSelect(Select: any) {
|
||||
function getSelect() {
|
||||
const { Select } = require('enquirer')
|
||||
return new Select({
|
||||
name: "dotfiles",
|
||||
message: "Select the action to run",
|
||||
@ -30,6 +36,9 @@ function getSelect(Select: any) {
|
||||
},{
|
||||
name: 'options',
|
||||
message: 'Options'
|
||||
},{
|
||||
name: 'git',
|
||||
message: 'Git'
|
||||
},{
|
||||
name: 'exit',
|
||||
message: 'Exit'
|
||||
@ -39,7 +48,7 @@ function getSelect(Select: any) {
|
||||
}
|
||||
|
||||
async function saveModule(moduleName: string, save = false): Promise<ListI> {
|
||||
const md = `./modules/${moduleName}`
|
||||
const md = `${__dirname}/modules/${moduleName}`
|
||||
const module: ModuleInterface = new (await require(md).default)(moduleName)
|
||||
if (save) {
|
||||
return module.save()
|
||||
@ -49,12 +58,13 @@ async function saveModule(moduleName: string, save = false): Promise<ListI> {
|
||||
}
|
||||
|
||||
async function bootstrap(): Promise<never> {
|
||||
const { Select, MultiSelect } = await require('enquirer');
|
||||
const { MultiSelect } = await require('enquirer');
|
||||
const Listr: ListI = await require('listr')
|
||||
console.log(`${__dirname}`)
|
||||
|
||||
let response: string = ""
|
||||
try {
|
||||
response = await getSelect(Select).run()
|
||||
response = await getSelect().run()
|
||||
} catch {
|
||||
process.exit(process.exitCode)
|
||||
}
|
||||
@ -96,6 +106,10 @@ async function bootstrap(): Promise<never> {
|
||||
case "options":
|
||||
await options.manager()
|
||||
await bootstrap()
|
||||
break
|
||||
case "git":
|
||||
console.log(`cd ${Statics.folder}`)
|
||||
// execSync(`git push`)
|
||||
default:
|
||||
break;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import Requirements from "./Prerequises";
|
||||
import Requirements from "../Prerequises";
|
||||
|
||||
export default interface FileInterface {
|
||||
displayName?: string,
|
@ -1,5 +1,4 @@
|
||||
import { SingleBar } from "cli-progress";
|
||||
import ListI from "./interfaces/Listr";
|
||||
import ListI from "./Listr"
|
||||
|
||||
export default interface ModuleInterface {
|
||||
moduleName?: string
|
@ -1,6 +1,6 @@
|
||||
import SimpleModule from "../SimpleModule";
|
||||
import { getUserHome } from "../Functions";
|
||||
import FileInterface from "../FileInterface";
|
||||
import FileInterface from "../interfaces/FileInterface";
|
||||
|
||||
export default class Fish extends SimpleModule {
|
||||
files: FileInterface[] = [
|
@ -1,6 +1,6 @@
|
||||
import SimpleModule from "../SimpleModule";
|
||||
import { getUserHome } from "../Functions";
|
||||
import FileInterface from "../FileInterface";
|
||||
import FileInterface from "../interfaces/FileInterface";
|
||||
|
||||
export default class HyperJS extends SimpleModule {
|
||||
files: FileInterface[] = [
|
@ -1,5 +1,5 @@
|
||||
import SimpleModule from "../SimpleModule"
|
||||
import FileInterface from "../FileInterface"
|
||||
import FileInterface from "../interfaces/FileInterface"
|
||||
import { getUserHome } from "../Functions"
|
||||
|
||||
export default class Nano extends SimpleModule {
|
@ -1,5 +1,5 @@
|
||||
import SimpleModule from "../SimpleModule"
|
||||
import FileInterface from "../FileInterface"
|
||||
import FileInterface from "../interfaces/FileInterface"
|
||||
import Requirements from "../Prerequises"
|
||||
import { execSync } from "child_process"
|
||||
|
@ -1,11 +1,10 @@
|
||||
import SimpleModule from "../SimpleModule";
|
||||
import fsSync, { promises as fs } from "fs";
|
||||
import fsSync from "fs";
|
||||
import { getUserHome } from "../Functions";
|
||||
|
||||
import { execSync } from "child_process";
|
||||
import FileInterface from "../FileInterface";
|
||||
import FileInterface from "../interfaces/FileInterface";
|
||||
import Requirements from "../Prerequises";
|
||||
import 'colors'
|
||||
|
||||
export default class VSCode extends SimpleModule {
|
||||
files: FileInterface[] = [
|
@ -1,6 +1,6 @@
|
||||
import SimpleModule from "../SimpleModule";
|
||||
import { getUserHome } from "../Functions";
|
||||
import FileInterface from "../FileInterface";
|
||||
import FileInterface from "../interfaces/FileInterface";
|
||||
|
||||
export default class Yarn extends SimpleModule {
|
||||
files: FileInterface[] = [
|
@ -1,11 +1,14 @@
|
||||
{
|
||||
"include": ["cli.ts", "modules/*"],
|
||||
"include": ["src/cli.ts", "src/modules/*"],
|
||||
"exclude": [
|
||||
".vscode/",
|
||||
"node_modules/",
|
||||
"backups/"
|
||||
"build/"
|
||||
],
|
||||
"compilerOptions": {
|
||||
|
||||
"resolveJsonModule": true,
|
||||
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
@ -14,12 +17,13 @@
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
"declarationDir": "./dist/types",
|
||||
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
"sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./dotfiles.js", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./build/", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
"outDir": "./dist/cjs", /* Redirect output structure to the directory. */
|
||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user