Skip to content

Commit

Permalink
Added fix config utility
Browse files Browse the repository at this point in the history
  • Loading branch information
pkarw committed Jan 11, 2018
1 parent b58cfc4 commit f1dfc44
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ npm-debug.log
.vscode/
.idea/
yarn.lock
src/config.json
config/local.json
package-lock.json
var
6 changes: 6 additions & 0 deletions build/webpack.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const path = require('path')
// const projectRoot = path.resolve(__dirname, '../')
const vueConfig = require('./vue-loader.config')

const config = require('config')
const fs = require('fs')
fs.writeFileSync(path.resolve(__dirname, '../build/config.json'), JSON.stringify(config))


module.exports = {
devtool: '#source-map',
entry: {
Expand All @@ -15,6 +20,7 @@ module.exports = {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
extensions: ['.js', '.vue'],
alias: {
config: path.resolve(__dirname, '../build/config.json'),
core_pages: path.resolve(__dirname, '../src/pages'),
core_components: path.resolve(__dirname, '../src/components'),
core_stores: path.resolve(__dirname, '../src/store'),
Expand Down
2 changes: 1 addition & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
"endpoint": "http://localhost:8080/api/ext/mailchimp-subscribe/subscribe"
},
"registeredExtensions": ["custom_extension", "mailchimp-subscribe"]
}
}
9 changes: 5 additions & 4 deletions doc/Installing on Linux and MacOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ To test out the application you'll need some test data. In vue-storefront-api/va
First step is to configure the application:

```
cp src/config.example.json src/config.json
nano config.json
cp config/default.json config/local.json
nano config/local.json
```
The config file is quite simple, but here you have some comments: [Config file for vue-storefront](https://github.com/DivanteLtd/vue-storefront/wiki/Config-file-format-for-vue-storefront).

Expand Down Expand Up @@ -84,10 +84,11 @@ npm install
```

You have to prepare the config:
(we re using powerfull node.js library for config files, check the docs to learn more on it: https://github.com/lorenwest/node-config)

```
cp src/config.example.json src/config.json
nano config.json
cp config/default.json config/local.json
nano config/local.json
```

And then you can build app and run dev server:
Expand Down
5 changes: 3 additions & 2 deletions doc/Installing on Windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Vue storefront is based on open source technologies which SHOULD (in theory ;))
2. Clone the [vue-storefront](https://github.com/DivanteLtd/vue-storefront) project: `git clone https://github.com/DivanteLtd/vue-storefront.git vue-storefront`
3. Go to vue-storefront in dir: `cd vue-storefront`
4. Install dependencies: `npm install`
5. Copy `src/config.example.json` to `src/config.json`
6. Images: because vue-storefront-api uses `imagemagick` and some nodejs cmdline bindings it can be dificult to run the image proxy on localhost/windows machine. Please point out the vue-storefront to image proxy provided by changing `src/config.json` images.baseUrl:
5. Copy `config/default.json` to `config/local.json`
6. Images: because vue-storefront-api uses `imagemagick` and some nodejs cmdline bindings it can be dificult to run the image proxy on localhost/windows machine. Please point out the vue-storefront to image proxy provided by changing `config/local.json` images.baseUrl:

```json
export default {
Expand All @@ -43,6 +43,7 @@ export default {
baseUrl: 'https://demo.vuestorefront.io/img/'
}
}
(we re using powerfull node.js library for config files, check the docs to learn more on it: https://github.com/lorenwest/node-config)

```
6. Run API using `npm run dev`
19 changes: 19 additions & 0 deletions fixconfigs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

const path = require('path')
const fs = require('fs')

const CONFIG_EXAMPLE_ORG_PATH = path.resolve(__dirname, './src/config.example.json')
const CONFIG_ORG_PATH = path.resolve(__dirname, './src/config.json')
const CONFIG_DEST_PATH = path.resolve(__dirname, './config/local.json')

if (!fs.existsSync(CONFIG_DEST_PATH)) {
console.log('Fixing old config paths!')
fs.writeFileSync(CONFIG_DEST_PATH, fs.readFileSync(CONFIG_ORG_PATH))
console.log('Removing old configs paths!')
fs.unlinkSync(CONFIG_ORG_PATH)

if (fs.existsSync(CONFIG_EXAMPLE_ORG_PATH)) {
fs.unlinkSync(CONFIG_EXAMPLE_ORG_PATH)
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"start": "cross-env NODE_ENV=production node server",
"installer": "node installer",
"all": "node all",
"dev": "node server",
"fixconfigs": "node fixconfigs.js",
"dev": "npm run fixconfigs && node server",
"dev:inspect": "node --inspect server",
"build:client": "cross-env NODE_ENV=production webpack --config ./build/webpack.client.config.js --progress --hide-modules",
"build:server": "cross-env NODE_ENV=production webpack --config ./build/webpack.server.config.js --progress --hide-modules",
Expand Down
2 changes: 1 addition & 1 deletion src/api/search.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let es = require('elasticsearch')

import { Config as config } from 'src/config'
import config from 'config'
import _ from 'lodash'
import { slugify } from '../lib/filters'
import hash from 'object-hash'
Expand Down
3 changes: 2 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import App from './themes/default/App.vue'
import store from './store'
import router from './router'
import { EventBusPlugin as EventBus } from './event-bus'
import { ConfigPlugin as ConfigPlg, Config as config } from 'src/config'
import { ConfigPlugin as ConfigPlg } from 'src/config'
import config from 'config'

import { sync } from 'vuex-router-sync'

Expand Down
2 changes: 1 addition & 1 deletion src/client-entry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createApp } from './app'
import { Config as config } from 'src/config'
import config from 'config'
require('./service-worker-registration') // register the service worker

const { app, router, store } = createApp()
Expand Down
6 changes: 3 additions & 3 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const Config = require('config')
import config from 'config'

const ConfigPlugin = {
install (Vue) {
if (!Vue.prototype.$config) {
Object.defineProperties(Vue.prototype, {
$config: {
get: function () {
return Config
return config
}
}
})
}
}
}

export { Config as default, ConfigPlugin }
export { config as default, ConfigPlugin }
2 changes: 1 addition & 1 deletion src/lib/filters.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Vue from 'vue'
import { Config as config } from 'src/config'
import config from 'config'
import he from 'he'

/**
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as types from '../mutation-types'
import { ValidationError } from 'lib/exceptions'
import * as entities from 'lib/entities'
import EventBus from 'src/event-bus'
import { Config as config } from 'src/config'
import config from 'config'
const Ajv = require('ajv') // json validator

// initial state
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/product.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as types from '../mutation-types'
import { Config as config } from 'src/config'
import config from 'config'
const bodybuilder = require('bodybuilder')
import { quickSearchByQuery } from '../../api/search'
import { entityKeyName } from '../../lib/entities'
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/stock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config as config } from 'src/config'
import config from 'config'
import EventBus from 'src/event-bus'
import store from '../'

Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/sync.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as types from '../mutation-types'
import * as entities from 'lib/entities'
import { Config as config } from 'src/config'
import config from 'config'
import EventBus from 'src/event-bus'

// initial state
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/user.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as types from '../mutation-types'
import { Config as config } from 'src/config'
import config from 'config'
import EventBus from 'src/event-bus'

// initial state
Expand Down

0 comments on commit f1dfc44

Please sign in to comment.