Skip to content

Commit 601af02

Browse files
Adding ComponentFixture option
1 parent b19864a commit 601af02

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

generator/updateTemplateWithCompnentFixture.js renamed to generator/componentFixtureHelper.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
const templateUpdater = (m) => `<component-fixture>
22
3-
${m}
3+
${m}
44
5-
<Editor slot="control" slot-scope="scope" v-bind="scope"/>
6-
7-
</component-fixture>`;
8-
9-
const componentTemplateRegex = /<HelloWorld (.)*\/>/g;
5+
<Editor slot="control" slot-scope="scope" v-bind="scope"/>
106
7+
</component-fixture>`;
118

129
const script = '<script>';
1310
const scriptUpdater = `<script>
@@ -18,11 +15,12 @@ const exportUpdater = ` components: {
1815
ComponentFixture,
1916
Editor,`;
2017

21-
function updateExample(content) {
22-
const updatedTemplate = content.replace(componentTemplateRegex, templateUpdater);
18+
function updateExample(content, componentName) {
19+
const componentTemplateRegex = new RegExp(`<${componentName} (.)*\/>`, 'g');
20+
const newValue = templateUpdater(`<${componentName} \/>`);
21+
const updatedTemplate = content.replace(componentTemplateRegex, newValue);
2322
const updatedScript = updatedTemplate.replace(script, scriptUpdater);
24-
const updatedExport = updatedScript.replace(exportComponents, exportUpdater);
25-
return updatedExport;
23+
return updatedScript.replace(exportComponents, exportUpdater);
2624
}
2725

2826
module.exports = {

generator/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { renameFiles, updateFile } = require('./fileHelper')
2-
const { updateExample } = ('./updateTemplateWithCompnentFixture')
2+
const { updateExample } = require('./componentFixtureHelper')
33
const readmeUpdater = require('./readmeUpdater');
44
const licenseList = require('spdx-license-list/full');
55

@@ -98,7 +98,7 @@ module.exports = (api, { addBadges, addLicense, componentName, copyrightHolders,
9898
updateFile(files, 'README.md', content => readmeUpdater(content, context));
9999

100100
if (useComponentFixture) {
101-
updateFile(files, 'src/App.vue', updateExample);
101+
updateFile(files, 'src/App.vue', content => updateExample(content, componentName));
102102
}
103103

104104
const immutableFiles = ['src/components/HelloWorld.vue', 'src/index.js']

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-cli-plugin-component",
3-
"version": "1.7.1",
3+
"version": "1.8.5",
44
"description": "vue-cli 3 plugin to create shareable component",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)