Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [{
"configurations": [

{
"name": "Attach to Process",
"type": "node",
"request": "attach",
"port": 9229,
"protocol": "inspector",
"restart": true
"restart": true,
"outFiles": ["${workspaceRoot}/lib"],
"sourceMaps": true
},
{
"type": "node",
Expand Down
4 changes: 2 additions & 2 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var exampleMixin = {
};

const options = {
rootPath: path.join(__dirname, '/vueFiles'),
rootPath: path.join(__dirname, ''),
vue: {
head: {
meta: [{
Expand Down Expand Up @@ -66,7 +66,7 @@ app.get('/', (req, res) => {
]
}
}
res.renderVue('main/main.vue', data, vueOptions)
res.renderVue('main.vue', data, vueOptions)
});

app.listen(3000);
Expand Down
4 changes: 2 additions & 2 deletions example/components/uuid.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<template>
<div>
<inner></inner>
<h2>Uuid: {{uuid ? uuid : 'no uuid'}}</h2>
<h2 class="test">Uuid: {{uuid ? uuid : 'no uuid'}}</h2>
</div>
</template>

<script>
import inner from '../components/inner.vue';
import inner from './components/inner.vue';
export default {
props: ['uuid'],
data: function () {
Expand Down
6 changes: 3 additions & 3 deletions example/components/uuid2.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<h3>Uuid2: {{uuid2 ? uuid2 : 'no uuid'}}</h3>
<h3 class="red">Uuid2: {{uuid2 ? uuid2 : 'no uuid'}}</h3>
</div>
</template>

Expand All @@ -14,7 +14,7 @@ export default {
</script>

<style lang="css">
.test {
color: blue;
.red {
color: yellowgreen;
}
</style>
File renamed without changes.
20 changes: 0 additions & 20 deletions example/vueFiles/components/uuid.vue

This file was deleted.

20 changes: 0 additions & 20 deletions example/vueFiles/components/uuid2.vue

This file was deleted.

37 changes: 0 additions & 37 deletions example/vueFiles/main/main.vue

This file was deleted.

10 changes: 0 additions & 10 deletions example/vueFiles/mixins/exampleMixin.js

This file was deleted.

9 changes: 8 additions & 1 deletion src/parser/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const fs = require('fs');
const camelCase = require('camel-case');
const compiler = require('vue-template-compiler');
const CleanCSS = require('clean-css');
const styleParser = require('./style');
const htmlParser = require('./html');
const scriptParser = require('./script');
Expand All @@ -16,6 +17,7 @@ function componentParser(templatePath: string, defaults: Object, type: string, C
scriptParser(cachedComponentContentObject.parsedContent.script, defaults, type, Cache).then(parsedScriptObject => {
cachedComponentContentObject.script = parsedScriptObject;
cachedComponentContentObject.script.template = cachedComponentContentObject.template;
cachedComponentContentObject.styles = parsedScriptObject.styles;
resolve(cachedComponentContentObject);
}).catch(error => {
reject(error);
Expand Down Expand Up @@ -64,7 +66,12 @@ function parseContent(content: string, templatePath: string, defaults: Object, t
Promise.all(promiseArray).then(resultsArray => {
const template = resultsArray[0];
const script = resultsArray[1];
const style = resultsArray[2];
let style = '';
if (resultsArray[2]) {
style = resultsArray[2];
} else {
style = new CleanCSS({}).minify(resultsArray[1].styles ? resultsArray[1].styles : '').styles;
}

script.template = template;

Expand Down
9 changes: 4 additions & 5 deletions src/parser/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ type StyleObjectType = {

function styleParser(styleObjectArray: StyleObjectType[]): Promise<string> {
return new Promise((resolve) => {
if (!styleObjectArray || styleObjectArray.length === 0) {
resolve('');
} else {
let output = '';
if (styleObjectArray && styleObjectArray.length > 0) {
for (const styleObject of styleObjectArray) {
if(styleObject.lang === 'scss' || styleObject.lang === 'less') {
console.error('Sorry please only use plain CSS in your files for now');
}
const output = new CleanCSS({}).minify(styleObject.content);
resolve(output.styles);
output += new CleanCSS({}).minify(styleObject.content).styles;
}
}
resolve(output);
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/utils/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,19 @@ function requireFromString(code: string, filename: string = '', optsObj: Object
}
Promise.all(promiseArray)
.then(renderedItemArray => {
let styles = '';
for (var renderedItem of renderedItemArray) {
const rawString = renderedItem.rendered.scriptStringRaw;
code = code.replace(renderedItem.match, rawString);
if (renderedItem.rendered.layout && renderedItem.rendered.layout.style) {
styles += renderedItem.rendered.layout.style;
}
}
//check if its the last element and then render
const last_element = code.match(options.vueFileRegex);
if (last_element === undefined || last_element === null) {
m._compile(code, filename);
m.exports.default.styles = styles;
resolve(m.exports.default);
}
})
Expand Down
6 changes: 3 additions & 3 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Models = require('../src/models');
const path = require('path');

const options = {
rootPath: path.join(__dirname, '../example/vueFiles')
rootPath: path.join(__dirname, '../example')
};

const data = {
Expand All @@ -20,8 +20,8 @@ const vueOptions = {
}
}

const exampleHead = `<head>\n<title>Page Title</title>\n</head>`;
const exampleScript = `<script>(function(){"use strict";var u=function(){return new Vue({mixins:[{methods:{hello:function(){console.log('Hello')}}}],data:function(){return{"title":"Express Vue","message":"Hello world","uuid":"farts"}},methods:{test:function(){console.error('test')}},components:{uuid:{props:["uuid"],data:function(){return{}},template:"<div><h2>Uuid: {{uuid ? uuid : 'no uuid'}}</h2></div>"},uuid2:{props:["uuid2"],data:function(){return{}},template:"<div><h3>Uuid2: {{uuid2 ? uuid2 : 'no uuid'}}</h3></div>"}},template:"<div><h1>{{title}}</h1><p>Welcome to the {{title}} demo. Click a link:</p><input v-model=\\"message\\" placeholder=\\"edit me\\"><p>{{message}}</p><uuid :uuid=\\"uuid\\"></uuid><uuid2 :uuid2=\\"uuid2\\"></uuid2><button type=\\"button\\" name=\\"button\\" v-on:click=\\"this.hello\\">Test mixin</button> <button type=\\"button\\" name=\\"button\\" v-on:click=\\"this.test\\">Test method</button></div>"})};typeof module!=='undefined'&&module.exports?(module.exports=u):(this.app=u())}).call(this),app.$mount('#app')</script>`
const exampleHead = `<head>\n<title>Page Title</title>\n<style>.test{color:#00f}.red{color:#9acd32}</style></head>`;
const exampleScript = `<script>(function(){"use strict";var u=function(){return new Vue({mixins:[{methods:{hello:function(){console.log(\'Hello\')}}}],data:function(){return{"title":"Express Vue","message":"Hello world","uuid":"farts"}},methods:{test:function(){console.error(\'test\')}},components:{uuid:{props:["uuid"],data:function(){return{}},components:{inner:{data:function(){return{}},template:"<div><p>Inner Text</p></div>"}},styles:"",template:"<div><inner></inner><h2 class=\\"test\\">Uuid: {{uuid ? uuid : \'no uuid\'}}</h2></div>"},uuid2:{props:["uuid2"],data:function(){return{}},template:"<div><h3 class=\\"red\\">Uuid2: {{uuid2 ? uuid2 : \'no uuid\'}}</h3></div>"}},styles:".test{color:#00f}.red{color:#9acd32}",template:"<div><h1>{{title}}</h1><p>Welcome to the {{title}} demo. Click a link:</p><input v-model=\\"message\\" placeholder=\\"edit me\\"><p>{{message}}</p><uuid :uuid=\\"uuid\\"></uuid><uuid2 :uuid2=\\"uuid2\\"></uuid2><button type=\\"button\\" name=\\"button\\" v-on:click=\\"this.hello\\">Test mixin</button> <button type=\\"button\\" name=\\"button\\" v-on:click=\\"this.test\\">Test method</button></div>"})};typeof module!==\'undefined\'&&module.exports?(module.exports=u):(this.app=u())}).call(this),app.$mount(\'#app\')</script>`;

test('renders App object', t => {
const renderer = new ExpressVueRenderer(options);
Expand Down
4 changes: 2 additions & 2 deletions tests/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ var cacheOptions = {
var lruCache = LRU(cacheOptions);

let types = new Types();
const component = __dirname + '/../../example/vueFiles/components/uuid.vue';
const component = __dirname + '/../../example/components/uuid.vue';
const options = {
rootPath: path.join(__dirname, 'tests'),
rootPath: path.join(__dirname, '../../example'),
component: 'uuid.vue'
};

Expand Down
4 changes: 2 additions & 2 deletions tests/utils/checkPathUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '../../src/utils';
import Models from '../../src/models';

const rootPath = path.join(__dirname, '../../example/vueFiles/');
const rootPath = path.join(__dirname, '../../example/');
const defaults = new Models.Defaults();
var LRU = require('lru-cache');
var cacheOptions = {
Expand All @@ -15,7 +15,7 @@ var cacheOptions = {
var lruCache = LRU(cacheOptions);

test('correctPath Path', t => {
const filePath = path.join(rootPath, '../../example/vueFiles/components/uuid.vue');
const filePath = path.join(rootPath, '../example/components/uuid.vue');
const correctPath = rootPath + 'components/uuid.vue';

return PathUtils.getCorrectPathForFile(filePath, 'view', defaults, lruCache)
Expand Down