-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Register unpublish cli command to the console #4995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
awongCM
wants to merge
6
commits into
hexojs:master
Choose a base branch
from
awongCM:unplublish-cli
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0c1c172
added unpublish command along with its unit test
awongCM 34b46ad
register unpublish command to console
awongCM 5480574
Apply suggestions from code review
renbaoshuo 1799ed9
updated as per review
awongCM df29205
Merge branch 'unplublish-cli' of https://github.com/awongCM/hexo into…
awongCM f635055
fixed failing test suite
awongCM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| 'use strict'; | ||
|
|
||
| const tildify = require('tildify'); | ||
| const { magenta } = require('picocolors'); | ||
|
|
||
| function unPublishConsole(args) { | ||
| // Display help message if user didn't input any arguments | ||
| if (!args._.length) { | ||
| return this.call('help', {_: ['unpublish']}); | ||
| } | ||
|
|
||
| return this.post.unpublish({ | ||
| slug: args._.pop(), | ||
| layout: args._.length ? args._[0] : this.config.default_layout | ||
| }, args.r || args.replace).then(post => { | ||
| this.log.info('Unpublished: %s', magenta(tildify(post.path))); | ||
| }); | ||
| } | ||
|
|
||
| module.exports = unPublishConsole; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| 'use strict'; | ||
|
|
||
| const { exists, mkdirs, readFile, rmdir, unlink } = require('hexo-fs'); | ||
| const moment = require('moment'); | ||
| const { join } = require('path'); | ||
| const Promise = require('bluebird'); | ||
| const { useFakeTimers, spy } = require('sinon'); | ||
|
|
||
| describe('unpublish', () => { | ||
| const Hexo = require('../../../lib/hexo'); | ||
| const hexo = new Hexo(join(__dirname, 'unpublish_test'), {silent: true}); | ||
| const unpublish = require('../../../lib/plugins/console/unpublish').bind(hexo); | ||
| const post = hexo.post; | ||
| const now = Date.now(); | ||
| let clock; | ||
|
|
||
| before(async () => { | ||
| clock = useFakeTimers(now); | ||
|
|
||
| await mkdirs(hexo.base_dir); | ||
| await hexo.init(); | ||
| await hexo.scaffold.set('post', [ | ||
| '---', | ||
| 'title: {{ title }}', | ||
| 'date: {{ date }}', | ||
| 'tags:', | ||
| '---' | ||
| ].join('\n')); | ||
| await hexo.scaffold.set('draft', [ | ||
| '---', | ||
| 'title: {{ title }}', | ||
| 'tags:', | ||
| '---' | ||
| ].join('\n')); | ||
| }); | ||
|
|
||
| after(() => { | ||
| clock.restore(); | ||
| return rmdir(hexo.base_dir); | ||
| }); | ||
|
|
||
| beforeEach(() => post.create({ | ||
| title: 'Hello World', | ||
| layout: 'post', | ||
| date: moment(now).format('YYYY-MM-DD HH:mm:ss') | ||
| })); | ||
|
|
||
| it('slug', async () => { | ||
| const postPath = join(hexo.source_dir, '_posts', 'Hello-World.md'); | ||
| const path = join(hexo.source_dir, '_drafts', 'Hello-World.md'); | ||
|
|
||
| const content = [ | ||
| '---', | ||
| 'title: Hello World', | ||
| 'tags:', | ||
| '---' | ||
| ].join('\n') + '\n'; | ||
|
|
||
| await unpublish({ | ||
| _: ['Hello-World'] | ||
| }); | ||
|
|
||
| const exist = await exists(postPath); | ||
| const data = await readFile(path); | ||
|
|
||
| exist.should.be.false; | ||
| data.should.eql(content); | ||
|
|
||
| await unlink(path); | ||
| }); | ||
|
|
||
| it('no args', async () => { | ||
| const hexo = new Hexo(join(__dirname, 'unpublish_test'), {silent: true}); | ||
| hexo.call = spy(); | ||
| const unpublish = require('../../../lib/plugins/console/unpublish').bind(hexo); | ||
|
|
||
| await unpublish({_: []}); | ||
|
|
||
| hexo.call.calledOnce.should.be.true; | ||
| hexo.call.args[0][0].should.eql('help'); | ||
| hexo.call.args[0][1]._[0].should.eql('unpublish'); | ||
| }); | ||
|
|
||
| it('layout', async () => { | ||
| const path = join(hexo.source_dir, '_posts', 'Hello-World.md'); | ||
| const date = moment(now); | ||
|
|
||
| const content = [ | ||
| '---', | ||
| 'title: Hello World', | ||
| 'date: ' + date.format('YYYY-MM-DD HH:mm:ss'), | ||
| 'tags:', | ||
| '---' | ||
| ].join('\n') + '\n'; | ||
|
|
||
| await unpublish({ | ||
| _: ['photo', 'Hello-World'] | ||
| }); | ||
| const data = await readFile(path); | ||
| data.should.eql(content); | ||
|
|
||
| await unlink(path); | ||
| }); | ||
|
|
||
| it('rename if target existed', async () => { | ||
| const path = join(hexo.source_dir, '_posts', 'Hello-World.md'); | ||
|
|
||
| await post.create({ | ||
| title: 'Hello World' | ||
| }); | ||
| await unpublish({ | ||
| _: ['Hello-World'] | ||
| }); | ||
|
|
||
| const exist = await exists(path); | ||
| exist.should.be.true; | ||
|
|
||
| await Promise.all([ | ||
| unlink(path), | ||
| unlink(join(hexo.source_dir, '_posts', 'Hello-World.md')) | ||
| ]); | ||
| }); | ||
|
|
||
| it('replace existing target', async () => { | ||
| const path = join(hexo.source_dir, '_posts', 'Hello-World.md'); | ||
|
|
||
| await post.create({ | ||
| title: 'Hello World' | ||
| }); | ||
| await unpublish({ | ||
| _: ['Hello-World'], | ||
| replace: true | ||
| }); | ||
| const exist = await exists(join(hexo.source_dir, '_drafts', 'Hello-World-1.md')); | ||
| exist.should.be.false; | ||
|
|
||
| await unlink(path); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.