Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nd-demos into history
  • Loading branch information
christopher-johnson committed Dec 13, 2018
2 parents 694885b + 20436d4 commit 5d692a0
Show file tree
Hide file tree
Showing 32 changed files with 12,393 additions and 8,911 deletions.
2 changes: 1 addition & 1 deletion minimal_redux_poc/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["env", "react"]
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
4 changes: 2 additions & 2 deletions minimal_redux_poc/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m3core.umd.js
mirador.min.js
dist/
config/
6 changes: 4 additions & 2 deletions minimal_redux_poc/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
"env": {
"jest/globals": true
},
"extends": "airbnb",
"extends": ["airbnb","react-app"],
"globals": {
"page": true,
"document": true
},
"parser": "babel-eslint",
"plugins": ["jest"],
"rules": {
"no-console": "off",
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true,
"ArrowFunctionExpression": true,
"FunctionExpression": true,
"FunctionExpression": true
}
}],
"react/prefer-stateless-function": "off"
Expand Down
4 changes: 2 additions & 2 deletions minimal_redux_poc/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
m3core.umd.js
dist/

dist/mirador.min.js
.idea
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* global miradorInstance */

describe('Config updating from instance', () => {
beforeAll(async () => {
await page.goto('http://127.0.0.1:4488/__tests__/integration/mirador/');
});
it('can modify the config via api', async () => {
await page.evaluate(() => {
const a = miradorInstance.actions.updateConfig({ foo: 'bat' });
miradorInstance.store.dispatch(a);
});
const config = await page.evaluate(() => (
miradorInstance.store.getState().config
));
await expect(config.foo).toBe('bat');
});
});
2 changes: 1 addition & 1 deletion minimal_redux_poc/__tests__/integration/mirador/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div id="mirador"></div>
<script>document.write("<script type='text/javascript' src='../../../dist/mirador.min.js?v=" + Date.now() + "'><\/script>");</script>
<script type="text/javascript">
Mirador({
var miradorInstance = Mirador({
id: 'mirador',
plugins: ['HelloWorld']
});
Expand Down
98 changes: 98 additions & 0 deletions minimal_redux_poc/config/paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
const path = require('path');
const fs = require('fs');
const url = require('url');

// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebook/create-react-app/issues/637
const appDirectory = fs.realpathSync(process.cwd());

/**
*
* @param relativePath
* @returns {string}
*/
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);

const envPublicUrl = process.env.PUBLIC_URL;

/**
*
* @param inputPath
* @param needsSlash
* @returns {*}
*/
function ensureSlash(inputPath, needsSlash) {
const hasSlash = inputPath.endsWith('/');
if (hasSlash && !needsSlash) {
return inputPath.substr(0, inputPath.length - 1);
} else if (!hasSlash && needsSlash) {
return `${inputPath}/`;
} else {
return inputPath;
}
}

/**
*
* @param appPackageJson
* @returns {string | *}
*/
const getPublicUrl = appPackageJson => envPublicUrl || require(appPackageJson).homepage;

/**
*
* @param appPackageJson
* @returns {*}
*/
function getServedPath(appPackageJson) {
const publicUrl = getPublicUrl(appPackageJson);
const servedUrl =
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
return ensureSlash(servedUrl, true);
}

const moduleFileExtensions = [
'web.mjs',
'mjs',
'web.js',
'js',
'web.ts',
'ts',
'web.tsx',
'tsx',
'json',
'web.jsx',
'jsx',
];

/**
*
* @param resolveFn
* @param filePath
* @returns {*}
*/
const resolveModule = (resolveFn, filePath) => {
const extension = moduleFileExtensions.find(extension => fs.existsSync(resolveFn(`${filePath}.${extension}`)));

if (extension) {
return resolveFn(`${filePath}.${extension}`);
}

return resolveFn(`${filePath}.js`);
};

module.exports = {
dotenv: resolveApp('.env'),
appPath: resolveApp('.'),
appBuild: resolveApp('build'),
appDist: resolveApp('dist'),
appIndexJs: resolveModule(resolveApp, 'src/index'),
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
testsSetup: resolveModule(resolveApp, 'src/setupTests'),
appNodeModules: resolveApp('node_modules'),
publicUrl: getPublicUrl(resolveApp('package.json')),
servedPath: getServedPath(resolveApp('package.json')),
};

module.exports.moduleFileExtensions = moduleFileExtensions;
Loading

0 comments on commit 5d692a0

Please sign in to comment.