fix build, migrate test backend

This commit is contained in:
Shawn Erquhart 2018-07-17 18:09:59 -04:00
parent 2e7406862e
commit 040dd6859c
26 changed files with 174 additions and 82 deletions

View File

@ -16,9 +16,10 @@
],
"pre-commit": "lint:staged",
"scripts": {
"start": "lerna run --parallel watch",
"clean": "cd packages && rimraf */.cache */*.js */*.css */*.svg */*.map",
"reset": "yarn clean && lerna clean --yes && lerna bootstrap && cd packages/netlify-cms-core && yarn link netlify-cms-lib-auth netlify-cms-lib-util netlify-cms-ui-default netlify-cms-editor-component-image"
"bootstrap": "lerna bootstrap && lerna link --force-local",
"start": "yarn bootstrap && yarn watch",
"watch": "lerna run watch --parallel",
"clean": "cd packages && rimraf */.cache */*.js */*.css */*.svg */*.map"
},
"jest": {
"moduleNameMapper": {

View File

@ -0,0 +1,30 @@
{
"name": "netlify-cms-backend-github",
"description": "GitHub backend for Netlify CMS",
"version": "2.0.0-alpha.0",
"license": "MIT",
"keywords": [
"netlify",
"netlify-cms",
"backend",
"github"
],
"scripts": {
"watch": "parcel watch src/*.js --out-dir . --no-cache",
"build": "parcel build src/*.js --out-dir . --no-cache"
},
"dependencies": {
"js-base64": "^2.4.8",
"lodash": "^4.17.10",
"netlify-cms-lib-auth": "file:../netlify-cms-lib-auth",
"netlify-cms-lib-util": "file:../netlify-cms-lib-util",
"netlify-cms-ui-default": "file:../netlify-cms-ui-default",
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react-emotion": "^9.2.6",
"semaphore": "^1.1.0"
},
"devDependencies": {
"parcel-bundler": "^1.9.4"
}
}

View File

@ -2,8 +2,6 @@ import localForage from "netlify-cms-lib-util/localForage";
import { Base64 } from "js-base64";
import { uniq, initial, last, get, find, hasIn, partial } from "lodash";
import { filterPromises, resolvePromiseProperties } from "netlify-cms-lib-util/promise";
import AssetProxy from "ValueObjects/AssetProxy";
import { SIMPLE, EDITORIAL_WORKFLOW, status } from "Constants/publishModes";
import APIError from "netlify-cms-lib-util/APIError";
import EditorialWorkflowError from "netlify-cms-lib-util/EditorialWorkflowError";
@ -17,6 +15,8 @@ export default class API {
this.repo = config.repo || "";
this.repoURL = `/repos/${ this.repo }`;
this.merge_method = config.squash_merges ? "squash" : "merge";
this.initialStatus = config.initialStatus;
}
user() {
@ -287,13 +287,13 @@ export default class API {
const fileTree = this.composeFileTree(files);
return Promise.all(uploadPromises).then(() => {
if (!options.mode || (options.mode && options.mode === SIMPLE)) {
if (!options.useWorkflow) {
return this.getBranch()
.then(branchData => this.updateTree(branchData.commit.sha, "/", fileTree))
.then(changeTree => this.commit(options.commitMessage, changeTree))
.then(response => this.patchBranch(this.branch, response.sha));
} else if (options.mode && options.mode === EDITORIAL_WORKFLOW) {
} else {
const mediaFilesList = mediaFiles.map(file => ({ path: file.path, sha: file.sha }));
return this.editorialWorkflowGit(fileTree, entry, mediaFilesList, options);
}
@ -347,7 +347,7 @@ export default class API {
head: prResponse.head && prResponse.head.sha,
},
user: user.name || user.login,
status: status.first(),
status: this.initialStatus,
branch: branchName,
collection: options.collectionName,
title: options.parsedData && options.parsedData.title,

View File

@ -1,7 +1,39 @@
import PropTypes from 'prop-types';
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'react-emotion';
import Authenticator from 'netlify-cms-lib-auth/netlify-auth';
import Icon from 'netlify-cms-ui-default/Icon';
import { buttons, shadows } from 'netlify-cms-ui-default/styles';
const StyledAuthenticationPage = styled.section`
display: flex;
flex-flow: column nowrap;
align-items: center;
justify-content: center;
height: 100vh;
`
const AuthenticationPageLogo = styled(Icon)`
color: #c4c6d2;
margin-top: -300px;
`
const LoginButton = styled.button`
${buttons.button};
${shadows.dropDeep};
${buttons.default};
${buttons.gray};
padding: 0 30px;
margin-top: -80px;
display: flex;
align-items: center;
position: relative;
${Icon} {
margin-right: 18px;
}
`
export default class AuthenticationPage extends React.Component {
static propTypes = {
@ -37,17 +69,13 @@ export default class AuthenticationPage extends React.Component {
const { inProgress } = this.props;
return (
<section className="nc-githubAuthenticationPage-root">
<Icon className="nc-githubAuthenticationPage-logo" size="500px" type="netlify-cms"/>
{loginError && <p>{loginError}</p>}
<button
className="nc-githubAuthenticationPage-button"
disabled={inProgress}
onClick={this.handleLogin}
>
<StyledAuthenticationPage>
<AuthenticationPageLogo size="500px" type="netlify-cms"/>
{loginError ? <p>{loginError}</p> : null}
<LoginButton disabled={inProgress} onClick={this.handleLogin}>
<Icon type="github" /> {inProgress ? "Logging in..." : "Login with GitHub"}
</button>
</section>
</LoginButton>
</StyledAuthenticationPage>
);
}
}

View File

@ -1,4 +1,3 @@
import AssetProxy from "ValueObjects/AssetProxy";
import API from "../API";
describe('github API', () => {

View File

@ -0,0 +1,30 @@
{
"name": "netlify-cms-backend-test",
"description": "Development testing backend for Netlify CMS",
"version": "2.0.0-alpha.0",
"license": "MIT",
"keywords": [
"netlify",
"netlify-cms",
"backend"
],
"scripts": {
"watch": "parcel watch src/*.js --out-dir . --no-cache",
"build": "parcel build src/*.js --out-dir . --no-cache"
},
"dependencies": {
"immutable": "^3.8.2",
"lodash": "^4.17.10",
"netlify": "^1.2.0",
"netlify-cms-lib-util": "file:../netlify-cms-lib-util",
"netlify-cms-ui-default": "file:../netlify-cms-ui-default",
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react-emotion": "^9.2.6",
"react-immutable-proptypes": "^2.1.0",
"uuid": "^3.3.2"
},
"devDependencies": {
"parcel-bundler": "^1.9.4"
}
}

View File

@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import React from 'react';
import Icon from 'netlify-cms-ui-default/Icon';
export default class AuthenticationPage extends React.Component {

View File

@ -1,9 +1,8 @@
import { fromJS } from 'immutable';
import { remove, attempt, isError, take } from 'lodash';
import uuid from 'uuid/v4';
import { fromJS } from 'immutable';
import { EDITORIAL_WORKFLOW, status } from 'Constants/publishModes';
import EditorialWorkflowError from 'netlify-cms-lib-util/EditorialWorkflowError';
import Cursor, { CURSOR_COMPATIBILITY_SYMBOL } from 'ValueObjects/Cursor'
import Cursor, { CURSOR_COMPATIBILITY_SYMBOL } from 'netlify-cms-lib-util/Cursor'
import AuthenticationPage from './AuthenticationPage';
window.repoFiles = window.repoFiles || {};
@ -47,6 +46,7 @@ export default class TestRepo {
constructor(config) {
this.config = config;
this.assets = [];
this.initialStatus = config.initialStatus;
}
authComponent() {
@ -135,7 +135,7 @@ export default class TestRepo {
}
persistEntry({ path, raw, slug }, mediaFiles = [], options = {}) {
if (options.mode === EDITORIAL_WORKFLOW) {
if (options.useWorkflow) {
const unpubStore = window.repoFilesUnpublished;
const existingEntryIndex = unpubStore.findIndex(e => e.file.path === path);
if (existingEntryIndex >= 0) {
@ -151,7 +151,7 @@ export default class TestRepo {
},
metaData: {
collection: options.collectionName,
status: status.first(),
status: this.initialStatus,
title: options.parsedData && options.parsedData.title,
description: options.parsedData && options.parsedData.description,
},

View File

@ -16,7 +16,7 @@
],
"scripts": {
"watch": "cross-env NETLIFY_CMS_VERSION=$npm_package_version parcel example/index.html --no-cache --open",
"build": "cross-env NETLIFY_CMS_VERSION=$npm_package_version parcel build example/index.html --no-cache"
"build": "cross-env NETLIFY_CMS_VERSION=$npm_package_version parcel build example/index.html --no-cache "
},
"keywords": [
"netlify",

View File

@ -6,7 +6,7 @@ import { getIntegrationProvider } from 'Integrations';
import { getAsset, selectIntegration } from 'Reducers';
import { selectFields } from 'Reducers/collections';
import { selectCollectionEntriesCursor } from 'Reducers/cursors';
import Cursor from 'ValueObjects/Cursor';
import Cursor from 'netlify-cms-lib-util/Cursor'
import { createEntry } from 'ValueObjects/Entry';
import ValidationErrorTypes from 'Constants/validationErrorTypes';
import isArray from 'lodash/isArray';

View File

@ -1,6 +1,8 @@
import { attempt, flatten, isError } from 'lodash';
import { fromJS, Map } from 'immutable';
import fuzzy from 'fuzzy';
import GitHubBackend from "netlify-cms-backend-github";
import TestRepoBackend from "netlify-cms-backend-test";
import { resolveFormat } from "Formats/formats";
import { selectIntegration } from 'Reducers/integrations';
import {
@ -15,13 +17,12 @@ import {
} from "Reducers/collections";
import { createEntry } from "ValueObjects/Entry";
import { sanitizeSlug } from "Lib/urlHelper";
import TestRepoBackend from "./test-repo/implementation";
import GitHubBackend from "./github/implementation";
import GitLabBackend from "./gitlab/implementation";
import BitBucketBackend from "./bitbucket/implementation";
import GitGatewayBackend from "./git-gateway/implementation";
import { registerBackend, getBackend } from 'Lib/registry';
import Cursor, { CURSOR_COMPATIBILITY_SYMBOL } from '../valueObjects/Cursor';
import Cursor, { CURSOR_COMPATIBILITY_SYMBOL } from 'netlify-cms-lib-util/Cursor'
import { EDITORIAL_WORKFLOW, status } from 'Constants/publishModes';
/**
* Register internal backends
@ -395,7 +396,7 @@ class Backend {
const commitMessage = commitMessageFormatter(newEntry ? 'create' : 'update', config, { collection, slug: entryObj.slug, path: entryObj.path });
const mode = config.get("publish_mode");
const useWorkflow = config.get("publish_mode") === EDITORIAL_WORKFLOW;
const collectionName = collection.get("name");
@ -404,7 +405,15 @@ class Backend {
*/
const hasAssetStore = integrations && !!selectIntegration(integrations, null, 'assetStore');
const updatedOptions = { ...options, hasAssetStore };
const opts = { newEntry, parsedData, commitMessage, collectionName, mode, ...updatedOptions };
const opts = {
newEntry,
parsedData,
commitMessage,
collectionName,
useWorkflow,
initialStatus: status.first(),
...updatedOptions
};
return this.implementation.persistEntry(entryObj, MediaFiles, opts)
.then(() => entryObj.slug);

View File

@ -1,4 +1,4 @@
import GithubAPI from "Backends/github/API";
import GithubAPI from "netlify-cms-backend-github/API";
import APIError from "netlify-cms-lib-util/APIError";
export default class API extends GithubAPI {

View File

@ -1,4 +1,4 @@
import GithubAPI from "Backends/github/API";
import GithubAPI from "netlify-cms-backend-github/API";
import APIError from "netlify-cms-lib-util/APIError";
export default class API extends GithubAPI {

View File

@ -2,8 +2,8 @@ import GoTrue from "gotrue-js";
import jwtDecode from 'jwt-decode';
import {List} from 'immutable';
import { get, pick, intersection } from "lodash";
import unsentRequest from "Lib/unsentRequest";
import GitHubBackend from "Backends/github/implementation";
import { unsentRequest } from "netlify-cms-lib-util";
import GitHubBackend from "netlify-cms-backend-github";
import GitLabBackend from "Backends/gitlab/implementation";
import BitBucketBackend from "Backends/bitbucket/implementation";
import GitHubAPI from "./GitHubAPI";

View File

@ -1,29 +0,0 @@
.nc-githubAuthenticationPage-root {
display: flex;
flex-flow: column nowrap;
align-items: center;
justify-content: center;
height: 100vh;
}
.nc-githubAuthenticationPage-logo {
color: #c4c6d2;
margin-top: -300px;
}
.nc-githubAuthenticationPage-button {
@apply(--button);
@apply(--dropShadowDeep);
@apply(--buttonDefault);
@apply(--buttonGray);
padding: 0 30px;
margin-top: -80px;
display: flex;
align-items: center;
position: relative;
& .nc-icon {
margin-right: 18px;
}
}

View File

@ -5,8 +5,8 @@ import { cond, flow, isString, partial, partialRight, pick, omit, set, update, g
import unsentRequest from "netlify-cms-lib-util/unsentRequest";
import { then } from "netlify-cms-lib-util/promise";
import APIError from "netlify-cms-lib-util/APIError";
import Cursor from 'netlify-cms-lib-util/Cursor'
import AssetProxy from "ValueObjects/AssetProxy";
import Cursor from "ValueObjects/Cursor"
export default class API {
constructor(config) {

View File

@ -1,8 +1,9 @@
import trimStart from 'lodash/trimStart';
import semaphore from "semaphore";
import { fileExtension } from 'netlify-cms-lib-util/path';
import Cursor, { CURSOR_COMPATIBILITY_SYMBOL } from 'netlify-cms-lib-util/Cursor'
import AuthenticationPage from "./AuthenticationPage";
import API from "./API";
import { CURSOR_COMPATIBILITY_SYMBOL } from 'ValueObjects/Cursor';
import { EDITORIAL_WORKFLOW } from "Constants/publishModes";
const MAX_CONCURRENT_DOWNLOADS = 10;

View File

@ -3,13 +3,13 @@ import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { connect } from 'react-redux';
import { partial } from 'lodash';
import Cursor from 'netlify-cms-lib-util/Cursor'
import {
loadEntries as actionLoadEntries,
traverseCollectionCursor as actionTraverseCollectionCursor,
} from 'Actions/entries';
import { selectEntries } from 'Reducers';
import { selectCollectionEntriesCursor } from 'Reducers/cursors';
import Cursor from 'ValueObjects/Cursor';
import Entries from './Entries';
class EntriesCollection extends React.Component {

View File

@ -2,12 +2,12 @@ import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { connect } from 'react-redux';
import Cursor from 'netlify-cms-lib-util/Cursor'
import { selectSearchedEntries } from 'Reducers';
import {
searchEntries as actionSearchEntries,
clearSearch as actionClearSearch
} from 'Actions/search';
import Cursor from 'ValueObjects/Cursor';
import Entries from './Entries';
class EntriesSearch extends React.Component {

View File

@ -4,9 +4,9 @@ import ImmutablePropTypes from 'react-immutable-proptypes';
import styled from 'react-emotion';
import Waypoint from 'react-waypoint';
import { Map } from 'immutable';
import Cursor from 'netlify-cms-lib-util/Cursor';
import { selectFields, selectInferedField } from 'Reducers/collections';
import EntryCard from './EntryCard';
import Cursor from 'ValueObjects/Cursor';
const CardsGrid = styled.div`
display: flex;

View File

@ -7,4 +7,3 @@
* Backend auth pages
*/
@import "./backends/git-gateway/AuthenticationPage.css";
@import "./backends/github/AuthenticationPage.css";

View File

@ -1,5 +1,5 @@
import { fromJS, Map } from 'immutable';
import Cursor from "ValueObjects/Cursor";
import Cursor from 'netlify-cms-lib-util/Cursor'
import {
ENTRIES_SUCCESS,
} from 'Actions/entries';

View File

@ -1,4 +0,0 @@
import implicitOauth from './implicit-oauth';
import netlifyAuth from './netlify-auth';
export { implicitOauth, netlifyAuth };

View File

@ -1152,7 +1152,7 @@ balanced-match@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
base64-js@^1.0.2:
base64-js@>=0.0.4, base64-js@^1.0.2:
version "1.3.0"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.0.tgz#cab1e6118f051095e58b5281aea8c1cd22bfc0e3"
@ -3180,7 +3180,7 @@ glob-parent@^3.1.0:
is-glob "^3.1.0"
path-dirname "^1.0.0"
glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2:
glob@>=3.2.6, glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2:
version "7.1.2"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
dependencies:
@ -3234,6 +3234,12 @@ gotrue-js@^0.9.15:
dependencies:
micro-api-client "^3.2.1"
graceful-fs@^3.0.4:
version "3.0.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-3.0.11.tgz#7613c778a1afea62f25c630a086d7f3acbbdd818"
dependencies:
natives "^1.1.0"
graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4, graceful-fs@^4.1.6:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
@ -3551,7 +3557,7 @@ immediate@~3.0.5:
version "3.0.6"
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"
immutable@^3.7.6:
immutable@^3.7.6, immutable@^3.8.2:
version "3.8.2"
resolved "https://registry.yarnpkg.com/immutable/-/immutable-3.8.2.tgz#c2439951455bb39913daf281376f1530e104adf3"
@ -4347,6 +4353,10 @@ js-base64@^2.1.9:
version "2.4.5"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.4.5.tgz#e293cd3c7c82f070d700fc7a1ca0a2e69f101f92"
js-base64@^2.4.8:
version "2.4.8"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.4.8.tgz#57a9b130888f956834aa40c5b165ba59c758f033"
js-beautify@^1.7.5:
version "1.7.5"
resolved "https://registry.yarnpkg.com/js-beautify/-/js-beautify-1.7.5.tgz#69d9651ef60dbb649f65527b53674950138a7919"
@ -5051,6 +5061,10 @@ nanomatch@^1.2.9:
snapdragon "^0.8.1"
to-regex "^3.0.1"
natives@^1.1.0:
version "1.1.4"
resolved "https://registry.yarnpkg.com/natives/-/natives-1.1.4.tgz#2f0f224fc9a7dd53407c7667c84cf8dbe773de58"
natural-compare@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
@ -5104,6 +5118,16 @@ needle@^2.2.0:
react-toggled "^1.1.2"
react-transition-group "^2.2.1"
netlify@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/netlify/-/netlify-1.2.0.tgz#ebf89b94b01b478d539630174decb496c2bbe315"
dependencies:
base64-js ">=0.0.4"
glob ">=3.2.6"
graceful-fs "^3.0.4"
semaphore "^1.0.5"
when "^3.7.5"
nice-try@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.4.tgz#d93962f6c52f2c1558c0fbda6d512819f1efe1c4"
@ -7239,7 +7263,7 @@ selection-is-backward@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/selection-is-backward/-/selection-is-backward-1.0.0.tgz#97a54633188a511aba6419fc5c1fa91b467e6be1"
semaphore@^1.0.5:
semaphore@^1.0.5, semaphore@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/semaphore/-/semaphore-1.1.0.tgz#aaad8b86b20fe8e9b32b16dc2ee682a8cd26a8aa"
@ -8266,7 +8290,7 @@ uuid@^2.0.1:
version "2.0.3"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a"
uuid@^3.0.1, uuid@^3.1.0:
uuid@^3.0.1, uuid@^3.1.0, uuid@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
@ -8403,6 +8427,10 @@ whatwg-url@^6.4.0, whatwg-url@^6.4.1:
tr46 "^1.0.1"
webidl-conversions "^4.0.2"
when@^3.7.5:
version "3.7.8"
resolved "https://registry.yarnpkg.com/when/-/when-3.7.8.tgz#c7130b6a7ea04693e842cdc9e7a1f2aa39a39f82"
whet.extend@~0.9.9:
version "0.9.9"
resolved "https://registry.yarnpkg.com/whet.extend/-/whet.extend-0.9.9.tgz#f877d5bf648c97e5aa542fadc16d6a259b9c11a1"