Skip to content

Commit

Permalink
Switch from vueify to Vue CLI
Browse files Browse the repository at this point in the history
vueify is now deprecated, and Vue CLI seems to be what is recommended
for web apps. Vue CLI is also well documented.

To make the switch to Vue CLI, I first created a new project using Vue
CLI, then made changes to the project, then moved files from the
existing repository to the project.

I created the project as follows:

$ vue create odk-central-frontend

Vue CLI v3.7.0
? Please pick a preset: Manually select features
? Check the features needed for your project:
  Babel, Router, Vuex, CSS Pre-processors, Linter, Unit
? Use history mode for router?
  (Requires proper server setup for index fallback in production)
  No
? Pick a CSS pre-processor
  (PostCSS, Autoprefixer and CSS Modules are supported by default):
  Sass/SCSS (with node-sass)
? Pick a linter / formatter config: Airbnb
? Pick additional lint features:
? Pick a unit testing solution: Mocha
? Where do you prefer placing config for Babel, PostCSS, ESLint, etc.?
  In dedicated config files

I then made these changes to the project:

- package.json
  - Specified options for `npm run build` and `npm run lint`.
- Changed .browserslistrc.
- Removed favicon.ico, including from the HTML.
- Added a copyright notice and license information to files.
- Removed dangling commas from some config files.

Making the switch entailed quite a few other changes:

- I updated my version of Node to 8.16, because Vue CLI recommends
  8.11.0+.
- Updated Vue from 2.5 to 2.6. See #207.
- With vueify, our Babel configuration included the stage 2 preset.
  However, I think that was just the vueify default, and Babel has since
  deprecated stage presets. Vue CLI seems to include some polyfills by
  default, including Promise.prototype.finally(), which we use, so I
  think we can just use the Vue CLI defaults. As a result, I think we
  have bumped the major version of Babel.
- Vue CLI seems to import styles in a slightly different order from
  vueify. With vueify, we had App.vue contain the global styles,
  importing the Bootstrap and IcoMoon CSS. However, before importing
  App's styles, Vue CLI seems to import the styles of the components
  that App uses, Alert and Navbar. Instead, we want Vue CLI to import
  the global styles before Alert's and Navbar's styles. For that reason,
  we now import the global styles in setup.js. The Boostrap and IcoMoon
  CSS are now stored in .css files, while the global styles specific to
  Central are stored in app.scss, outside App.vue.
  - The Sass in app.scss no longer imports the Bootstrap CSS, so our
    custom class .navbar-icon-bar no longer @extends the Bootstrap class
    .icon-bar: the styles are simply copied instead.
- Vue CLI threw an error for the Glyphicon url() references in the
  Bootstrap CSS, so I removed all the Glyphicon-related CSS. We had
  already removed that CSS in #44, but the removal was undone in #199.
  See also #142.
- I had trouble using relative references to the font assets in
  icomoon.css, so I moved the font assets to public/ and changed the
  references to absolute. See
  https://cli.vuejs.org/guide/html-and-static-assets.html#the-public-folder.
  I would guess that there is a way to continue using relative
  references, but it did not seem worth spending too much time on.
  - Note that Vue CLI copies assets to the dist/ directory: this commit
    closes #77.
- Renamed lib/ to src/. This will make blaming more difficult, but Vue
  CLI does not have an option to specify a directory other than src/.
- Vue CLI flagged imports that should have imported a function
  individually rather than importing the default export, which I
  corrected.
- Vue CLI flagged dependency cycles that involved src/router.js and
  src/mixins/conditional-route.js. I resolved those by adding a new
  file, src/util/router.js.
- Vue CLI flagged a component that referenced a nonexistent
  awaitingResponse property (FormSettings).
- Vue CLI includes the command `npm run serve`, which starts a
  development server that provides hot-module-replacement. However, this
  wasn't playing well with our NGINX config, so I removed
  `npm run serve`. Instead, I added `npm run dev`, which works similarly
  to our previous setup: files are built and outputted to dist/, and if
  a file is changed, files are rebuilt. Hot-module-replacement is not
  provided.
- Moved index.html to public/.
  - Note that Vue CLI builds the final index.html: this commit closes
    #140.
- While we have been using Karma and avoriaz, Vue CLI uses JSDOM and Vue
  Test Utils. Replacing Karma with JSDOM seemed nontrivial, so I updated
  our Karma config to work with Vue CLI, replacing Vue CLI's default
  `npm run test:unit` with our own `npm run test`. I'm not sure how
  robust the Karma config really is, though it seems to be working. I
  think we will eventually want to migrate to JSDOM and Vue Test Utils.
  However, now doesn't seem like the right time.
