Skip to content
This repository has been archived by the owner on Sep 23, 2021. It is now read-only.

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbedard committed Feb 8, 2017
2 parents c18669e + 2d28c89 commit 9e2c661
Show file tree
Hide file tree
Showing 72 changed files with 906 additions and 896 deletions.
16 changes: 16 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"presets": [
["es2015", { "modules": false }],
"stage-2",
],
"plugins": [
"transform-runtime",
"transform-vue-jsx",
],
"comments": false,
"env": {
"test": {
"plugins": ["istanbul"],
},
},
}
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
File renamed without changes.
21 changes: 21 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// http://eslint.org/docs/user-guide/configuring
module.exports = {
env: {
browser: true,
},
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module',
},
plugins: [
'html', // required to lint *.vue files
],
root: true,
rules: {
'comma-dangle': ['error', 'always'],
'indent': ['error', 4],
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, // allow debugger in development
'quotes': ['error', 'single'],
'semi': ['error', 'always'],
},
};
6 changes: 3 additions & 3 deletions template/.gitignore → .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DS_Store
node_modules/
dist/
/assets
/node_modules
/pages
npm-debug.log
selenium-debug.log
test/unit/coverage
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2016-2017 Scott Bedard

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
70 changes: 29 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,56 @@
<p align="center">
<a href="//github.com/vuejs/vue" target="_blank"><img src="http://vuejs.org/images/logo.png" width="auto" height="105px"><a href="//github.com/octobercms/october" target="_blank"><img src="https://raw.githubusercontent.com/octobercms/october/master/themes/demo/assets/images/october.png" alt="October" width="auto" height="100px" /></a></a>
</p>

# oc-vuetober-theme

