Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

Server side render styled components #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ npm-debug.log
# code coverage
coverage

# build
lib

# tests results
**/__tests__/_output*

Expand Down
22 changes: 22 additions & 0 deletions lib/Link/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Link = undefined;

var _chalk = require("chalk");

var _chalk2 = _interopRequireDefault(_chalk);

var _Link = require("../components/Link");

var _Link2 = _interopRequireDefault(_Link);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// deprecated
console.log("⚠️ " + _chalk2.default.yellow("'phenomic/lib/Link' reference is deprecated.\n" + "Please use `import { Link } from \"phenomic\" instead`."));

exports.Link = _Link2.default;
exports.default = _Link2.default;
20 changes: 20 additions & 0 deletions lib/PageContainer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

var _chalk = require("chalk");

var _chalk2 = _interopRequireDefault(_chalk);

var _PageContainer = require("../components/PageContainer");

var _PageContainer2 = _interopRequireDefault(_PageContainer);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// deprecated
console.log("⚠️ " + _chalk2.default.yellow("'phenomic/lib/PageContainer' reference is deprecated.\n" + "Please use `import { PageContainer } from \"phenomic\" instead`."));

exports.default = _PageContainer2.default;
15 changes: 15 additions & 0 deletions lib/_utils/array-unique/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

// @ flow
// flow is not enabled because of the issue with set and spread
// https://github.com/facebook/flow/issues/1059

exports.default = function (array) {
return [].concat(_toConsumableArray(new Set(array)));
};
13 changes: 13 additions & 0 deletions lib/_utils/beautify-html/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _jsBeautify = require("js-beautify");

exports.default = function (html) {
return (0, _jsBeautify.html)(html, _extends({}, _jsBeautify.default_options, { indent_size: 2 }));
};
13 changes: 13 additions & 0 deletions lib/_utils/bins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";

// ⚠️ Used in postinstall, so es6 - imports - not transpiled

var resolve = require("path").resolve;

var platformSuffix = process.platform === "win32" ? ".cmd" : "";

module.exports = {
babelNode: resolve("./node_modules/.bin/babel-node" + platformSuffix),
npm: "npm" + platformSuffix,
yarn: "yarn" + platformSuffix
};
43 changes: 43 additions & 0 deletions lib/_utils/cache/webpack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

var _path = require("path");

var _hardSourceWebpackPlugin = require("hard-source-webpack-plugin");

var _hardSourceWebpackPlugin2 = _interopRequireDefault(_hardSourceWebpackPlugin);

var _nodeObjectHash = require("node-object-hash");

var _nodeObjectHash2 = _interopRequireDefault(_nodeObjectHash);

var _findCacheDir = require("find-cache-dir");

var _findCacheDir2 = _interopRequireDefault(_findCacheDir);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.default = function (config) {
if (!config.cache) {
return [];
}

var cacheDir = (0, _findCacheDir2.default)({
name: "phenomic/webpack-hard-source-cache/[confighash]/"
});

return [new _hardSourceWebpackPlugin2.default({
cacheDirectory: (0, _path.join)(cacheDir),
recordsPath: (0, _path.join)(cacheDir, "records.json"),
configHash: function configHash(config) {
return new _nodeObjectHash2.default().hash(config);
},
environmentPaths: {
root: config.cwd,
files: ["package.json", "webpack.config.js"]
}
})];
};
63 changes: 63 additions & 0 deletions lib/_utils/catch-links/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (elements, cb) {
var eventCallback = catchLinks(cb);
elements.map(function (el) {
return el.addEventListener("click", eventCallback);
});

return function () {
elements.map(function (el) {
return el.removeEventListener("click", eventCallback);
});
};
};

var _url = require("url");

var _url2 = _interopRequireDefault(_url);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var catchLinks = function catchLinks(cb) {
return function (ev) {
if (ev.altKey || ev.ctrlKey || ev.metaKey || ev.shiftKey || ev.defaultPrevented) {
return;
}

var anchor = null;
for (var n = ev.target; n.parentNode; n = n.parentNode) {
if (n.nodeName === "A") {
anchor = n;
break;
}
}
if (!anchor) {
return;
}
var href = anchor.getAttribute("href");

// Don't intercerpt anchor
if (!href || href.startsWith("#")) {
return;
}

var u = _url2.default.parse(href);

if (u.host && u.host !== window.location.host) {
return;
}

var finalUrl = _url2.default.resolve(window.location.pathname, u.path || "") + (u.hash || "");

if (!cb(finalUrl)) {
return;
}

ev.preventDefault();
};
};
71 changes: 71 additions & 0 deletions lib/_utils/error-formatter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.help = exports.cwd = undefined;

var _os = require("os");

var _os2 = _interopRequireDefault(_os);

var _path = require("path");

var _path2 = _interopRequireDefault(_path);

var _chalk = require("chalk");

var _chalk2 = _interopRequireDefault(_chalk);

var _multili = require("multili");

var _multili2 = _interopRequireDefault(_multili);

var _configNode = require("../../builder/webpack/config.node.js");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var normalizeWinPath = function normalizeWinPath(path) {
return path.replace(/\\/g, "\\\\");
};

var cwd = exports.cwd = normalizeWinPath(process.cwd());
var cache = normalizeWinPath(_configNode.cacheDir);

var reSep = normalizeWinPath(_path2.default.sep);
var webpackNodeModulesRE = new RegExp("webpack:" + reSep + reSep + "?~", "gm");
var cleanStaticBuildPathRE = new RegExp(cache + reSep, "gm");
var cwdRE = new RegExp(cwd + reSep, "g");
var homeRE = new RegExp(_os2.default.homedir(), "g");

var cleanPaths = function cleanPaths(string) {
return string
// normalize windows path
.replace(/\\+g/, "/")
// cleanup
.replace(cleanStaticBuildPathRE, "").replace(webpackNodeModulesRE, "node_modules").replace(cwdRE, "").replace(homeRE, "~");
};

var notDefinedRE = /\s+(.*)( is not defined.*)/gm;
var help = exports.help = _chalk2.default.yellow("\n\n" + "If you are seeing this message during the static build, that means you are" + "probably using an API only available in the browser (such as 'window', " + "'document', 'Element'...). Note that a module can be responsible for this." + "\n" + "In order to prevent this error, you can simply avoid calling the code " + "responsible when the dependency is not available. " + "\n\n" + "Examples:\n" +
/* eslint-disable max-len */
(0, _multili2.default)("\nFor a single API:\n\n const element = (typeof document !== \"undefined\") ? document.querySelector(\".something\") : null\n\n if (element) {\n // do your thing with your element\n }\n\nFor a module:\n\n const clipboard = (typeof window !== \"undefined\") ? require(\"clipboard\") : null\n\n // then later\n\n if (clipboard) {\n // do your thing using the module\n }\n ")
/* eslint-enable max-len */
);
var enhanceError = function enhanceError(error) {
if (error.message.match(notDefinedRE) || error.stack.match(notDefinedRE)) {
error.stack += help;
}
};

exports.default = function (error) {
error.message = "\n\n" + _chalk2.default.red(error.message) + "\n";

// sometimes paths are in message
// eg: errors thrown by webpack loaders/plugin
error.message = cleanPaths(error.message);
error.stack = cleanPaths(error.stack);
enhanceError(error);

return error;
};
30 changes: 30 additions & 0 deletions lib/_utils/jsdom/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (url) {
global.document = _jsdom2.default.jsdom("<!doctype html><html><body><div id=\"app\"></div></body></html>", {
url: url
});
global.window = document.defaultView;
global.navigator = window.navigator;
window.localStorage = window.sessionStorage = {
getItem: function getItem(key) {
return this[key];
},
setItem: function setItem(key, value) {
this[key] = value;
},
removeItem: function removeItem(key) {
delete this[key];
}
};
};

var _jsdom = require("jsdom");

var _jsdom2 = _interopRequireDefault(_jsdom);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
Loading