Skip to content

Commit

Permalink
feat(cli): aadded resolve support for config
Browse files Browse the repository at this point in the history
  • Loading branch information
Gcaufy committed Sep 6, 2018
1 parent 6b2b2b2 commit d7465d2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
33 changes: 31 additions & 2 deletions packages/cli/core/plugins/parser/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const path = require('path');
const loaderUtils = require('loader-utils');


exports = module.exports = function () {
this.register('wepy-parser-config', function (rst) {
this.register('wepy-parser-config', function (rst, ctx) {
let configString = rst.content.replace(/^\n*/, '').replace(/\n*$/, '');
configString = configString || '{}';
let config = null;
Expand All @@ -11,6 +15,31 @@ exports = module.exports = function () {
}
config.component = true;
config.usingComponents = config.usingComponents || {};
return Promise.resolve(config);

let componentKeys = Object.keys(config.usingComponents);

if (componentKeys.length === 0) {
return Promise.resolve(config);
}

// Getting resolved path for usingComponents

let resolved = Object.keys(config.usingComponents).map(comp => {
const url = config.usingComponents[comp];
const moduleRequest = loaderUtils.urlToRequest(url, url.charAt(0) === '/' ? '' : null);
return this.resolvers.normal.resolve({}, path.dirname(ctx.file), moduleRequest, {}).then(rst => {
let parsed = path.parse(rst.path);
let fullpath = path.join(parsed.dir, parsed.name); // remove file extention
let relative = path.relative(path.dirname(ctx.file), fullpath);
return [comp, relative];
});
});

return Promise.all(resolved).then(rst => {
rst.forEach(item => {
config.usingComponents[item[0]] = item[1];
});
return config;
});
});
}
26 changes: 17 additions & 9 deletions packages/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d7465d2

Please sign in to comment.