Resolve style sheets paths during script/build for bundled packages

This commit is contained in:
Antonio Scandurra
2017-03-14 14:27:07 +01:00
parent b2ef8abf0a
commit a1da6c9196
2 changed files with 33 additions and 9 deletions

View File

@@ -2,7 +2,7 @@
const CSON = require('season')
const deprecatedPackagesMetadata = require('../deprecated-packages')
const fs = require('fs-extra')
const fs = require('fs-plus')
const normalizePackageData = require('normalize-package-data')
const path = require('path')
const semver = require('semver')
@@ -76,6 +76,26 @@ function buildBundledPackagesMetadata () {
}
}
const packageStyleSheetsPath = path.join(packagePath, 'styles')
let styleSheets = null
if (packageMetadata.mainStyleSheet) {
styleSheets = [fs.resolve(packagePath, packageMetadata.mainStyleSheet)]
} else if (packageMetadata.styleSheets) {
styleSheets = packageMetadata.styleSheets.map((name) => (
fs.resolve(packageStyleSheetsPath, name, ['css', 'less', ''])
))
} else {
const indexStylesheet = fs.resolve(packagePath, 'index', ['css', 'less'])
if (indexStylesheet) {
styleSheets = [indexStylesheet]
} else {
styleSheets = fs.listSync(packageStyleSheetsPath, ['css', 'less'])
}
}
packageNewMetadata.styleSheetsPaths =
styleSheets.map(styleSheetPath => path.relative(packagePath, styleSheetPath))
packages[packageMetadata.name] = packageNewMetadata
if (packageModuleCache.extensions) {
for (let extension of Object.keys(packageModuleCache.extensions)) {

View File

@@ -358,15 +358,19 @@ class Package
path.join(@path, 'styles')
getStylesheetPaths: ->
stylesheetDirPath = @getStylesheetsPath()
if @metadata.mainStyleSheet
[fs.resolve(@path, @metadata.mainStyleSheet)]
else if @metadata.styleSheets
@metadata.styleSheets.map (name) -> fs.resolve(stylesheetDirPath, name, ['css', 'less', ''])
else if indexStylesheet = fs.resolve(@path, 'index', ['css', 'less'])
[indexStylesheet]
if @bundledPackage and @packageManager.packagesCache[@name].styleSheetsPaths?
styleSheetsPaths = @packageManager.packagesCache[@name].styleSheetsPaths
styleSheetsPaths.map (styleSheetPath) => path.join(@path, styleSheetPath)
else
fs.listSync(stylesheetDirPath, ['css', 'less'])
stylesheetDirPath = @getStylesheetsPath()
if @metadata.mainStyleSheet
[fs.resolve(@path, @metadata.mainStyleSheet)]
else if @metadata.styleSheets
@metadata.styleSheets.map (name) -> fs.resolve(stylesheetDirPath, name, ['css', 'less', ''])
else if indexStylesheet = fs.resolve(@path, 'index', ['css', 'less'])
[indexStylesheet]
else
fs.listSync(stylesheetDirPath, ['css', 'less'])
loadGrammarsSync: ->
return if @grammarsLoaded