Skip to content

Commit 76bba13

Browse files
committed
Updated reading of files
1 parent 82f65bf commit 76bba13

File tree

9 files changed

+620
-1060
lines changed

9 files changed

+620
-1060
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Run Vue Single File Components from the CLI
33

44
[![npm](https://img.shields.io/npm/v/vue-run.svg) ![npm](https://img.shields.io/npm/dm/vue-run.svg)](https://www.npmjs.com/package/vue-run)
5+
![Vue 2](https://img.shields.io/badge/vue-2.x-brightgreen.svg)
56

67
> Currently a WIP, star us and key an eye out
78

bin/vue-sfc-runner.js

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
11
#!/usr/bin/env node
22
console.log('Running a Vue File')
3-
4-
/**
5-
* Steps
6-
* 1. Run vsr on the CLI
7-
* 2. Shown a list of Vue files in the current directory
8-
* 3. Ask for props data
9-
* 4. Run the file in the browser
10-
*/
11-
12-
const fs = require('fs')
13-
const path = require('path')
14-
const inquirer = require('inquirer')
15-
16-
async function run() {
17-
const availableFiles = fs.readdirSync(process.cwd()).filter(file => path.extname(file) === ".vue")
18-
19-
const questions = await inquirer.prompt([
20-
{
21-
name: 'files',
22-
message: 'Please select a Vue Component',
23-
type: 'list',
24-
choices: availableFiles
25-
}
26-
])
27-
}
28-
29-
run()
3+
require('../src')()

package-lock.json

Lines changed: 512 additions & 1031 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@
4040
"vuepress": "^0.10.2"
4141
},
4242
"dependencies": {
43-
"inquirer": "^6.0.0"
43+
"babel-loader": "^7.1.5",
44+
"css-loader": "^1.0.0",
45+
"html-webpack-plugin": "^3.2.0",
46+
"inquirer": "^6.0.0",
47+
"less-loader": "^4.1.0",
48+
"sass-loader": "^7.0.3",
49+
"vue-loader": "^15.2.4",
50+
"vue-style-loader": "^4.1.0",
51+
"webpack": "^4.15.1",
52+
"webpack-serve": "^1.0.4"
4453
}
4554
}

src/cli/index.js

Whitespace-only changes.

src/engine/webpack.config.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const webpack = require('webpack')
2+
const HtmlWebpackPlugin = require('html-webpack-plugin')
3+
const path = require('path')
4+
5+
function entry (componentName, fileImport) {
6+
return `
7+
document.querySelector('body').innerHTML = '<div id="app"><${componentName} /></div>'
8+
9+
import Test from '${fileImport}'
10+
import Vue from 'vue/dist/vue.js'
11+
`
12+
}
13+
14+
module.exports = opts => {
15+
16+
const config = {
17+
devtool: 'eval-source-map',
18+
devServer: {
19+
contentBase: opts.cwd,
20+
compress: true,
21+
open: true,
22+
port: 9000,
23+
disableHostCheck: true
24+
},
25+
entry: () => entry(opts.componentName, opts.entry), // './test/demo/entry.js',
26+
27+
module: {
28+
rules: [
29+
{
30+
test: /\.vue$/,
31+
loader: 'vue-loader',
32+
options: {
33+
loaders: {
34+
js: {
35+
loader: 'babel-loader'
36+
},
37+
scss: 'vue-style-loader!css-loader!sass-loader',
38+
sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax',
39+
less: 'vue-style-loader!css-loader!less-loader'
40+
}
41+
}
42+
},
43+
{
44+
test: /\.js$/,
45+
exclude: /node_modules/,
46+
use: {
47+
loader: 'babel-loader'
48+
}
49+
}
50+
]
51+
},
52+
53+
plugins: [
54+
new HtmlWebpackPlugin()
55+
]
56+
}
57+
58+
return config
59+
}

src/index.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,37 @@
1-
console.log('Run Vue')
1+
const fs = require('fs')
2+
const path = require('path')
3+
const inquirer = require('inquirer')
4+
5+
const serve = require('webpack-serve')
6+
const configSFC = require('./engine/webpack.config.js')
7+
8+
/**
9+
* Steps
10+
* 1. Run vsr on the CLI
11+
* 2. Shown a list of Vue files in the current directory
12+
* 3. Ask for props data
13+
* 4. Ask for container priming e.g. align, width
14+
* 5. Run the file in the browser
15+
*/
16+
17+
async function run() {
18+
const availableFiles = fs.readdirSync(process.cwd()).filter(file => path.extname(file) === ".vue")
19+
20+
const questions = await inquirer.prompt([
21+
{
22+
name: 'file',
23+
message: 'Please select a Vue Component',
24+
type: 'list',
25+
choices: availableFiles
26+
}
27+
])
28+
29+
const config = configSFC({
30+
cwd: process.cwd(),
31+
componentName: questions.file.replace(/([a-z](?=[A-Z]))/g, '$1-').split('.')[0].toLowerCase(),
32+
entry: `${process.cwd()}/${questions.file}`
33+
})
34+
serve({ config })
35+
}
36+
37+
module.exports = run
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)