- Rather than first running test/setup.js, then *.spec.js, Karma now
  simply runs test/index.js. This is more performant, avoiding an
  out-of-memory error.
- Removed proxyquireify. Closes #145.
- Bumped the major version of the eslint and eslint-plugin-vue
  dependencies.
- Created an additional ESLint config for tests.
- Resolved new ESLint errors, including by updating the root config.
- I completely removed the existing package-lock.json, opting to rerun
  `npm install`.
  - Internal behavior of the Vue router that we relied on during
    testing changed in a patch version, so we now do not destroy the
    first component into which we inject the router. See the comments in
    test/index.js for details.
- Since we now do not need to update dependencies from vueify, this
  commit closes #32.
- Updated the CircleCI config.
- Updated the readme and a comment in nginx.conf.
  • Loading branch information
matthew-white committed May 27, 2019
1 parent 720e9a8 commit 17d5de0
Show file tree
Hide file tree
Showing 161 changed files with 9,327 additions and 5,428 deletions.
15 changes: 15 additions & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2019 ODK Central Developers
# See the NOTICE file at the top-level directory of this distribution and at
# https://github.com/opendatakit/central-frontend/blob/master/NOTICE.
#
# This file is part of ODK Central. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this distribution and at
# https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central,
# including this file, may be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.

last 2 Chrome versions
last 2 Edge versions
last 2 Firefox versions
last 2 Safari versions
IE 11
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:

- run: npm run lint

- run: npm test
- run: npm run test
71 changes: 71 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint'
},
extends: [
'plugin:vue/recommended',
'@vue/airbnb'
],
env: {
node: true
},
globals: {
'$': false,
alert: false,
document: false,
window: false
},
rules: {
'arrow-parens': 'off',
'class-methods-use-this': 'off',
'comma-dangle': ['error', 'never'],
'curly': 'off',
'implicit-arrow-linebreak': 'off',
'lines-between-class-members': ['error', 'always', {
exceptAfterSingleLine: true
}],
'no-confusing-arrow': ['error', { allowParens: true }],
'no-console': 'error',
'no-debugger': 'error',
'no-multiple-empty-lines': ['error', { max: 3 }],
'no-restricted-syntax': ['error', 'LabeledStatement', 'WithStatement'],
'no-underscore-dangle': 'off',
'nonblock-statement-body-position': 'off',
'object-curly-newline': ['error', {
multiline: true,
minProperties: 0,
consistent: true
}],
'operator-linebreak': ['error', 'after', {
overrides: { '?': 'before', ':': 'before' }
}],
'space-before-function-paren': ['error', {
anonymous: 'never',
named: 'never',
asyncArrow: 'always'
}],
'spaced-comment': 'off',
'vue/html-closing-bracket-newline': ['error', {
singleline: 'never',
multiline: 'never'
}],
'vue/html-closing-bracket-spacing': ['error', {
startTag: 'never',
endTag: 'never',
selfClosingTag: 'never'
}],
'vue/html-indent': 'off',
'vue/html-self-closing': ['error', {
html: {
void: 'never',
normal: 'never',
component: 'always'
},
svg: 'always',
math: 'always'
}],
'vue/max-attributes-per-line': 'off',
'vue/singleline-html-element-content-newline': 'off'
}
};
60 changes: 0 additions & 60 deletions .eslintrc.json

This file was deleted.

16 changes: 12 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@

.DS_Store
node_modules
dist/build.js
dist/build.css
yarn-error.log
npm-debug.log
/dist

# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
<!--
Copyright 2019 ODK Central Developers
See the NOTICE file at the top-level directory of this distribution and at
https://github.com/opendatakit/central-frontend/blob/master/NOTICE.
This file is part of ODK Central. It is subject to the license terms in
the LICENSE file found in the top-level directory of this distribution and at
https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central,
including this file, may be copied, modified, propagated, or distributed
except according to the terms contained in the LICENSE file.
-->
# Contributing to ODK Central Frontend

