Verified Commit af58886d authored by Aral Balkan's avatar Aral Balkan
Browse files

Remove data generation for app

We are no longer generating/using separate data for the app. The blocker list file is generated for the site and used by the app from there.
parent b96d0b44
......@@ -100,7 +100,6 @@ class App
@cacheDirectory = path.join @privateDirectory, 'cache'
@rulePartialsDirectory = path.join @cacheDirectory, 'rule-partials'
@dataForSiteCacheDirectory = path.join @cacheDirectory, 'data', 'site'
@dataForAppCacheDirectory = path.join @cacheDirectory, 'data', 'app'
@indicesDirectory = path.join @cacheDirectory, 'indices'
fs.ensureDirSync @indicesDirectory
......@@ -129,7 +128,6 @@ class App
@dataDirectory = path.join @homeDirectory, 'data'
@dataForSiteDirectory = path.join @homeDirectory, 'data', 'site'
@dataForAppDirectory = path.join @homeDirectory, 'data', 'app'
# Theme source directories.
@themesDirectory = path.join @homeDirectory, 'themes'
......
......@@ -76,9 +76,6 @@ class Blockdown
rendering: null
theme: null
isRenderingDataForSite: false
isRenderingDataForApp: false
#
# Cache-related.
#
......@@ -184,9 +181,6 @@ class Blockdown
renderDataForSite: =>
# @log.debug "Rendering data for site."
@isRenderingDataForSite = true
@isRenderingDataForApp = false
@theme = app.siteTheme
@rendering = @site
......@@ -246,65 +240,6 @@ class Blockdown
.catch (e) =>
throw new Error "[Blockdown: site data] #{e} #{e.stack}"
#
# Render data for apps.
#
renderDataForApp: =>
# @log.debug "Rendering data for apps."
@isRenderingDataForSite = false
@isRenderingDataForApp = true
@rendering = @app
@theme = app.appTheme
# Reset the rules
@rules = []
# Reset the global statistics for the app render.
GlobalStatistics.reset()
#
# TODO: Need a separate pass to create the indices as they
# will include folders as well as the content files.
#
# This could be done at the end, on the data folder.
#
indices = {}
Promise.try =>
# Clean the data directory before starting only if we’re not using the cache.
if @useContentCache
# @log.info "Using cache: returning true from Promise.try"
return true
else
# @log.info "Not using cache: returning promise to delete the data for app directory from Promise.try"
return fs.removeAsync "#{app.dataForAppDirectory}/*"
.then =>
@renderBlockdown app.contentDirectory, app.dataForAppDirectory, app.appTheme
.then (indices) =>
@saveBlockerListJSON app.dataForAppDirectory
.then =>
Promise.try =>
if @useContentCache and @contentHasNotChanged
return
else
@copyAssets @contentAssets('app'), app.dataForAppDirectory
.then =>
Promise.try =>
if @useContentCache and app.themeHasNotChanged
console.log "\t✓ Theme has not changed, not copying theme assets for app."
return
else
console.log "\t✓ Copying theme assets for app."
@copyAssets @themeForAppDataAssets(), app.dataForAppDirectory
.then =>
Promise.try =>
if @useContentCache
@removeDeletedFiles()
.catch (e) =>
throw new Error "[Blockdown: app data] #{e} #{e.stack}"
#
# Private methods.
#
......@@ -411,7 +346,7 @@ class Blockdown
console.log "\t✓ Source file #{file} was deleted; removing from build."
# Set the base of the path of the item to delete
pathToDelete = if @isRenderingDataForApp then app.dataForAppDirectory else app.dataForSiteDirectory
pathToDelete = app.dataForSiteDirectory
if @endsWith file, 'index.md'
#
......@@ -447,10 +382,6 @@ class Blockdown
indices = {}
titleOfPage = ''
# TODO: Refactor so we do not have to check for site/app render here.
isRenderingDataForApp = theme is app.appTheme
isRenderingDataForSite = !isRenderingDataForApp
# Used to hold the index pages of the various categories.
indexContent =
spotlight: {}
......@@ -547,7 +478,7 @@ class Blockdown
# (i.e., content pages)
#
if isRenderingDataForSite and category isnt 'none' and pageDomain isnt 'none'
if category isnt 'none' and pageDomain isnt 'none'
actionsBlock = """
## About Better
......@@ -604,18 +535,10 @@ Better is a Safari content blocker for <a href='https://itunes.apple.com/us/app/
fs.outputJSONSync indexCacheFile, indexCacheObject
#
# Apply data theme specialisations…
#
# (Note: the app-specific specialisations that were here have now been moved to the iOS App.)
if isRenderingDataForSite
#
# Is rendering data for site
#
# Strip the markdown from the title for the site (keep it for the app
# as we use it to intelligently truncate the title displayed in the navitation bar).
# Only valid markup for headings is strong and emphasized, so just strips the *s.
titleOfPage = "#{titleOfPageClean} | Better"
# Strip the markdown from the title for the site (keep it for the app
# as we use it to intelligently truncate the title displayed in the navitation bar).
# Only valid markup for headings is strong and emphasized, so just strips the *s.
titleOfPage = "#{titleOfPageClean} | Better"
marked.setOptions
renderer: @blockdownRenderer
......@@ -709,16 +632,14 @@ Better is a Safari content blocker for <a href='https://itunes.apple.com/us/app/
# Only render pages from themes if the theme has changed
Promise.try =>
if !@useContentCache
if isRenderingDataForSite
# Render /reviews index.
@renderPage 'reviews', dataPath, '/reviews/index.html', {}, 'reviews'
# Render /reviews index.
@renderPage 'reviews', dataPath, '/reviews/index.html', {}, 'reviews'
.then =>
# Only render pages from themes if the theme has changed
Promise.try =>
if !@useContentCache
if isRenderingDataForSite
# Render /support index.
@renderPage 'support', dataPath, '/support/index.html', {}, 'support'
# Render /support index.
@renderPage 'support', dataPath, '/support/index.html', {}, 'support'
.then =>
# Only render pages from themes if the theme has changed
Promise.try =>
......@@ -753,9 +674,7 @@ Better is a Safari content blocker for <a href='https://itunes.apple.com/us/app/
title = name[0].toUpperCase() + name.slice(1) # title is the name with the first letter capitalised.
if @isRenderingDataForSite
title += ' | Better'
title += ' | Better'
pageHTML = set.render(@theme.page, {title: title, header: headerPartialHTML, content: contentPartialHTML, category: category})
pagePath = path.join dataPath, pathFragment
......@@ -972,28 +891,6 @@ Better is a Safari content blocker for <a href='https://itunes.apple.com/us/app/
fs.outputFileAsync indexHTMLFilePath, indexHTML
#
# Create the index JSON files for the app data.
# UNUSED. TODO: Refactor or remove.
#
createIndexFilesForAppData: (indices) =>
directoryPaths = Object.keys indices
Promise.series directoryPaths, (directoryPath) =>
fileNames = indices[directoryPath]
indexJSONFilePath = path.join app.dataForAppDirectory, directoryPath, 'index.json'
# Generate the index.json for the app.
indexJSON = JSON.stringify {files: fileNames}
# Save the JSON index file.
fs.outputFileAsync indexJSONFilePath, indexJSON
#
# Hook into the marked Markdown renderer for the Blockdown MSON code sections.
#
......
......@@ -138,20 +138,17 @@ class Builder
blockdown.renderDataForSite()
.then =>
@log.info "\t✓ Rendered content for site."
blockdown.renderDataForApp()
easyListConverter.convert()
.then =>
@log.info "\t✓ Rendered content for data."
easyListConverter.convert()
.then =>
@log.info "\t✓ Rendered EasyList version."
duration = ((new Date) - startTime)
durationUnit = "ms"
if duration > 1000
duration = duration / 1000
durationUnit = "seconds"
@log.info "\t✓ Rendered EasyList version."
duration = ((new Date) - startTime)
durationUnit = "ms"
if duration > 1000
duration = duration / 1000
durationUnit = "seconds"
@log.info "\t✓ Render complete. (#{duration} #{durationUnit})"
@log.info "\t✓ Render complete. (#{duration} #{durationUnit})"
#
......@@ -204,9 +201,7 @@ class Builder
@updateRepository app.dataForSiteDirectory
.then =>
@updateRepository app.dataForAppDirectory
.then =>
@log.info "\t✓ Data repository updates complete."
@log.info "\t✓ Data repository update for site complete."
#
......
......@@ -40,7 +40,7 @@ class WebkitContentBlockerRulesToBindDNS
constructor: ->
@domainPrefixRegex = '^[^:]+://+([^:/]+\\.)?'
@blockerListPath = path.join app.dataForAppDirectory, 'blockerList.json'
@blockerListPath = path.join app.dataForSiteDirectory, 'blockerList.json'
@bindDNSSiteOutputPath = path.join app.dataForSiteDirectory, 'db.dns.indie'
# Set up logging.
......
......@@ -34,7 +34,7 @@ class WebkitContentBlockerRulesToEasyList
constructor: ->
@domainPrefixRegex = '^[^:]+://+([^:/]+\\.)?'
@blockerListPath = path.join app.dataForAppDirectory, 'blockerList.json'
@blockerListPath = path.join app.dataForSiteDirectory, 'blockerList.json'
@easyListSiteOutputPath = path.join app.dataForSiteDirectory, 'blockerList.txt'
# Set up logging.
......
......@@ -255,11 +255,9 @@ configureLocalEnvironment(){
# Set up output repositories.
#
# Create two bare repositories to act as remotes for the data generated by the builder
# (The builder generates separate data for the site and one for the apps.)
# Create a bare repository to act as the remote for the site data generated by the builder.
setUpGeneratedRepository site
setUpGeneratedRepository app
#
# Make symbolic links from the main directory for easy access.
......@@ -275,20 +273,6 @@ configureLocalEnvironment(){
if ! [ -d ../trackers ]; then ln -s ~/better.fyi/content/trackers ../trackers; fi
if ! [ -d ../sites ]; then ln -s ~/better.fyi/content/sites ../sites; fi
#
# For the data/app repository, add the live remotes that are used by the
# iOS app. The working directory is copied into iOS app builds
# so that an Internet connection is not required to get started with it.
# (Also, disable pushes to live so we don’t accicentally deploy this generated repo.)
#
dataForAppDirectory="${ROOT}/data/app"
# TODO: Get these URLs from the installation script – write them out to the config.
runIn $dataForAppDirectory "git remote add live https://data.better.fyi/generated/app.git"
runIn $dataForAppDirectory "git remote add development http://localhost:8889/app.git"
runIn $dataForAppDirectory "git remote set-url --push live no_push"
runIn $dataForAppDirectory "git remote set-url --push development no_push"
siteLocalPath="${privateFolder}/site-local"
if [ -d $siteLocalPath ]; then
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment