-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Add support for metalsmith builder hooks #428
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
Changes from all commits
8932af1
f39241a
e5a1c78
0125ac7
7605ff2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = { | ||
"metalsmith": { | ||
before: function (metalsmith, opts, helpers) { | ||
metalsmith.metadata().before = "Before"; | ||
}, | ||
after: function (metalsmith, opts, helpers) { | ||
metalsmith.metadata().after = "After"; | ||
function customMetalsmithPlugin (files, metalsmith, done) { | ||
// Implement something really custom here. | ||
|
||
var readme = files['readme.md'] | ||
delete files['readme.md'] | ||
files['custom-before-after/readme.md'] = readme | ||
|
||
done(null, files) | ||
} | ||
|
||
metalsmith.use(customMetalsmithPlugin) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Metalsmith {{after}} and {{before}} hooks |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = { | ||
"metalsmith": function (metalsmith, opts, helpers) { | ||
metalsmith.metadata().custom = "Custom"; | ||
function customMetalsmithPlugin (files, metalsmith, done) { | ||
// Implement something really custom here. | ||
|
||
var readme = files['readme.md'] | ||
delete files['readme.md'] | ||
files['custom/readme.md'] = readme | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to be sure. What you're doing here in custom metalsmith plugin is you're moving file from root template directory into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that's it. |
||
|
||
done(null, files) | ||
} | ||
|
||
metalsmith.use(customMetalsmithPlugin) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Metalsmith {{custom}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ const metadata = require('../../lib/options') | |
const { isLocalPath, getTemplatePath } = require('../../lib/local-path') | ||
|
||
const MOCK_META_JSON_PATH = path.resolve('./test/e2e/mock-meta-json') | ||
const MOCK_METALSMITH_CUSTOM_PATH = path.resolve('./test/e2e/mock-metalsmith-custom') | ||
const MOCK_METALSMITH_CUSTOM_BEFORE_AFTER_PATH = path.resolve('./test/e2e/mock-metalsmith-custom-before-after') | ||
const MOCK_TEMPLATE_REPO_PATH = path.resolve('./test/e2e/mock-template-repo') | ||
const MOCK_TEMPLATE_BUILD_PATH = path.resolve('./test/e2e/mock-template-build') | ||
const MOCK_METADATA_REPO_JS_PATH = path.resolve('./test/e2e/mock-metadata-repo-js') | ||
|
@@ -120,6 +122,46 @@ describe('vue-cli', () => { | |
}) | ||
}) | ||
|
||
it('supports custom metalsmith plugins', done => { | ||
generate('test', MOCK_METALSMITH_CUSTOM_PATH, MOCK_TEMPLATE_BUILD_PATH, err => { | ||
if (err) done(err) | ||
|
||
expect(exists(`${MOCK_TEMPLATE_BUILD_PATH}/custom/readme.md`)).to.equal(true) | ||
|
||
async.eachSeries([ | ||
'readme.md' | ||
], function (file, next) { | ||
const template = fs.readFileSync(`${MOCK_METALSMITH_CUSTOM_PATH}/template/${file}`, 'utf8') | ||
const generated = fs.readFileSync(`${MOCK_TEMPLATE_BUILD_PATH}/custom/${file}`, 'utf8') | ||
render(template, {custom: 'Custom'}, (err, res) => { | ||
if (err) return next(err) | ||
expect(res).to.equal(generated) | ||
next() | ||
}) | ||
}, done) | ||
}) | ||
}) | ||
|
||
it('supports custom metalsmith plugins with after/before object keys', done => { | ||
generate('test', MOCK_METALSMITH_CUSTOM_BEFORE_AFTER_PATH, MOCK_TEMPLATE_BUILD_PATH, err => { | ||
if (err) done(err) | ||
|
||
expect(exists(`${MOCK_TEMPLATE_BUILD_PATH}/custom-before-after/readme.md`)).to.equal(true) | ||
|
||
async.eachSeries([ | ||
'readme.md' | ||
], function (file, next) { | ||
const template = fs.readFileSync(`${MOCK_METALSMITH_CUSTOM_BEFORE_AFTER_PATH}/template/${file}`, 'utf8') | ||
const generated = fs.readFileSync(`${MOCK_TEMPLATE_BUILD_PATH}/custom-before-after/${file}`, 'utf8') | ||
render(template, {before: 'Before', after: 'After'}, (err, res) => { | ||
if (err) return next(err) | ||
expect(res).to.equal(generated) | ||
next() | ||
}) | ||
}, done) | ||
}) | ||
}) | ||
|
||
it('generate a vaild package.json with escaped author', done => { | ||
monkeyPatchInquirer(escapedAnswers) | ||
generate('test', MOCK_TEMPLATE_REPO_PATH, MOCK_TEMPLATE_BUILD_PATH, err => { | ||
|
@@ -254,7 +296,7 @@ describe('vue-cli', () => { | |
expect(getTemplatePath('../template')).to.equal(path.join(__dirname, '/../../../template')) | ||
}) | ||
|
||
it.only('points out the file in the error', done => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
it('points out the file in the error', done => { | ||
monkeyPatchInquirer(answers) | ||
generate('test', MOCK_ERROR, MOCK_TEMPLATE_BUILD_PATH, err => { | ||
expect(err.message).to.match(/^\[readme\.md\] Parse error/) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides this one you can also test
before
andafter
, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just push a new commit with an additional test, and better assertions