Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build frontend with webpack #149

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions .gitmodules

This file was deleted.

16 changes: 6 additions & 10 deletions frontend/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
/**
Define your enyo/Application kind in this file.
*/
import kind from 'enyo/kind';
import Application from 'enyo/Application';

var
kind = require('enyo/kind'),
Application = require('enyo/Application'),
MainView = require('./views/MainView');
import MainView from './views/MainView';

module.exports = kind({
kind: Application,
view: MainView
export default kind({
kind: Application,
view: MainView,
});
29 changes: 12 additions & 17 deletions frontend/baseurl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// https://www.ietf.org/rfc/rfc3986.txt - page 50
function parseURL(url) {
var re = new RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?");
var res = url.match(re);
export function parseURL(url) {
const re = new RegExp('^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?');
const res = url.match(re);

return {
scheme: res[2],
authority: res[4],
Expand All @@ -15,21 +16,21 @@ function parseURL(url) {
* Resolve URL url based off URL base (equivalent API to nodejs url.resolve with
* arguments flipped)
*/
function resolveURL(url, base) {
var p1 = parseURL(url);
var p2 = parseURL(base);
export function resolveURL(url, base) {
const p1 = parseURL(url);
const p2 = parseURL(base);

if (p1.scheme) return url;

if (p1.path.indexOf('/') == 0) {
return p2.scheme + '://' + p2.authority + p1.path + (p1.query ? '?' + p1.query : '');
if (p1.path.startsWith('/')) {
return `${p2.scheme}://${p2.authority}${p1.path}${p1.query ? `?${p1.query}` : ''}`;
} else {
var b = (p2.path.lastIndexOf('/') != -1) ? p2.path.substring(0, p2.path.lastIndexOf('/')) : p2.path;
return p2.scheme + '://' + p2.authority + b + '/' + p1.path + (p1.query ? '?' + p1.query : '');
const b = p2.path.lastIndexOf('/') != -1 ? p2.path.substring(0, p2.path.lastIndexOf('/')) : p2.path;
return `${p2.scheme}://${p2.authority}${b}/${p1.path}${p1.query ? '?' + p1.query : ''}`;
}
}

function test() {
export function test() {
// Some quick testcases...
var testCases = [
['test', 'https://google.com', 'https://google.com/test'],
Expand All @@ -55,9 +56,3 @@ function test() {
console.info(t[0], t[1], res, res == t[2]);
});
}

module.exports = {
parseURL: parseURL,
resolveURL: resolveURL,
test: test,
};
20 changes: 20 additions & 0 deletions frontend/chore/MoonstoneResolverPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { NormalModuleReplacementPlugin, type ResolveData } from 'webpack';

/**
* The plugin resolves Moonstone packages with non-standard 'moduleDir' property.
*/
export class MoonstoneResolverPlugin extends NormalModuleReplacementPlugin {
public constructor() {
super(/^(?:enyo(?:-ilib|-webos)?|layout|moonstone)/, MoonstoneResolverPlugin.resolve);
}

private static resolve(resource: ResolveData) {
const [name, ...path] = resource.request.split('/');

if (path.length > 0) {
const { moduleDir: root } = require(`${name}/package.json`);

resource.request = [name, root, ...path].join('/');
}
}
}
51 changes: 24 additions & 27 deletions frontend/configutils.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,47 @@
var repositoryBaseURL = 'https://repo.webosbrew.org/api/apps.json';
var repositoryNonfreeBaseURL = 'https://repo.webosbrew.org/api/non-free/apps.json';
export const repositoryBaseURL = 'https://repo.webosbrew.org/api/apps.json';
export const repositoryNonfreeBaseURL = 'https://repo.webosbrew.org/api/non-free/apps.json';

function getConfig() {
var repositoriesConfig = {
export function getConfig() {
const repositoriesConfig = {
repositories: [],
disableDefault: false,
enableNonfree: false,
};

try {
var parsed = JSON.parse(window.localStorage['repositoriesConfig']);
if (parsed.disableDefault !== undefined)
repositoriesConfig.disableDefault = parsed.disableDefault;
if (parsed.repositories !== undefined)
repositoriesConfig.repositories = parsed.repositories;
if (parsed.enableNonfree !== undefined)
repositoriesConfig.enableNonfree = parsed.enableNonfree;
const parsed = JSON.parse(window.localStorage.getItem('repositoriesConfig'));

Object.assign(repositoriesConfig, parsed);
} catch (err) {
console.warn('Config load failed:', err);
}

return repositoriesConfig;
}

function getRepositories() {
export function getRepositories() {
try {
var repositoriesConfig = getConfig();
var repos = repositoriesConfig.repositories.map(function (repo) { return repo.url; });
if (!repositoriesConfig.disableDefault) repos.push(repositoryBaseURL);
if (repositoriesConfig.enableNonfree) repos.push(repositoryNonfreeBaseURL);
return repos;
const { repositories, disableDefault, enableNonfree } = getConfig();

const urls = repositories.map(({ url }) => url);

if (!disableDefault) {
urls.push(repositoryBaseURL);
}

if (enableNonfree) {
urls.push(repositoryNonfreeBaseURL);
}

return urls;
} catch (err) {
console.warn(err);

return [repositoryBaseURL];
}
}

function setConfig(config) {
window.localStorage['repositoriesConfig'] = JSON.stringify(config);
export function setConfig(config) {
window.localStorage.setItem('repositoriesConfig', JSON.stringify(config));
console.info(window.localStorage['repositoriesConfig']);
}

module.exports = {
repositoryBaseURL: repositoryBaseURL,

getRepositories: getRepositories,
getConfig: getConfig,
setConfig: setConfig,
};
15 changes: 3 additions & 12 deletions frontend/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
/**
Instantiate your enyo/Application kind in this file. Note, application
rendering should be deferred until the DOM is ready by wrapping it in a
call to ready().
*/
import ready from 'enyo/ready';
import App from './App';

var
ready = require('enyo/ready'),
App = require('./App');

ready(function () {
new App();
});
ready(() => new App());
Loading
Loading