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

@ -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 };