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