Skip to content

Commit dd3d2a5

Browse files
committed
Add template
1 parent b792710 commit dd3d2a5

24 files changed

+1010
-0
lines changed

LICENSE

+674
Large diffs are not rendered by default.

meta.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module.exports = {
2+
"prompts": {
3+
"name": {
4+
"type": "string",
5+
"required": true,
6+
"message": "Project name"
7+
},
8+
"description": {
9+
"type": "string",
10+
"required": false,
11+
"message": "Project description",
12+
"default": "A Vue.js web extension"
13+
},
14+
"author": {
15+
"type": "string",
16+
"message": "Author"
17+
},
18+
"router": {
19+
"type": "confirm",
20+
"message": "Install vue-router?"
21+
},
22+
"store": {
23+
"type": "confirm",
24+
"message": "Install vuex?"
25+
},
26+
"axios": {
27+
"type": "confirm",
28+
"message": "Install axios?"
29+
}
30+
},
31+
"filters": {
32+
"src/store/**/*": "store",
33+
"src/popup/router/**/*": "router"
34+
},
35+
"completeMessage": "To get started:\n\n {{^inPlace}}cd {{destDirName}}\n {{/inPlace}}npm install\n npm run build"
36+
};

template/.babelrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"presets": [
3+
["latest", {
4+
"es2015": { "modules": "commonjs"}
5+
}]
6+
]
7+
}

