https://github.com/downgoon/cpmd
copy or move markdown files (supporting wildcard characters) to the destination directory **with their attached images** usually located on sub dir named 'assets' or 'images'.
https://github.com/downgoon/cpmd
copy-markdown-file-and-images cpmd markdown-images
Last synced: 3 months ago
JSON representation
copy or move markdown files (supporting wildcard characters) to the destination directory **with their attached images** usually located on sub dir named 'assets' or 'images'.
- Host: GitHub
- URL: https://github.com/downgoon/cpmd
- Owner: downgoon
- Created: 2019-06-21T08:51:24.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-10T05:56:07.000Z (almost 6 years ago)
- Last Synced: 2025-03-17T18:05:15.395Z (3 months ago)
- Topics: copy-markdown-file-and-images, cpmd, markdown-images
- Language: JavaScript
- Homepage:
- Size: 374 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](http://hits.dwyl.io/downgoon/cpmd)
# cpmd
copy or move markdown files (supporting wildcard characters) to the destination directory **with their attached images** usually located on sub dir named 'assets', 'images' or '$filename'. the application has been published into https://www.npmjs.com/package/cpmd. By the way, An awesome editor [Typora](https://typora.io/) is recommended, if you also like writing in markdown.
## Quick Start
- **Install**: install command line tool 'cpmd' (copy markdown)
``` bash
$ npm install cpmd -g
```- **Single Copy**: copy a single file named 'README.md' with its referenced image 'assets/image-20190625115442118.png' into the existed dir 'backup' in long term format.
``` bash
$ cpmd --src README.md --dst backup/src file wildcard: README.md
src file list: README.md
cp assets/image-20190625115442118.png to /Users/downgoon/Documents/backup
cp README.md to /Users/downgoon/Documents/backup
```- **Single Move**: move a single file in short term format. the additional argument '-m' or `--move` indicates a moving operation rather than copying.
``` bash
$ cpmd -s README.md -d backup/ -m
src file wildcard: README.md
src file list: README.md
mv assets/image-20190625115442118.png to /Users/downgoon/Documents/backup/
mv README.md to /Users/downgoon/Documents/backup/
```- **Multi Copy/Move**: copy two files named 'README.md' and 'REMORE.md'.
``` bash
$ cpmd -s 'RE*.md' -d backup/
src file wildcard: RE*.md
src file list: README.md,REMORE.md
cp assets/image-20190625115442118.png to /Users/downgoon/Documents/backup/
cp README.md to /Users/downgoon/Documents/backup/
cp REMORE.md to /Users/downgoon/Documents/backup/$ tree . # the two files' layout
.
├── README.md
├── REMORE.md
└── assets
└── image-20190625115442118.png
```> **NOTE**: wildcard src fie name like 'RE*.md' **MUST** be quoted by single quotation marks ``'``.
- **hexo-style copy**: in [hexo](https://hexo.io/docs/asset-folders), Asset folder will have the same name as the markdown file associated with the post. Place all assets related to your post into the associated folder, and you will be able to reference them using a relative path, making for an easier and more convenient workflow. For example:
- before coping, source layout of the markdown file and its attached images
``` bash
$ tree .
├── README.md
├── assets
│ ├── image-20190708204512742.png
```- after copying, destination layout
``` bash
$ cpmd -s README.md -d hexo-blog/source/_post/ --hexo
$ tree hexo-blog/source/_post/
├── README
│ └── image-20190708204512742.png
├── README.md
```- **Help Info**: for help information, please type ``cpmd -h`` or ``cpmd`` directly
``` bash
$ cpmd
copy/move markdown files supporting wildcard characters to the destination directory **with its/their attached images** on local file paths
Usage(Long Term): cpmd --src <$src.md> --dst <$dstdir> [--move]
Usage(Short Term): cpmd -s <$src.md> -d <$dstdir> [-m]
Multi Copy Example: cpmd -s 'RE*.md' -d backup/$ cpmd -h
Options:
-V, --version output the version number
-s, --src src markdown files (supporting wildcard characters)
-d, --dst dst directory
-m, --move move flag, default value is false
-h, --help output usage information
```----
## Developer Guide
### Quick Start
``` bash
$ git clone [email protected]:downgoon/cpmd.git
$ cd cpmd
$ npm install # download dependencies and save them into 'node_modules'
$ node cpmd.js # debug
$ mkdir backup # create a directory at which markdown files will be placed
$ node cpmd.js -s './test/REMORE.md' -d backup/ --hexo # test hexo-style copy
```### local install
- ``package.json`` introduction
``` json
{
"name": "cpmd",
"version": "0.1.0", // version number, default is 1.0.0
"description": "copy markdown file to the destination directory with its attached images on local file paths",
"main": "cpmd.js", // entry point of the application, default is 'Index.js'
"dependencies": { // auto added on 'npm install $module_name --save' executed
"command-line-args": "^5.1.1",
"commander": "^2.20.0",
"fs-extra": "^8.0.1",
"markdown-parser": "0.0.8"
},
"repository": {
"type": "git",
"url": "git://github.com/downgoon/cpmd.git"
},
"bin": { // cmd line name for 'npm install . -g'
"cpmd": "cpmd.js" // cmd line name -> js reference
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "[email protected]",
"license": "MIT"
}```
> the ``bin`` section is required for local installation in which the command like ``npm install . -g`` will be executed.
- **directive head line**: ``#!/usr/bin/env node``
Add the following directive, which is also required, at the first line of "cpmd.js" file whose content is just like this:
``` javascript
#!/usr/bin/env nodevar fs = require('fs');
var fse = require("fs-extra");
var Parser = require('markdown-parser');
const path = require("path");```
- **locally install**
``` bash
$ sudo npm uninstall . -g # uninstall previous version
$ sudo npm install . -g # install local new version
/usr/local/bin/cpmd -> /usr/local/lib/node_modules/cpmd/cpmd.js
+ [email protected]
updated 1 package in 0.161s
$ which cpmd
/usr/local/bin/cpmd
$ ll /usr/local/bin/ | grep cpmd
cpmd -> ../lib/node_modules/cpmd/cpmd.js
```- **cmd line testing**
``` bash
$ cpmd
Usage: mdcp --src $src.md --dst $dstdir
```### remote install
- **publish firstly**: publish the application to the official site [www.npmjs.com]([https://www.npmjs.com](https://www.npmjs.com/))
``` bash
$ npm login # please signup an account firstly
Username: downgoon
Password: # input your password hear
Email: (this IS public) [email protected]
Logged in as downgoon on https://registry.npmjs.org/.$ npm publish # publish to registry.npmjs.org
npm publish
npm notice
npm notice 📦 [email protected]
npm notice === Tarball Contents ===
npm notice 686B package.json
npm notice 2.0kB cpmd.js
npm notice 2.9kB README.md
npm notice === Tarball Details ===
npm notice name: cpmd
npm notice version: 0.1.0
npm notice package size: 2.1 kB
npm notice unpacked size: 5.6 kB
npm notice shasum: 7cc7dc6378216e3bb4ad6fc15d4a2511f18aecf7
npm notice integrity: sha512-Lki/LCZBB7sp8[...]OCYpIyhyDtB+A==
npm notice total files: 3
npm notice
+ [email protected]$ npm view cpmd # view the published detail info
[email protected] | MIT | deps: 4 | versions: 1
copy markdown file to the destination directory with its attached images on local file paths
https://github.com/downgoon/cpmd#readmebin: cpmd
dist
.tarball: https://registry.npmjs.org/cpmd/-/cpmd-0.1.0.tgz
.shasum: 7cc7dc6378216e3bb4ad6fc15d4a2511f18aecf7
.integrity: sha512-Lki/LCZBB7sp8aOt8wTHtJ8sgMmEt25WgRXM4iQmytNSEbBF0dkL9+aomsvgIrGuCXtkyR2GJOCYpIyhyDtB+A==
.unpackedSize: 5.6 kBdependencies:
command-line-args: ^5.1.1 commander: ^2.20.0 fs-extra: ^8.0.1 markdown-parser: 0.0.8maintainers:
- downgoondist-tags:
latest: 0.1.0published 39 seconds ago by downgoon
```- **remotely install**: download from 'registry.npmjs.org' and install
``` bash
$ npm install cpmd -g
/usr/local/bin/cpmd -> /usr/local/lib/node_modules/cpmd/cpmd.js
+ [email protected]
updated 12 packages in 3.2s```