codesnippets-cli
v1.2.0
Published
A CLI tool for importing and exporting code snippets via https://codesnippets.dev
Downloads
16
Maintainers
Readme
CodeSnippets.dev CLI (BETA)
CodeSnippets.dev is a service that allows you to publish code snippets for easy reuse across projects and teams. Gone are the days of hunting through folders and projects looking for that one snippet of code to copy and paste.
Basic Example
Imagine you created a nice little utility function, getQueryStringParam.js
inside of ProjectA. You can do "future you" a favor and export
it as code snippet.
snippets export src/utils/getQueryStringParam.js
Then two months later, when the same need arises while working on ProjectB, you can quickly import
it.
snippets import getQueryStringParam.js --out src/shared
Getting Started
Install the CLI via NPM
npm install -g codesnippets-cli
Then login:
snippets login
Available Commands
- list - Display a list of your (or a specified user's) code snippets
- export <filepath> - Export a local file to create a new CodeSnippet
- import <snippetPath> - Import a remote CodeSnippet to be saved as a local file.
- remove <snippetPath> - Remove a CodeSnippet you have created
- settings - Display your CodeSnippets.dev CLI settings
- login - Log into the CodeSnippets.dev CLI
- logout - Log out of the CodeSnippets.dev CLI
List
Display the available code snippets. By default your own, but you can specify a CodeSnippets.dev user.
snippets list [--user <value>] [--collection <value>]
List Examples
Show all of your own snippets
snippets list
Show all your snippets from a specified collection
snippets list --collection utils
Show all of another user's snippets
snippets list --user droopytersen
Export
Export a local file to be available as a CodeSnippets.dev snippet.
snippets export <filepath> [--title <value>] [--collection <value>] [--details <value>] [--overwrite]
- If already have a snippet with a matching
filename
andcollection
, you must pass the--overwrite
flag. - When you run the export command without any options you will be prompted for the required parmeters.
Export Examples
Export a file
snippets export src/components/Slider.jsx
Export a file to a specific collection
snippets export src/components/Slider.jsx --collection components
Import
Save available CodeSnippets.dev snippets as local files.
snippets import <snippet> [--path <value>] [--overwrite]
- If a local file already exists, you will need to pass the
--overwrite
flag - If the given
--path
doesn't exist, you will receive an error
Import Examples
Import a snippet file to the current folder
Get your snippet that has a filename of Slider.tsx
and save it locally to the current directory
snippets import Slider.tsx
Import a snippet file to a specific folder
If the destination folder doesn't exist, it will automatically be created
Get your snippet that has a filename of Slider.tsx
and save it locally to src/components/Slider
snippets import Slider.tsx --out src/components/Slider
Import a snippet to a specific folder with a different filename
If you include a filename in the --out
path, then that filename will be used instead of the Snippet's filename.
snippets import Slider.tsx --out src/components/AnimatedSlider/AnimatedSlider.tsx
Import a snippet file from a specific collection
Look in your utils
collection for a snippet named debounce.js
and save it to the current folder
snippets import utils/debounce.js
Import an entire collection
You can import an entire collection with the COLLECTION/
syntax
Import every snippet file that exists in your utils
collection and save them locally in the src/utils
folder.
snippets import utils/ --out src/utils
Import another user's entire collection
You can import an entire collection of another user with the USERNAME/COLLECTION/
syntax
Import every snippet file that exists in DroopyTersen's utils
collection and save them locally in the src/utils
folder.
snippets import droopytersen/utils/ --out src/utils
Login / Logout
Log in and out of the CodeSnippets.dev CLI
snippets login
snippets logout
Settings
For development only. Allows you to see your env configuration as well as switch from local
to dev
to prod
.
snippets settings [--env <value>]
Display current environment settings
snippets settings
Switch to a different environment
Switch to the dev
environment. You might have to login again if it is your first time using the targeted env.
snippets settings --env dev