## Contributing Code
Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ except according to the terms contained in the LICENSE file.
[![License](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Build status](https://circleci.com/gh/opendatakit/central-frontend.svg?style=shield)](https://circleci.com/gh/opendatakit/central-frontend)

ODK Central Frontend uses Vue.js to provide the frontend for [ODK Central](https://github.com/opendatakit/central). It is currently under development.
ODK Central Frontend uses Vue.js to provide the frontend for [ODK Central](https://github.com/opendatakit/central). It is currently [under development](https://forum.opendatakit.org/t/whats-coming-in-central-over-the-next-few-years/19677).

## Setting up your development environment

Install npm, then install Node package dependencies with `npm install`.
First, install Node.js 8 (specifically 8.11.0+).

Install NGINX. Depending on your OS and how you install NGINX, you may need to change the absolute paths in ODK Central Frontend's [`nginx.conf`](/nginx.conf).
Next, install dependencies by running `npm install`.

Install NGINX. Depending on your operating system and how you install NGINX, you may need to change the absolute paths in ODK Central Frontend's [`nginx.conf`](/nginx.conf).

You will also need to set up [ODK Central Backend](https://github.com/opendatakit/central-backend).

Expand All @@ -36,23 +38,23 @@ Next, build ODK Central Frontend files for development by running `npm run dev`.
Finally, run NGINX by changing the working directory to the root directory of the repository, then typing the following:

```bash
nginx -c "$PWD/nginx.conf" -p "$PWD/"
nginx -c "$PWD/nginx.conf" -p "$PWD/dist/"
```

We specify `-p "$PWD/"` so that relative paths in [`nginx.conf`](/nginx.conf) are relative to the root directory of the repository.
We specify `-p "$PWD/dist/"` so that relative paths in [`nginx.conf`](/nginx.conf) are relative to `dist/`.

NGINX effectively places ODK Central Frontend and ODK Central Backend at the same origin, avoiding cross-origin requests.

ODK Central Frontend will be available on port 8989.

## Deploying to production

To build ODK Central Frontend files for production with minification, run `npm run build`. The files will be outputted to `dist/`. For more details on this command, see the [documentation for vueify](https://github.com/vuejs/vueify).
To build ODK Central Frontend files for production with minification, run `npm run build`. The files will be outputted to `dist/`. For more details on this command, see the [documentation for Vue CLI](https://cli.vuejs.org/).

For more information on deploying to production, see the [ODK Central repository](https://github.com/opendatakit/central).

## Testing

To run unit tests, type `npm test`.
To run unit tests, type `npm run test`.

For linting, type `npm run lint`. We use [ESLint](https://eslint.org/) with [rules](/.eslintrc.json) based on the [Airbnb JavaScript style guide](https://github.com/airbnb/javascript).
For linting, run `npm run lint`. We use [rules](/.eslintrc.json) based on the [Airbnb JavaScript style guide](https://github.com/airbnb/javascript).
16 changes: 16 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Copyright 2019 ODK Central Developers
See the NOTICE file at the top-level directory of this distribution and at
https://github.com/opendatakit/central-frontend/blob/master/NOTICE.
This file is part of ODK Central. It is subject to the license terms in
the LICENSE file found in the top-level directory of this distribution and at
https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central,
including this file, may be copied, modified, propagated, or distributed
except according to the terms contained in the LICENSE file.
*/
module.exports = {
presets: [
'@vue/app'
]
};
Empty file removed dist/.gitkeep
Empty file.
43 changes: 24 additions & 19 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
// https://github.com/Nikku/karma-browserify
module.exports = function (config) {
/*
This config is based on:
- https://github.com/Nikku/karma-browserify
- https://github.com/eddyerburgh/vue-test-utils-karma-example
- https://github.com/eddyerburgh/avoriaz-karma-mocha-example
*/

const webpackConfig = require('./node_modules/@vue/cli-service/webpack.config.js');

const { entry, ...configForTests } = webpackConfig;
configForTests.devtool = 'inline-source-map';

module.exports = function(config) {
config.set({
browsers: ['ChromeHeadless'],
frameworks: ['browserify', 'mocha'],
frameworks: ['mocha'],
files: [
'test/setup.js',
'test/**/*.spec.js',
{ pattern: 'assets/fonts/icomoon.ttf', included: false, served: true }
'test/index.js',
{ pattern: 'public/fonts/icomoon.ttf', included: false, served: true }
],
proxies: {
'/assets/': '/base/assets/'
'/fonts/': '/base/public/fonts/'
},
reporters: ['spec'],
preprocessors: {
'test/**/*.js': ['browserify']
},
browserify: {
debug: true,
// needed to enable mocks
plugin: [require('proxyquireify').plugin]
'test/index.js': ['webpack', 'sourcemap']
},
// if you want to continuously re-run tests on file-save,
// replace the following line with `autoWatch: true`
webpack: configForTests,
browsers: ['ChromeHeadless'],
reporters: ['spec'],
singleRun: true
})
}
});
};
4 changes: 2 additions & 2 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ http {
server {
listen 8989;
server_name localhost;
# Specify the root directory of the repository to `nginx -p` so that . is
# relative to the root of the repository.
# Specify the dist/ directory of the repository to `nginx -p` so that . is
# relative to dist/.
root .;
expires -1;

Expand Down
Loading

0 comments on commit 17d5de0

Please sign in to comment.