Skip to content

Commit

Permalink
added yaml loader
Browse files Browse the repository at this point in the history
  • Loading branch information
ZIS committed Feb 12, 2020
1 parent db501ec commit 9a18325
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BASE_URL=http://localhost:3000
62 changes: 62 additions & 0 deletions nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const path = require('path')

const isPlainObject = require('lodash/isPlainObject')
const extend = require('lodash/extend')

export default {
mode: 'spa',
Expand Down Expand Up @@ -60,6 +64,64 @@ export default {
** You can extend webpack config here
*/
extend (config, ctx) {

/**
* custom configuration for store/constants.yaml
*/
const yaml = require('js-yaml')
const actionSufixes = ['STARTED', 'COMPLETED', 'SUCCESSFUL', 'FAILED']

config.module.rules.push({
test: /\.yaml$/,
include: path.resolve(__dirname, 'store/constants'),
use: [{
loader: 'skeleton-loader',
options: {
procedure: function (content) {
let parsed = yaml.safeLoad(content)
let obj = {}
let actions = parsed.ACTION ? parsed.ACTION : []
let generics = parsed.ACTION ? (parsed.GENERIC ? parsed.GENERIC : []) : parsed

for (var i = 0; i < actions.length; i++) {
obj[actions[i]] = actions[i]
for (var j = 0; j < actionSufixes.length; j++) {
let type = actions[i] + '_' + actionSufixes[j]
obj[type] = type
}
}

for (i = 0; i < generics.length; i++) {
if (isPlainObject(generics[i])) {
extend(obj, generics[i])
} else {
obj[generics[i]] = generics[i]
}
}

return obj
},
toCode: true
}
}]
})

/**
* configuration for other yaml files
*/
config.module.rules.push({
test: /\.yaml$/,
exclude: path.resolve(__dirname, 'store/constants'),
use: [{
loader: 'skeleton-loader',
options: {
procedure: function (content) {
return yaml.load(content)
},
toCode: true
}
}]
})
}
}
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"@nuxtjs/axios": "^5.3.6",
"@nuxtjs/dotenv": "^1.4.0",
"loadsh": "^0.0.4",
"nuxt": "^2.0.0"
},
"devDependencies": {
Expand All @@ -22,7 +23,10 @@
"babel-eslint": "^10.0.1",
"eslint": "^6.1.0",
"eslint-plugin-nuxt": ">=0.4.2",
"js-yaml": "^3.13.1",
"node-sass": "^4.13.1",
"sass-loader": "^8.0.2"
"raw-loader": "^4.0.0",
"sass-loader": "^8.0.2",
"skeleton-loader": "^2.0.0"
}
}
13 changes: 13 additions & 0 deletions store/constants.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ACTION:
# All items under ACTION key will contribute three respective mutation types
# 1. {ACTION_NAME}_STARTED
# 2. {ACTION_NAME}_COMPLETED
# 3. {ACTION_NAME}_SUCCESSFUL
# 4. {ACTION_NAME}_FAILED
- LOAD_CATEGORIES
GENERIC:
# All items under GENERIC key will be process
-
API_END_POINTS:
LOCATION: 'location'
PICKUP_POINT: 'pickup-point'
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5024,6 +5024,11 @@ loadjs@^4.2.0:
resolved "https://registry.yarnpkg.com/loadjs/-/loadjs-4.2.0.tgz#2a0336376397a6a43edf98c9ec3229ddd5abb6f6"
integrity sha512-AgQGZisAlTPbTEzrHPb6q+NYBMD+DP9uvGSIjSUM5uG+0jG15cb8axWpxuOIqrmQjn6scaaH8JwloiP27b2KXA==

loadsh@^0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/loadsh/-/loadsh-0.0.4.tgz#5314babd12bb13315dde024a4ca70758c5489d2d"
integrity sha512-U+wLL8InpfRalWrr+0SuhWgGt10M4OyAk6G8xCYo2rwpiHtxZkWiFpjei0vO463ghW8LPCdhqQxXlMy2qicAEw==

locate-path@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
Expand Down Expand Up @@ -7008,6 +7013,14 @@ [email protected]:
iconv-lite "0.4.24"
unpipe "1.0.0"

raw-loader@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/raw-loader/-/raw-loader-4.0.0.tgz#d639c40fb9d72b5c7f8abc1fb2ddb25b29d3d540"
integrity sha512-iINUOYvl1cGEmfoaLjnZXt4bKfT2LJnZZib5N/LLyAphC+Dd11vNP9CNVb38j+SAJpFI1uo8j9frmih53ASy7Q==
dependencies:
loader-utils "^1.2.3"
schema-utils "^2.5.0"

read-cache@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/read-cache/-/read-cache-1.0.0.tgz#e664ef31161166c9751cdbe8dbcf86b5fb58f774"
Expand Down Expand Up @@ -7599,6 +7612,13 @@ simple-swizzle@^0.2.2:
dependencies:
is-arrayish "^0.3.1"

skeleton-loader@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/skeleton-loader/-/skeleton-loader-2.0.0.tgz#4154ed123d28be036c5d65297633d9049a70ea63"
integrity sha1-QVTtEj0ovgNsXWUpdjPZBJpw6mM=
dependencies:
loader-utils "^1.1.0"

slice-ansi@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-2.1.0.tgz#cacd7693461a637a5788d92a7dd4fba068e81636"
Expand Down

0 comments on commit 9a18325

Please sign in to comment.