Refactored everythings

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2020-01-09 09:13:33 +01:00
parent d0f8f945f3
commit 9c65463684
No known key found for this signature in database
GPG Key ID: B143FF27EF555D16
23 changed files with 156 additions and 869 deletions

4
.gitignore vendored
View File

@ -1,7 +1,5 @@
build/
.vscode/ .vscode/
backups/ dist/
node_modules/ node_modules/
*.js
yarn-error.log yarn-error.log
package-lock.json package-lock.json

10
.npmignore Normal file
View 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
View 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
```

View File

@ -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
}
}

View File

@ -1,30 +1,25 @@
{ {
"name": "dotfiles", "name": "@dzeio/dotfiles",
"version": "0.1.0", "version": "1.0.0",
"main": "build/cli.js", "main": "./dist/cjs/cli.js",
"types": "./dist/types/cli.d.ts",
"bin": { "bin": {
"dotfiles": "./build/cli.js" "dotfiles": "./dist/cjs/cli.js"
}, },
"license": "MIT", "license": "MIT",
"private": false,
"scripts": { "scripts": {
"start": "ts-node index.ts", "start": "ts-node src/cli.ts",
"build": "tsc" "build": "tsc",
"prepublishOnly": "tsc"
}, },
"dependencies": { "dependencies": {
"clear": "^0.1.0",
"cli-color": "^2.0.0",
"cli-progress": "^3.3.1",
"colors": "^1.4.0", "colors": "^1.4.0",
"enquirer": "^2.3.2", "enquirer": "^2.3.2",
"listr": "^0.14.3", "listr": "^0.14.3"
"ora": "^4.0.3"
}, },
"devDependencies": { "devDependencies": {
"@types/cli-progress": "^3.4.0",
"@types/node": "^13.1.1", "@types/node": "^13.1.1",
"ts-node": "^8.5.4", "ts-node": "^8.5.4",
"ts-node-dev": "^1.0.0-pre.44",
"typescript": "^3.7.4" "typescript": "^3.7.4"
} }
} }

View File

@ -50,7 +50,6 @@ async function processFile(src: string, dest: string) {
export async function confirmOverride(filename: string): Promise<boolean> { export async function confirmOverride(filename: string): Promise<boolean> {
const doOverride = new Options().getConfig().override const doOverride = new Options().getConfig().override
if (typeof doOverride === "boolean" ) return doOverride if (typeof doOverride === "boolean" ) return doOverride
Statics.multibar.stop()
clear() clear()
const resp = await new Confirm({ const resp = await new Confirm({
name: "override", name: "override",
@ -146,14 +145,22 @@ export async function processCommand(command: string, location: string, filename
export async function getModules(): Promise<Array<string>> { export async function getModules(): Promise<Array<string>> {
return ['Fish', 'HyperJS', 'Nano', 'OhMyFish', 'VSCode', 'Yarn']
const res = [] const res = []
let els = await fs.readdir("./modules") console.log(`${__dirname}/modules`)
try {
let els = await fs.readdir(`${__dirname}/modules`)
for (const el of els) { for (const el of els) {
res.push( res.push(
el.substr(0, el.length-3) el.substr(0, el.length-3)
) )
} }
return res return res
} catch {
console.log(`${__dirname}/modules`)
throw new Error(`${__dirname}/modules`)
}
} }
export function capitalize(str: string) { export function capitalize(str: string) {

View File

@ -1,6 +1,7 @@
import { getUserHome, getModules } from "./Functions" import { getModules } from "./Functions"
import fs, {promises as fsp} from "fs" import fs, { promises as fsp } from "fs"
import 'colors' import 'colors'
import Statics from './Statics'
const { MultiSelect, Select } = require('enquirer') const { MultiSelect, Select } = require('enquirer')
@ -11,13 +12,20 @@ interface p {
export default class Options { export default class Options {
private configFolder = `${getUserHome()}/.config/dzeio-dotfiles/` private configFolder = Statics.folder
private configFile = `config.yml` private configFile = `config.yml`
private location: string private location: string
private config: p private config: p
private static defaultReadme = `
# Dotfiles
_This dotfiles was generated using https://www.npmjs.com/package/@dzeio/dotfiles_
`
public constructor() { public constructor() {
this.location = `${this.configFolder}/${this.configFile}` this.location = `${this.configFolder}/${this.configFile}`
try { try {
@ -26,6 +34,7 @@ export default class Options {
} catch { } catch {
fs.mkdirSync(this.configFolder) fs.mkdirSync(this.configFolder)
this.config = this.defaultConfig() this.config = this.defaultConfig()
fs.writeFileSync(`${this.configFolder}/README.md`, Options.defaultReadme)
this.save() this.save()
} }
} }

View File

@ -1,9 +1,10 @@
import ModuleInterface from "./ModuleInterface" import ModuleInterface from "./interfaces/ModuleInterface"
import { copy, processCommand } from "./Functions" import { copy, processCommand } from "./Functions"
import FileInterface from "./FileInterface" import FileInterface from "./interfaces/FileInterface"
import Requirements from "./Prerequises" import Requirements from "./Prerequises"
import Logger from "./Logger" import Logger from "./Logger"
import ListI, { ListrInterface } from "./interfaces/Listr" import ListI, { ListrInterface } from "./interfaces/Listr"
import Statics from "./Statics"
const Listr: ListI = require('listr') const Listr: ListI = require('listr')
export default abstract class SimpleModule implements ModuleInterface { export default abstract class SimpleModule implements ModuleInterface {
@ -23,7 +24,7 @@ export default abstract class SimpleModule implements ModuleInterface {
public async save(): Promise<ListI> { public async save(): Promise<ListI> {
const directory = `./backups/${this.moduleName}` const directory = `${Statics.folder}/backups/${this.moduleName}`
const subTasks: ListrInterface[] = [] const subTasks: ListrInterface[] = []
for (const file of this.files) { for (const file of this.files) {

8
src/Statics.ts Normal file
View File

@ -0,0 +1,8 @@
import { getUserHome } from "./Functions";
export default class Statics {
public static get folder(): string {
return `${getUserHome()}/.config/dzeio-dotfiles`
}
}

View File

@ -1,16 +1,22 @@
#!/usr/bin/env node #!/usr/bin/env node
console.clear() console.clear()
const pkg = require('../package.json')
console.log(`[${pkg.name}] version ${pkg.version}`)
import Logger from './Logger' import Logger from './Logger'
import ModuleInterface from './ModuleInterface' import ModuleInterface from './interfaces/ModuleInterface'
import Options from './Options' import Options from './Options'
import { getModules } from './Functions' import { getModules } from './Functions'
import ListI, { ListrInterface } from './interfaces/Listr' import ListI, { ListrInterface } from './interfaces/Listr'
import Statics from './Statics'
const logger = Logger.getInstance() const logger = Logger.getInstance()
const options = new Options() const options = new Options()
function getSelect(Select: any) { function getSelect() {
const { Select } = require('enquirer')
return new Select({ return new Select({
name: "dotfiles", name: "dotfiles",
message: "Select the action to run", message: "Select the action to run",
@ -30,6 +36,9 @@ function getSelect(Select: any) {
},{ },{
name: 'options', name: 'options',
message: 'Options' message: 'Options'
},{
name: 'git',
message: 'Git'
},{ },{
name: 'exit', name: 'exit',
message: 'Exit' message: 'Exit'
@ -39,7 +48,7 @@ function getSelect(Select: any) {
} }
async function saveModule(moduleName: string, save = false): Promise<ListI> { 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) const module: ModuleInterface = new (await require(md).default)(moduleName)
if (save) { if (save) {
return module.save() return module.save()
@ -49,12 +58,13 @@ async function saveModule(moduleName: string, save = false): Promise<ListI> {
} }
async function bootstrap(): Promise<never> { async function bootstrap(): Promise<never> {
const { Select, MultiSelect } = await require('enquirer'); const { MultiSelect } = await require('enquirer');
const Listr: ListI = await require('listr') const Listr: ListI = await require('listr')
console.log(`${__dirname}`)
let response: string = "" let response: string = ""
try { try {
response = await getSelect(Select).run() response = await getSelect().run()
} catch { } catch {
process.exit(process.exitCode) process.exit(process.exitCode)
} }
@ -96,6 +106,10 @@ async function bootstrap(): Promise<never> {
case "options": case "options":
await options.manager() await options.manager()
await bootstrap() await bootstrap()
break
case "git":
console.log(`cd ${Statics.folder}`)
// execSync(`git push`)
default: default:
break; break;
} }

View File

@ -1,4 +1,4 @@
import Requirements from "./Prerequises"; import Requirements from "../Prerequises";
export default interface FileInterface { export default interface FileInterface {
displayName?: string, displayName?: string,

View File

@ -1,5 +1,4 @@
import { SingleBar } from "cli-progress"; import ListI from "./Listr"
import ListI from "./interfaces/Listr";
export default interface ModuleInterface { export default interface ModuleInterface {
moduleName?: string moduleName?: string

View File

@ -1,6 +1,6 @@
import SimpleModule from "../SimpleModule"; import SimpleModule from "../SimpleModule";
import { getUserHome } from "../Functions"; import { getUserHome } from "../Functions";
import FileInterface from "../FileInterface"; import FileInterface from "../interfaces/FileInterface";
export default class Fish extends SimpleModule { export default class Fish extends SimpleModule {
files: FileInterface[] = [ files: FileInterface[] = [

View File

@ -1,6 +1,6 @@
import SimpleModule from "../SimpleModule"; import SimpleModule from "../SimpleModule";
import { getUserHome } from "../Functions"; import { getUserHome } from "../Functions";
import FileInterface from "../FileInterface"; import FileInterface from "../interfaces/FileInterface";
export default class HyperJS extends SimpleModule { export default class HyperJS extends SimpleModule {
files: FileInterface[] = [ files: FileInterface[] = [

View File

@ -1,5 +1,5 @@
import SimpleModule from "../SimpleModule" import SimpleModule from "../SimpleModule"
import FileInterface from "../FileInterface" import FileInterface from "../interfaces/FileInterface"
import { getUserHome } from "../Functions" import { getUserHome } from "../Functions"
export default class Nano extends SimpleModule { export default class Nano extends SimpleModule {

View File

@ -1,5 +1,5 @@
import SimpleModule from "../SimpleModule" import SimpleModule from "../SimpleModule"
import FileInterface from "../FileInterface" import FileInterface from "../interfaces/FileInterface"
import Requirements from "../Prerequises" import Requirements from "../Prerequises"
import { execSync } from "child_process" import { execSync } from "child_process"

View File

@ -1,11 +1,10 @@
import SimpleModule from "../SimpleModule"; import SimpleModule from "../SimpleModule";
import fsSync, { promises as fs } from "fs"; import fsSync from "fs";
import { getUserHome } from "../Functions"; import { getUserHome } from "../Functions";
import { execSync } from "child_process"; import { execSync } from "child_process";
import FileInterface from "../FileInterface"; import FileInterface from "../interfaces/FileInterface";
import Requirements from "../Prerequises"; import Requirements from "../Prerequises";
import 'colors'
export default class VSCode extends SimpleModule { export default class VSCode extends SimpleModule {
files: FileInterface[] = [ files: FileInterface[] = [

View File

@ -1,6 +1,6 @@
import SimpleModule from "../SimpleModule"; import SimpleModule from "../SimpleModule";
import { getUserHome } from "../Functions"; import { getUserHome } from "../Functions";
import FileInterface from "../FileInterface"; import FileInterface from "../interfaces/FileInterface";
export default class Yarn extends SimpleModule { export default class Yarn extends SimpleModule {
files: FileInterface[] = [ files: FileInterface[] = [

View File

@ -1,11 +1,14 @@
{ {
"include": ["cli.ts", "modules/*"], "include": ["src/cli.ts", "src/modules/*"],
"exclude": [ "exclude": [
".vscode/", ".vscode/",
"node_modules/", "node_modules/",
"backups/" "build/"
], ],
"compilerOptions": { "compilerOptions": {
"resolveJsonModule": true,
/* Basic Options */ /* Basic Options */
// "incremental": true, /* Enable incremental compilation */ // "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "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. */ // "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */ // "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */ "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ "declarationDir": "./dist/types",
// "sourceMap": true, /* Generates corresponding '.map' file. */ "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. */ // "outFile": "./dotfiles.js", /* Concatenate and emit output to single file. */
"outDir": "./build/", /* Redirect output structure to the directory. */ "outDir": "./dist/cjs", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */ // "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */ // "removeComments": true, /* Do not emit comments to output. */

790
yarn.lock

File diff suppressed because it is too large Load Diff