-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1656 from briandipalma/feat/inline-app-meta-require
refactor: Inline app-metadata require
- Loading branch information
Showing
18 changed files
with
199 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 0 additions & 110 deletions
110
...ins/src/main/java/org/bladerunnerjs/plugin/bundlers/appmeta/AppMetadataContentPlugin.java
This file was deleted.
Oops, something went wrong.
134 changes: 134 additions & 0 deletions
134
...ugins/src/main/java/org/bladerunnerjs/plugin/plugins/require/AppMetaDataSourceModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package org.bladerunnerjs.plugin.plugins.require; | ||
|
||
import java.io.IOException; | ||
import java.io.Reader; | ||
import java.io.StringReader; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.bladerunnerjs.api.App; | ||
import org.bladerunnerjs.api.Asset; | ||
import org.bladerunnerjs.api.BRJS; | ||
import org.bladerunnerjs.api.BundlableNode; | ||
import org.bladerunnerjs.api.memoization.MemoizedFile; | ||
import org.bladerunnerjs.api.model.exception.ConfigException; | ||
import org.bladerunnerjs.api.model.exception.ModelOperationException; | ||
import org.bladerunnerjs.model.AssetContainer; | ||
import org.bladerunnerjs.plugin.bundlers.commonjs.CommonJsSourceModule; | ||
import org.bladerunnerjs.utility.AppMetadataUtility; | ||
|
||
import com.google.common.base.Joiner; | ||
|
||
public class AppMetaDataSourceModule implements CommonJsSourceModule | ||
{ | ||
|
||
public static final String PRIMARY_REQUIRE_PATH = "app-meta!$app-metadata"; | ||
private BRJS brjs; | ||
private BundlableNode bundlableNode; | ||
|
||
public AppMetaDataSourceModule(BRJS brjs, BundlableNode bundlableNode) { | ||
this.brjs = brjs; | ||
this.bundlableNode = bundlableNode; | ||
} | ||
|
||
@Override | ||
public boolean isEncapsulatedModule() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isGlobalisedModule() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public List<Asset> getPreExportDefineTimeDependentAssets(BundlableNode bundlableNode) | ||
throws ModelOperationException { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public List<Asset> getPostExportDefineTimeDependentAssets(BundlableNode bundlableNode) | ||
throws ModelOperationException { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public List<Asset> getUseTimeDependentAssets(BundlableNode bundlableNode) throws ModelOperationException { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public List<Asset> getDependentAssets(BundlableNode bundlableNode) throws ModelOperationException { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public void addImplicitDependencies(List<Asset> implicitDependencies) { | ||
} | ||
|
||
@Override | ||
public Reader getReader() throws IOException { | ||
try { | ||
App app = bundlableNode.app(); | ||
String appLocales = Joiner.on("':true, '").join(app.appConf().getLocales()); | ||
String localCookieName = app.appConf().getLocaleCookieName(); | ||
String version = brjs.root().getAppVersionGenerator().getVersion(); | ||
String bundlePath = AppMetadataUtility.getRelativeVersionedBundlePath(app, version, ""); | ||
|
||
return new StringReader( | ||
String.format(COMMONJS_DEFINE_BLOCK_HEADER, getPrimaryRequirePath()) + "\n" + | ||
"// these variables should not be used directly but accessed via the 'br.app-meta-service' instead\n" + | ||
"module.exports.APP_VERSION = '" + version + "';\n" + | ||
"module.exports.VERSIONED_BUNDLE_PATH = '" + bundlePath + "';\n" + | ||
"module.exports.LOCALE_COOKIE_NAME = '" + localCookieName + "';\n" + | ||
"module.exports.APP_LOCALES = {'" + appLocales + "':true};" + | ||
COMMONJS_DEFINE_BLOCK_FOOTER | ||
); | ||
} catch (ConfigException e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public MemoizedFile file() { | ||
return bundlableNode.dir(); | ||
} | ||
|
||
@Override | ||
public String getAssetName() { | ||
return getPrimaryRequirePath(); | ||
} | ||
|
||
@Override | ||
public String getAssetPath() { | ||
return getPrimaryRequirePath(); | ||
} | ||
|
||
@Override | ||
public List<String> getRequirePaths() { | ||
return Arrays.asList(getPrimaryRequirePath()); | ||
} | ||
|
||
@Override | ||
public String getPrimaryRequirePath() { | ||
return PRIMARY_REQUIRE_PATH; | ||
} | ||
|
||
@Override | ||
public AssetContainer assetContainer() { | ||
return bundlableNode; | ||
} | ||
|
||
@Override | ||
public boolean isScopeEnforced() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isRequirable() { | ||
return true; | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...brjs-plugins/src/main/java/org/bladerunnerjs/plugin/require/AppMetaDataRequirePlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.bladerunnerjs.plugin.require; | ||
|
||
import org.bladerunnerjs.api.Asset; | ||
import org.bladerunnerjs.api.BRJS; | ||
import org.bladerunnerjs.api.BundlableNode; | ||
import org.bladerunnerjs.api.model.exception.RequirePathException; | ||
import org.bladerunnerjs.api.plugin.RequirePlugin; | ||
import org.bladerunnerjs.api.plugin.base.AbstractRequirePlugin; | ||
import org.bladerunnerjs.plugin.plugins.require.AppMetaDataSourceModule; | ||
|
||
public class AppMetaDataRequirePlugin extends AbstractRequirePlugin implements RequirePlugin | ||
{ | ||
|
||
private BRJS brjs; | ||
private RequirePlugin defaultRequirePlugin; | ||
|
||
@Override | ||
public void setBRJS(BRJS brjs) { | ||
this.brjs = brjs; | ||
this.defaultRequirePlugin = brjs.plugins().requirePlugin("default"); | ||
} | ||
|
||
@Override | ||
public String getPluginName() { | ||
return "app-meta"; | ||
} | ||
|
||
@Override | ||
public Asset getAsset(BundlableNode bundlableNode, String requirePathSuffix) throws RequirePathException { | ||
String requirePath = getPluginName() + "!" + requirePathSuffix; | ||
|
||
if (requirePath.equals(AppMetaDataSourceModule.PRIMARY_REQUIRE_PATH)) { | ||
return new AppMetaDataSourceModule(brjs, bundlableNode); | ||
} | ||
|
||
return defaultRequirePlugin.getAsset(bundlableNode, requirePath); | ||
} | ||
|
||
} |
Oops, something went wrong.