template/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/node_modules
2+
/*.log
3+
/dist
4+
/zip-builds

template/package.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "{{ name }}",
3+
"version": "1.0.0",
4+
"description": "{{ description }}",
5+
"author": "{{ author }}",
6+
"scripts": {
7+
"build": "webpack --config webpack.config.js --progress --hide-modules",
8+
"watch": "npm run build -- --watch"
9+
},
10+
"dependencies": {
11+
"vue": "^2.4.1"{{#if axios or router or store}},{{/if}}
12+
{{#axios}}"axios": "^0.16.2",{{/axios}}
13+
{{#router}}"vue-router": "^2.7.0",{{/router}}
14+
{{#store}}"vuex": "^2.3.1",{{/store}}
15+
},
16+
"devDependencies": {
17+
"babel-core": "^6.25.0",
18+
"babel-loader": "^7.1.1",
19+
"babel-preset-latest": "^6.24.1",
20+
"copy-webpack-plugin": "^4.0.1",
21+
"css-loader": "^0.28.4",
22+
"extract-text-webpack-plugin": "^3.0.0",
23+
"file-loader": "^0.11.2",
24+
"node-sass": "^4.5.3",
25+
"sass-loader": "^6.0.6",
26+
"vue-loader": "^12.2.2",
27+
"vue-template-compiler": "^2.4.1",
28+
"webpack": "^3.3.0",
29+
"webpack-shell-plugin": "^0.5.0"
30+
}
31+
}

template/scripts/build-zip.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
5+
import os
6+
import json
7+
import shutil
8+
9+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
10+
EXTENSION_DIR = os.path.join(BASE_DIR, '../src')
11+
DIST_DIR = os.path.join(BASE_DIR, '../zip-builds')
12+
13+
14+
def extract_extension_data():
15+
with open(EXTENSION_DIR + '/manifest.json') as content:
16+
content_json = json.load(content)
17+
name = content_json.get('name')
18+
extension_version = content_json.get('version')
19+
20+
return [name, extension_version]
21+
22+
23+
def main():
24+
[name, version] = extract_extension_data()
25+
zip_name = '{}/{}-v{}'.format(DIST_DIR, name, version)
26+
27+
print('Building {}.zip'.format(zip_name))
28+
shutil.make_archive(zip_name, 'zip', EXTENSION_DIR)
29+
print('Ok')
30+
31+
32+
if __name__ == '__main__':
33+
main()

template/scripts/remove-evals.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
echo Running $0
6+
7+
BUNDLES_PATH=dist
8+
BUNDLES=("background.js" "popup/popup.js")
9+
10+
for BUNDLE in ${BUNDLES[@]};
11+
do
12+
FILE=${BUNDLES_PATH}/${BUNDLE}
13+
14+
echo "Removing eval()'s from ${FILE}..."
15+
16+
sed -e '/This works if eval is allowed (see CSP)/,+1d' ${FILE} > ${FILE}.tmp
17+
mv ${FILE}.tmp ${FILE}
18+
sed -e '/This works if the window reference is available/,+2d' ${FILE} > ${FILE}.tmp
19+
mv ${FILE}.tmp ${FILE}
20+
done

template/src/background.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{#if store}}import store from './store';{{/if}}
2+
3+
alert(`Hello ${store.getters.foo}!`);

template/src/icons/icon.xcf

43.1 KB
Binary file not shown.

template/src/icons/icon_128.png

9.81 KB
Loading

template/src/icons/icon_48.png

2.52 KB
Loading

template/src/manifest.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "{{ name }}",
3+
"description": "{{ description }}",
4+
"version": "1.0.0",
5+
"manifest_version": 2,
6+
"icons": {
7+
"48": "icons/icon_48.png",
8+
"128": "icons/icon_128.png"
9+
},
10+
"browser_action": {
11+
"default_title": "{{ name }}",
12+
"default_popup": "popup/popup.html"
13+
},
14+
"background": {
15+
"scripts": [
16+
"background.js"
17+
]
18+
}
19+
}

template/src/popup/App.vue

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<template>
2+
<div>
3+
{{#if router}}
4+
<router-view></router-view>
5+
{{else}}
6+
<p>Hello world!</p>
7+
{{/if}}
8+
</div>
9+
</template>
10+
11+
<script>
12+
export default {
13+
data () {
14+
return {}
15+
}
16+
}
17+
</script>
18+
19+
<style lang="scss" scoped>
20+
{{#unless router}}
21+
p {
22+
font-size: 20px;
23+
}
24+
{{/unless}}
25+
</style>

template/src/popup/popup.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Title</title>
6+
</head>
7+
<body>
8+
<div id="app">
9+
10+
</div>
11+
<script src="popup.js"></script>
12+
</body>
13+
</html>

template/src/popup/popup.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Vue from 'vue';
2+
import App from './App.vue';
3+
{{#if store}}import store from './../store';{{/if}}
4+
{{#if router}}import router from './router';{{/if}}
5+
6+
new Vue({
7+
el: '#app',
8+
{{#if store}}store,{{/if}}
9+
{{#if router}}router,{{/if}}
10+
render: h => h(App)
11+
});

template/src/popup/router/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import VueRouter from 'vue-router';
2+
import routes from './routes';
3+
4+
export default new VueRouter({
5+
routes
6+
});
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<template>
2+
<p>Hello world!</p>
3+
</template>
4+
5+
<script>
6+
export default {
7+
data () {
8+
return {}
9+
}
10+
}
11+
</script>
12+
13+
<style lang="scss" scoped>
14+
p {
15+
font-size: 20px;
16+
}
17+
</style>

template/src/popup/router/routes.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default [
2+
{
3+
path: '/',
4+
component: require('./pages/Index.vue')
5+
},
6+
];

template/src/store/actions.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as types from './mutation-types'
2+
3+
export const setFoo = ({commit, state}, payload) => {
4+
commit(types.UPDATE_FOO, payload);
5+
};

template/src/store/getters.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = (state) => state.foo;

template/src/store/index.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Vue from 'vue'
2+
import Vuex from 'vuex'
3+
4+
import * as getters from './getters'
5+
import * as mutations from './mutations'
6+
import * as actions from './actions'
7+
8+
Vue.use(Vuex);
9+
10+
export default new Vuex.Store({
11+
state: {
12+
foo: 'bar'
13+
},
14+
getters,
15+
mutations,
16+
actions,
17+
})

template/src/store/mutation-types.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const UPDATE_FOO = 'UPDATE_FOO';

template/src/store/mutations.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as types from './mutation-types';
2+
3+
export default {
4+
[types.UPDATE_FOO] (state, payload) {
5+
state.foo = payload;
6+
}
7+
}

template/webpack.config.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const webpack = require('webpack');
2+
const ExtractTextPlugin = require("extract-text-webpack-plugin");
3+
const WebpackShellPlugin = require('webpack-shell-plugin');
4+
const CopyWebpackPlugin = require('copy-webpack-plugin');
5+
6+
const config = {
7+
context: __dirname + '/src',
8+
entry: {
9+
'background': './background.js',
10+
'popup/popup': './popup/popup.js'
11+
},
12+
output: {
13+
path: __dirname + '/dist',
14+
filename: '[name].js'
15+
},
16+
resolve: {
17+
extensions: ['.js', '.vue'],
18+
},
19+
// other options...
20+
module: {
21+
loaders: [
22+
{
23+
test: /\.vue$/,
24+
loaders: 'vue-loader',
25+
options: {
26+
loaders: {
27+
scss: ExtractTextPlugin.extract({
28+
use: 'css-loader!sass-loader',
29+
fallback: 'vue-style-loader'
30+
}),
31+
sass: ExtractTextPlugin.extract({
32+
use: 'css-loader!sass-loader?indentedSyntax',
33+
fallback: 'vue-style-loader'
34+
}),
35+
}
36+
}
37+
},
38+
{
39+
test: /\.js$/,
40+
loader: 'babel-loader',
41+
exclude: /node_modules/
42+
},
43+
{
44+
test: /\.css$/,
45+
use: ExtractTextPlugin.extract({
46+
use: "css-loader",
47+
fallback: "vue-loader",
48+
})
49+
},
50+
{
51+
test: /\.(png|jpg|gif|svg|ico)$/,
52+
loader: 'file-loader',
53+
options: {
54+
name: '[name].[ext]?emitFile=false'
55+
}
56+
}
57+
],
58+
},
59+
plugins: [
60+
new ExtractTextPlugin({
61+
filename: '[name].css'
62+
}),
63+
new CopyWebpackPlugin([
64+
{from: 'icons', to: 'icons'},
65+
{from: 'popup/popup.html', to: 'popup/popup.html'},
66+
{from: 'manifest.json', to: 'manifest.json'}
67+
]),
68+
new WebpackShellPlugin({
69+
onBuildEnd: ['bash scripts/remove-evals.sh']
70+
}),
71+
]
72+
};
73+
74+
module.exports = config;

0 commit comments

Comments
 (0)