fist commit

This commit is contained in:
Guillaume "B.B." Van Hemmen 2024-08-07 10:43:19 +02:00
commit a27fca4dea
Signed by: GuillaumeHemmen
GPG key ID: 7921E64524F7EB35
17 changed files with 5033 additions and 0 deletions

18
.eslintrc.js Normal file
View file

@ -0,0 +1,18 @@
/**
* @type {import("eslint").Linter.Config}
*/
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
extends: [
'plugin:@typescript-eslint/recommended',
'prettier',
'plugin:prettier/recommended',
],
rules: {},
}

8
.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
.DS_Store
node_modules
npm-debug.log
coverage
.nyc_output
dist
build
.vscode

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2017
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,31 @@
import { system, filesystem } from 'gluegun'
const src = filesystem.path(__dirname, '..')
const cli = async (cmd) =>
system.run(
'node ' + filesystem.path(src, 'bin', 'docker-volume-manager') + ` ${cmd}`
)
test('outputs version', async () => {
const output = await cli('--version')
expect(output).toContain('0.0.1')
})
test('outputs help', async () => {
const output = await cli('--help')
expect(output).toContain('0.0.1')
})
test('generates file', async () => {
const output = await cli('generate foo')
expect(output).toContain('Generated file at models/foo-model.ts')
const foomodel = filesystem.read('models/foo-model.ts')
expect(foomodel).toContain(`module.exports = {`)
expect(foomodel).toContain(`name: 'foo'`)
// cleanup artifact
filesystem.remove('models')
})

21
bin/docker-volume-manager Executable file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env node
/* tslint:disable */
// check if we're running in dev mode
var devMode = require('fs').existsSync(`${__dirname}/../src`)
// or want to "force" running the compiled version with --compiled-build
var wantsCompiled = process.argv.indexOf('--compiled-build') >= 0
if (wantsCompiled || !devMode) {
// this runs from the compiled javascript source
require(`${__dirname}/../build/cli`).run(process.argv)
} else {
// this runs from the typescript source (for dev only)
// hook into ts-node so we can run typescript on the fly
require('ts-node').register({ project: `${__dirname}/../tsconfig.json` })
// run the CLI with the current process arguments
require(`${__dirname}/../src/cli`).run(process.argv)
}

3
docs/commands.md Normal file
View file

@ -0,0 +1,3 @@
# Command Reference for docker-volume-manager
TODO: Add your command reference here

47
docs/plugins.md Normal file
View file

@ -0,0 +1,47 @@
# Plugin guide for docker-volume-manager
Plugins allow you to add features to docker-volume-manager, such as commands and
extensions to the `toolbox` object that provides the majority of the functionality
used by docker-volume-manager.
Creating a docker-volume-manager plugin is easy. Just create a repo with two folders:
```
commands/
extensions/
```
A command is a file that looks something like this:
```js
// commands/foo.js
module.exports = {
run: (toolbox) => {
const { print, filesystem } = toolbox
const desktopDirectories = filesystem.subdirectories(`~/Desktop`)
print.info(desktopDirectories)
}
}
```
An extension lets you add additional features to the `toolbox`.
```js
// extensions/bar-extension.js
module.exports = (toolbox) => {
const { print } = toolbox
toolbox.bar = () => { print.info('Bar!') }
}
```
This is then accessible in your plugin's commands as `toolbox.bar`.
# Loading a plugin
To load a particular plugin (which has to start with `docker-volume-manager-*`),
install it to your project using `npm install --save-dev docker-volume-manager-PLUGINNAME`,
and docker-volume-manager will pick it up automatically.

63
package.json Normal file
View file

