Skip to content

Commit

Permalink
remove pageFlag
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaslee119 authored and 李 立 committed Oct 11, 2017
1 parent c256ca7 commit 4423d9d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
10 changes: 2 additions & 8 deletions lib/buildTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@ module.exports = function buildTemplate(components, buildOption) {
if (!Array.isArray(components))
reportError('components is not an array');
components.forEach((component) => {
let templatePath;
if (component.pageFlag) {
templatePath = path.resolve(buildOption.srcPath, component.dir, `${component.name}${buildOption.ext}`);
} else {
templatePath = path.resolve(buildOption.srcPath, component.dir, component.name, `${component.name}${buildOption.ext}`);
}
const templatePath = path.resolve(buildOption.srcPath, component.dir, component.name, `${component.base}`);
if (fs.existsSync(templatePath)) {
try {
let template = fsx.readFileSync(templatePath, 'utf8');
// TODO: implement css namespace here shodow DOM
template = setScope(template, component.scopeNames, component.scopeID);
fsx.ensureDirSync(path.resolve(buildOption.builtTemplatePath, component.dir));
fsx.writeFileSync(path.resolve(buildOption.builtTemplatePath, component.dir, `${component.name}${buildOption.ext}`), template);
fsx.writeFileSync(path.resolve(buildOption.builtTemplatePath, component.dir, `${component.base}`), template);
} catch (e) {
reportError(e);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/parsePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module.exports = function parsePage(source, extractor, buildOption) {
components = [];
recursiveParse(source, extractor, buildOption.srcPath);
const pageSelf = path.parse(buildOption.currentPagePath);
pageSelf.dir = pageSelf.dir.replace(pageSelf.name, '').replace(`${buildOption.srcPath}/`, '');
pageSelf.root = '';
pageSelf.pageFlag = true;
components.push(pageSelf);
return components;
Expand Down
6 changes: 1 addition & 5 deletions lib/putScopeName.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import fsx from 'fs-extra';

// TODO: should improve
function findScopeName (component, buildOption) {
let cssFilePath;
if (component.pageFlag)
cssFilePath = path.resolve(buildOption.srcPath, component.dir, `${component.name}.css`);
else
cssFilePath = path.resolve(buildOption.srcPath, component.dir, component.name, `${component.name}.css`);
const cssFilePath = path.resolve(buildOption.srcPath, component.dir, component.name, `${component.name}.css`);

const css = fsx.readFileSync(cssFilePath, 'utf8');
const selectorNameReg = new RegExp("([^\r\n,{}]+)(,(?=[^}]*{)|\s*{)", 'g');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webpack-component-loader",
"version": "1.0.2",
"version": "1.0.3",
"description": "A webpack loader to componentify CSS/JS/HTML without framework",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 4423d9d

Please sign in to comment.