This project is an opinionated approach to single page applications within the wonderful worlds of [Vue.js](https://vuejs.org), [October CMS](https://octobercms.com), and [Laravel](https://laravel.com). To see what's included out of the box, check out the [live demo](http://vuetober.scottbedard.net).

<a name="getting-started"></a>
### Getting started

Before getting started, make sure you have both [NPM](https://www.npmjs.com) and [vue-cli](https://github.com/vuejs/vue-cli) installed. Once that is taken care of, run the following command from your `/themes` directory.
In order to use this theme, you'll need to have a fair understanding of [Vue.js](https://vuejs.org). If you've never used this framework before, you can get the fundamentals down through [this free screencast series](http://vuecasts.com/).

```bash
$ vue init scottbedard/oc-vuetober-theme myawesometheme
$ cd myawesometheme
$ npm install
```
To install a Vuetober theme, run the following commands from your `/themes` directory.

To build your site for production, run the following command.
> **Note:** As of version 2.1, pulling in `vue-cli` is no longer neccessary.
```bash
$ npm run build
```
# clone down the repository and cd into it
$ git clone https://github.com/scottbedard/oc-vuetober-theme.git mytheme
$ cd mytheme

The development server can be fired up at `localhost:3000` by running the following.
# install dependencies
$ npm install

```bash
$ npm run dev
# run setup command
$ npm run setup
```

For a better development experience, make sure to install the [Vue devtools](https://github.com/vuejs/vue-devtools) Chrome extension.
Other available commands

<a name="routing"></a>
### Routing
```bash
# compile production assets
$ npm run build

Routes can be registered from the `app/routes.js` file. Simply import your component, and assign it to a route.
# start development server
$ npm run dev

The layout components exist to provide an easy way of creating multiple site structures. To use a given layout for your page, make sure to register its route as a child route of the layout component.
# run unit tests
$ npm test
```

When displaying dynamic content that may contain local links, it is recommended that you attach the `v-linkable` directive to the container. This will hijack click events and keep your user within the SPA. Without doing this, a full page reload will occur.
<a name="features"></a>
### Features

```html
<div v-html="blogPost" v-linkable></div>
```
**Single file components**

<a name="unit-testing"></a>
### Unit testing and continuous integration
Vue is a fantastic framework, and when using `.vue` files we have a great foundation for creating small, composable components. With this setup, we're able to write our code using any pre-processors we like, and take advantage of things like [hot reloading](https://vue-loader.vuejs.org/en/features/hot-reload.html) and [scoped css](https://vue-loader.vuejs.org/en/features/scoped-css.html).

This theme comes ready to go with unit testing and code coverage reporting. To run the test suite, execute the following command.
**State of the art tooling**

```bash
$ npm test
```
This theme takes full advantage of [Webpack 2](https://webpack.js.org). The build script will optimize your application with techniques like automatically inlining small images, tree shaking, and more. In addition to this, [ESLint](http://eslint.org/docs/rules) will automatically fix your javascript to ensure a consistent style throughout your codebase.

Most continuous integration services like [Travic CI](https://travis-ci.org) and [Circle CI](https://circleci.com) should be able to infer the test command. Also, this theme works seamlessly with coverage reporting such as [Coveralls](https://coveralls.io).
**Modern Javascript**

<a name="resources"></a>
### Resources
You're free to use the latest and greatest Javascript and [JSX](https://github.com/vuejs/babel-plugin-transform-vue-jsx). Your code will be compiled by Babel into something that every browser can understand.

This theme uses quite a few different tools. If you've never used some of these before, it is highly recommended that you familiarize yourself with them by giving their docs the once over.
**Unit testing**

- [Karma](https://karma-runner.github.io/1.0/index.html)
- [Vue](http://vuejs.org/guide)
- [Vue Loader](http://vue-loader.vuejs.org)
- [Vue Resource](https://github.com/vuejs/vue-resource)
- [Vue Router](http://router.vuejs.org)
- [Webpack](https://webpack.github.io)
Every aspect of this theme is unit testable, with great tooling set up to help you deliver rock solid code. This includes the ability to easily render components in tests, mock dependencies, and even spy on functions. In addition to this, code coverage reporting is already configured, which means it's trivially easy to integrate with a service like [CodeCov](https://codecov.io).
26 changes: 13 additions & 13 deletions template/build/build.js → build/build.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
// https://github.com/shelljs/shelljs
require('shelljs/global');
require('./check-versions')();

env.NODE_ENV = 'production';
process.env.NODE_ENV = 'production';

var config = require('../config');
var ora = require('ora');
var path = require('path');
var chalk = require('chalk');
var shell = require('shelljs');
var webpack = require('webpack');
var config = require('../config');
var webpackConfig = require('./webpack.prod.conf');

console.log(
' Tip:\n' +
' Built files are meant to be served over an HTTP server.\n' +
' Opening index.htm over file:// won\'t work.\n'
);

var spinner = ora('building for production...');
spinner.start();

var assetsPath = path.join(config.build.assetsRoot, config.build.assetsSubDirectory);
rm('-rf', assetsPath);
mkdir('-p', assetsPath);
cp('-R', 'static/', assetsPath);
shell.rm('-rf', assetsPath);
shell.mkdir('-p', assetsPath);
shell.config.silent = true;
shell.cp('-R', 'static/*', assetsPath);
shell.config.silent = false;

webpack(webpackConfig, function (err, stats) {
spinner.stop();
Expand All @@ -36,5 +34,7 @@ webpack(webpackConfig, function (err, stats) {
chunks: false,
colors: true,
modules: false,
}) + '\n');
}) + '\n\n');

console.log(chalk.cyan(' Build complete.\n'));
});
48 changes: 48 additions & 0 deletions build/check-versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
var chalk = require('chalk');
var semver = require('semver');
var packageConfig = require('../package.json');

function exec (cmd) {
return require('child_process').execSync(cmd).toString().trim();
};

var versionRequirements = [
{
name: 'node',
currentVersion: semver.clean(process.version),
versionRequirement: packageConfig.engines.node,
},
{
name: 'npm',
currentVersion: exec('npm --version'),
versionRequirement: packageConfig.engines.npm,
},
];

module.exports = function () {
var warnings = [];
for (var i = 0; i < versionRequirements.length; i++) {
var mod = versionRequirements[i];
if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
warnings.push(
mod.name + ': ' +
chalk.red(mod.currentVersion) + ' should be ' +
chalk.green(mod.versionRequirement)
);
}
}

if (warnings.length) {
console.log('');
console.log(chalk.yellow('To use this template, you must update following to modules:'));
console.log();

for (var i = 0; i < warnings.length; i++) {
var warning = warnings[i];
console.log(' ' + warning);
}

console.log();
process.exit(1);
}
};
File renamed without changes.
51 changes: 38 additions & 13 deletions template/build/dev-server.js → build/dev-server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
var browserSync = require('browser-sync');
require('./check-versions')();
var config = require('../config');

if (!process.env.NODE_ENV) {
process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV);
}

var browserSync = require('browser-sync');
var express = require('express');
var opn = require('opn');
var path = require('path');
var proxyMiddleware = require('http-proxy-middleware');
var webpack = require('webpack');
Expand All @@ -9,7 +16,10 @@ var webpackConfig = process.env.NODE_ENV === 'testing'
: require('./webpack.dev.conf');

// default port where dev server listens for incoming traffic
var port = process.env.PORT || config.dev.port;
var port = process.env.PORT;

// automatically open browser, if not set will be false
var autoOpenBrowser = !!config.dev.autoOpenBrowser;

// Define HTTP proxies to your custom API backend
// https://github.com/chimurai/http-proxy-middleware
Expand All @@ -20,13 +30,12 @@ var compiler = webpack(webpackConfig);

var devMiddleware = require('webpack-dev-middleware')(compiler, {
publicPath: webpackConfig.output.publicPath,
stats: {
chunks: false,
colors: true,
},
quiet: true,
});

var hotMiddleware = require('webpack-hot-middleware')(compiler);
var hotMiddleware = require('webpack-hot-middleware')(compiler, {
log: () => {},
});

// force page reload when html-webpack-plugin template changes
compiler.plugin('compilation', function (compilation) {
Expand All @@ -41,48 +50,64 @@ Object.keys(proxyTable).forEach(function (context) {
var options = proxyTable[context];

if (typeof options === 'string') {
options = { target: options }
options = { target: options };
}

app.use(proxyMiddleware(context, options));
app.use(proxyMiddleware(options.filter || context, options));
});

// handle fallback for HTML5 history API
app.use(require('connect-history-api-fallback')());

// serve webpack bundle output
app.use(devMiddleware);

// enable hot-reload and state-preserving
// compilation error display
app.use(hotMiddleware);

// serve pure static assets
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory);
app.use(staticPath, express.static('./static'));

// browser sync
browserSync({
proxy: "{{ proxy }}",
proxy: 'http://vuetober.october.dev',
open: false,
middleware: [
devMiddleware,
hotMiddleware,
],
rewriteRules: [
{
match: /<link(.*){{ name }}\/assets(.*?)>/ig,
match: /<link href=\/themes\/oc-vuetober-theme\/assets(.*?)>/ig,
fn: function(match) {
return '';
},
},
{
match: /<div id=\"?app\"?><\/div>(.*)<\/body>/ig,
fn: function(match) {
return '<div id="app"></div><script src="/app.js"></script></body>';
return '<div id="app"></div><script src="/app.js"></script></body>';
},
},
],
});

var uri = 'http://localhost:3000';

devMiddleware.waitUntilValid(function () {
console.log('> Listening at ' + uri + '\n');
});

module.exports = app.listen(port, function (err) {
if (err) {
console.log(err);
return;
}

console.log('Listening at http://localhost:3000' + '\n');
// when env is testing, don't need open it
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
opn(uri);
}
});
Loading

0 comments on commit 9e2c661

Please sign in to comment.