@ -0,0 +1,63 @@
{
"name": "docker-volume-manager",
"version": "0.0.1",
"description": "docker-volume-manager CLI",
"private": true,
"types": "build/types/types.d.ts",
"bin": {
"docker-volume-manager": "bin/docker-volume-manager"
},
"scripts": {
"clean-build": "rimraf -rf ./build",
"compile": "tsc -p .",
"copy-templates": "copyfiles ./src/templates/* ./build/templates",
"build": "yarn clean-build && yarn compile && yarn copy-templates",
"prepublishOnly": "yarn build",
"format": "eslint \"**/*.{js,jsx,ts,tsx}\" --fix && prettier \"**/*.{js,jsx,ts,tsx,json}\" --write",
"test": "jest",
"watch": "jest --watch",
"snapupdate": "jest --updateSnapshot",
"coverage": "jest --coverage"
},
"files": [
"build",
"LICENSE",
"readme.md",
"docs",
"bin"
],
"license": "MIT",
"dependencies": {
"gluegun": "latest"
},
"devDependencies": {
"@types/node": "^12.7.11",
"@types/jest": "^26.0.20",
"@typescript-eslint/eslint-plugin": "^4.17.0",
"@typescript-eslint/parser": "^4.17.0",
"ts-jest": "^26.5.3",
"ts-node": "^10.9.1",
"typescript": "~4.5.0",
"copyfiles": "^2.4.1",
"eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"husky": "^5.1.3",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"pretty-quick": "^3.1.0"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node"
},
"prettier": {
"semi": false,
"singleQuote": true
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
}
}

26
readme.md Normal file
View file

@ -0,0 +1,26 @@
# docker-volume-manager CLI
A CLI program running gluegunJS to easily manage your docker volumes
## Customizing your CLI
Check out the documentation at https://github.com/infinitered/gluegun/tree/master/docs.
## Publishing to NPM
To package your CLI up for NPM, do this:
```shell
$ npm login
$ npm whoami
$ npm test
$ npm run build
$ npm publish
```
# License
MIT - see LICENSE

28
src/cli.ts Normal file
View file

@ -0,0 +1,28 @@
import { build } from 'gluegun'
/**
* Create the cli and kick it off
*/
async function run(argv) {
// create a CLI runtime
const cli = build()
.brand('docker-volume-manager')
.src(__dirname)
.plugins('./node_modules', {
matching: 'docker-volume-manager-*',
hidden: true,
})
.help() // provides default for help, h, --help, -h
.version() // provides default for version, v, --version, -v
.create()
// enable the following method if you'd like to skip loading one of these core extensions
// this can improve performance if they're not necessary for your project:
// .exclude(['meta', 'strings', 'print', 'filesystem', 'semver', 'system', 'prompt', 'http', 'template', 'patching', 'package-manager'])
// and run it
const toolbox = await cli.run(argv)
// send it back (for testing, mostly)
return toolbox
}
module.exports = { run }

View file

@ -0,0 +1,12 @@
import { GluegunCommand } from 'gluegun'
const command: GluegunCommand = {
name: 'docker-volume-manager',
run: async (toolbox) => {
const { print } = toolbox
print.info('Welcome to your CLI')
},
}
module.exports = command

23
src/commands/generate.ts Normal file
View file

@ -0,0 +1,23 @@
import { GluegunToolbox } from 'gluegun'
module.exports = {
name: 'generate',
alias: ['g'],
run: async (toolbox: GluegunToolbox) => {
const {
parameters,
template: { generate },
print: { info },
} = toolbox
const name = parameters.first
await generate({
template: 'model.ts.ejs',
target: `models/${name}-model.ts`,
props: { name },
})
info(`Generated file at models/${name}-model.ts`)
},
}

View file

@ -0,0 +1,17 @@
import { GluegunToolbox } from 'gluegun'
// add your CLI-specific functionality here, which will then be accessible
// to your commands
module.exports = (toolbox: GluegunToolbox) => {
toolbox.foo = () => {
toolbox.print.info('called foo extension')
}
// enable this if you want to read configuration in from
// the current folder's package.json (in a "docker-volume-manager" property),
// docker-volume-manager.config.json, etc.
// toolbox.config = {
// ...toolbox.config,
// ...toolbox.config.loadConfig("docker-volume-manager", process.cwd())
// }
}

View file

@ -0,0 +1,3 @@
module.exports = {
name: '<%= props.name %>'
}

1
src/types.ts Normal file
View file

@ -0,0 +1 @@
// export types

28
tsconfig.json Normal file
View file

@ -0,0 +1,28 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": false,
"experimentalDecorators": true,
"lib": [
"es2015",
"scripthost",
"es2015.promise",
"es2015.generator",
"es2015.iterable",
"dom"
],
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": false,
"noImplicitThis": true,
"noUnusedLocals": true,
"sourceMap": true,
"inlineSourceMap": true,
"outDir": "build",
"strict": false,
"target": "es5",
"declaration": true,
"declarationDir": "build/types"
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}

4683
yarn.lock Normal file

File diff suppressed because it is too large Load diff