mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 07:28:08 +03:00
Store style sheet sources as auxiliary data in the snapshot
This commit is contained in:
parent
fce10242dc
commit
4c6805bf76
@ -26,7 +26,8 @@ module.exports = {
|
||||
repositoryRootPath, apmRootPath, scriptRootPath,
|
||||
buildOutputPath, docsOutputPath, intermediateAppPath, symbolsPath,
|
||||
electronDownloadPath, atomHomeDirPath, homeDirPath,
|
||||
getApmBinPath, getNpmBinPath
|
||||
getApmBinPath, getNpmBinPath,
|
||||
snapshotAuxiliaryData: {}
|
||||
}
|
||||
|
||||
function getChannel () {
|
||||
|
@ -15,6 +15,7 @@ module.exports = function (packagedAppPath) {
|
||||
baseDirPath,
|
||||
mainPath: path.resolve(baseDirPath, '..', 'src', 'initialize-application-window.js'),
|
||||
cachePath: path.join(CONFIG.atomHomeDirPath, 'snapshot-cache'),
|
||||
auxiliaryData: CONFIG.snapshotAuxiliaryData,
|
||||
shouldExcludeModule: (modulePath) => {
|
||||
if (processedFiles > 0) {
|
||||
process.stdout.write('\r')
|
||||
|
@ -28,6 +28,14 @@ module.exports = function () {
|
||||
}
|
||||
}
|
||||
|
||||
CONFIG.snapshotAuxiliaryData.lessSourcesByRelativeFilePath = {}
|
||||
function saveIntoSnapshotAuxiliaryData (absoluteFilePath, contents) {
|
||||
const relativeFilePath = path.relative(CONFIG.intermediateAppPath, absoluteFilePath)
|
||||
if (!CONFIG.snapshotAuxiliaryData.lessSourcesByRelativeFilePath.hasOwnProperty(relativeFilePath)) {
|
||||
CONFIG.snapshotAuxiliaryData.lessSourcesByRelativeFilePath[relativeFilePath] = contents
|
||||
}
|
||||
}
|
||||
|
||||
// Warm cache for every combination of the default UI and syntax themes,
|
||||
// because themes assign variables which may be used in any style sheet.
|
||||
for (let uiTheme of uiThemes) {
|
||||
@ -52,6 +60,7 @@ module.exports = function () {
|
||||
lessSource = FALLBACK_VARIABLE_IMPORTS + lessSource
|
||||
}
|
||||
lessCache.cssForFile(lessFilePath, lessSource)
|
||||
saveIntoSnapshotAuxiliaryData(lessFilePath, lessSource)
|
||||
}
|
||||
|
||||
// Cache all styles in static; don't append variable imports
|
||||
@ -69,10 +78,24 @@ module.exports = function () {
|
||||
// Cache styles for this UI theme
|
||||
const uiThemeMainPath = path.join(CONFIG.intermediateAppPath, 'node_modules', uiTheme, 'index.less')
|
||||
cacheCompiledCSS(uiThemeMainPath, true)
|
||||
for (let lessFilePath of glob.sync(path.join(CONFIG.intermediateAppPath, 'node_modules', uiTheme, '**', '*.less'))) {
|
||||
if (lessFilePath !== uiThemeMainPath) {
|
||||
saveIntoSnapshotAuxiliaryData(lessFilePath, fs.readFileSync(lessFilePath, 'utf8'))
|
||||
}
|
||||
}
|
||||
|
||||
// Cache styles for this syntax theme
|
||||
const syntaxThemeMainPath = path.join(CONFIG.intermediateAppPath, 'node_modules', syntaxTheme, 'index.less')
|
||||
cacheCompiledCSS(syntaxThemeMainPath, true)
|
||||
for (let lessFilePath of glob.sync(path.join(CONFIG.intermediateAppPath, 'node_modules', syntaxTheme, '**', '*.less'))) {
|
||||
if (lessFilePath !== syntaxThemeMainPath) {
|
||||
saveIntoSnapshotAuxiliaryData(lessFilePath, fs.readFileSync(lessFilePath, 'utf8'))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (let lessFilePath of glob.sync(path.join(CONFIG.intermediateAppPath, 'node_modules', 'atom-ui', '**', '*.less'))) {
|
||||
saveIntoSnapshotAuxiliaryData(lessFilePath, fs.readFileSync(lessFilePath, 'utf8'))
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
"csslint": "1.0.2",
|
||||
"donna": "1.0.13",
|
||||
"electron-chromedriver": "~1.3",
|
||||
"electron-link": "0.0.10",
|
||||
"electron-link": "0.0.12",
|
||||
"electron-mksnapshot": "~1.3",
|
||||
"electron-packager": "7.3.0",
|
||||
"electron-winstaller": "2.5.1",
|
||||
|
@ -25,6 +25,7 @@ const generateMetadata = require('./lib/generate-metadata')
|
||||
const generateModuleCache = require('./lib/generate-module-cache')
|
||||
const generateStartupSnapshot = require('./lib/generate-startup-snapshot')
|
||||
const packageApplication = require('./lib/package-application')
|
||||
const prebuildLessCache = require('./lib/prebuild-less-cache')
|
||||
const transpileBabelPaths = require('./lib/fast-transpile-babel-paths')
|
||||
const transpileCoffeeScriptPaths = require('./lib/fast-transpile-coffee-script-paths')
|
||||
|
||||
@ -39,4 +40,5 @@ transpileBabelPaths()
|
||||
transpileCoffeeScriptPaths()
|
||||
generateModuleCache()
|
||||
generateMetadata()
|
||||
prebuildLessCache()
|
||||
packageApplication().then(generateStartupSnapshot)
|
||||
|
@ -6,7 +6,7 @@ module.exports =
|
||||
class LessCompileCache
|
||||
@cacheDir: path.join(process.env.ATOM_HOME, 'compile-cache', 'less')
|
||||
|
||||
constructor: ({resourcePath, importPaths}) ->
|
||||
constructor: ({resourcePath, importPaths, lessSourcesByRelativeFilePath}) ->
|
||||
@lessSearchPaths = [
|
||||
path.join(resourcePath, 'static', 'variables')
|
||||
path.join(resourcePath, 'static')
|
||||
@ -21,6 +21,7 @@ class LessCompileCache
|
||||
cacheDir: @constructor.cacheDir
|
||||
importPaths: importPaths
|
||||
resourcePath: resourcePath
|
||||
lessSourcesByRelativeFilePath: lessSourcesByRelativeFilePath
|
||||
fallbackDir: path.join(resourcePath, 'less-compile-cache')
|
||||
|
||||
setImportPaths: (importPaths=[]) ->
|
||||
|
@ -18,6 +18,12 @@ class ThemeManager
|
||||
@packageManager.onDidActivateInitialPackages =>
|
||||
@onDidChangeActiveThemes => @packageManager.reloadActivePackageStyleSheets()
|
||||
|
||||
@lessSourcesByRelativeFilePath = null
|
||||
if typeof snapshotAuxiliaryData is 'undefined'
|
||||
@lessSourcesByRelativeFilePath = {}
|
||||
else
|
||||
@lessSourcesByRelativeFilePath = snapshotAuxiliaryData.lessSourcesByRelativeFilePath
|
||||
|
||||
initialize: ({@resourcePath, @configDirPath, @safeMode}) ->
|
||||
|
||||
###
|
||||
@ -196,7 +202,7 @@ class ThemeManager
|
||||
loadLessStylesheet: (lessStylesheetPath, importFallbackVariables=false) ->
|
||||
unless @lessCache?
|
||||
LessCompileCache = require './less-compile-cache'
|
||||
@lessCache = new LessCompileCache({@resourcePath, importPaths: @getImportPaths()})
|
||||
@lessCache = new LessCompileCache({@resourcePath, @lessSourcesByRelativeFilePath, importPaths: @getImportPaths()})
|
||||
|
||||
try
|
||||
if importFallbackVariables
|
||||
@ -204,7 +210,8 @@ class ThemeManager
|
||||
@import "variables/ui-variables";
|
||||
@import "variables/syntax-variables";
|
||||
"""
|
||||
less = fs.readFileSync(lessStylesheetPath, 'utf8')
|
||||
relativeFilePath = path.relative(@resourcePath, lessStylesheetPath)
|
||||
less = @lessSourcesByRelativeFilePath[relativeFilePath] ? fs.readFileSync(lessStylesheetPath, 'utf8')
|
||||
@lessCache.cssForFile(lessStylesheetPath, [baseVarImports, less].join('\n'))
|
||||
else
|
||||
@lessCache.read(lessStylesheetPath)
|
||||
|
Loading…
Reference in New Issue
Block a user