Skip to content

Commit

Permalink
Merge pull request #213 from plone/scaffold/test-1
Browse files Browse the repository at this point in the history
Scaffold/test 1
  • Loading branch information
nileshgulia1 committed Jul 7, 2018
2 parents 9d55b1b + 4e10d2c commit a08d857
Show file tree
Hide file tree
Showing 406 changed files with 36,319 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -15,8 +15,9 @@ create-plone-react-app <appName>
cd <appName>
yarn start //start the development server
```
![peek 2018-07-07 08-24](https://user-images.githubusercontent.com/22280901/42406154-b3304600-81bf-11e8-8617-9890db5b8378.gif)
#### Features
- Free from configurations.
- No configuration needed.
- Fixed development stack.
- Incredible fast website developing tool.

Expand Down
30 changes: 30 additions & 0 deletions create-plone-react-app/bin/create-plone-react-app.js
@@ -0,0 +1,30 @@
#! /usr/bin/env node

const chalk = require('chalk');
const program = require('commander');
const lib = require('..');
const pkg = require('../package.json');

const messages = lib.messages;
const createPloneApp = lib.createPloneApp;

let projectName;

program
.version(pkg.version)
.arguments('<project-directory>')
.usage(`${chalk.green('<project-directory>')} [options]`)
.action(function(name) {
projectName = name;
})
.option('-e, --example <example-path>', messages.exampleHelp())
.allowUnknownOption()
.on('--help', messages.help)
.parse(process.argv);

const example = program.example;

createPloneApp({
projectName,
example,
});
9 changes: 9 additions & 0 deletions create-plone-react-app/index.js
@@ -0,0 +1,9 @@
'use strict';

const createPloneReact = require('./lib');
const messages = require('./lib/messages');

module.exports = {
messages: messages,
createPloneApp: createPloneReact,
};
58 changes: 58 additions & 0 deletions create-plone-react-app/lib/index.js
@@ -0,0 +1,58 @@
'use strict';

const path = require('path');
const fs = require('fs');
const copyDir = require('./utils/copy-dir');
const install = require('./utils/install');
const messages = require('./messages');

module.exports = function createPloneApp(opts) {
const projectName = opts.projectName;

if (!projectName) {
console.log(messages.missingProjectName());
process.exit(1);
}

if (fs.existsSync(projectName)) {
console.log(messages.alreadyExists(projectName));
process.exit(1);
}

const projectPath = (opts.projectPath = process.cwd() + '/' + projectName);


const templatePath = path.resolve(__dirname, '../src');// problem is there

copyDir({
templatePath: templatePath,
projectPath: projectPath,
projectName: projectName,
})
.then(installWithMessageFactory(opts))
.catch(function(err) {
throw err;
});

};

function installWithMessageFactory(opts, isExample = false) {
const projectName = opts.projectName;
const projectPath = opts.projectPath;

return function installWithMessage() {
return install({
projectName: projectName,
projectPath: projectPath,
packages: isExample
? ['react']
: ['react', 'react-dom', 'react-router-dom', '@plone/plone-react', 'express'],
})
.then(function() {
console.log(messages.start(projectName));
})
.catch(function(err) {
throw err;
});
};
}
54 changes: 54 additions & 0 deletions create-plone-react-app/lib/utils/install.js
@@ -0,0 +1,54 @@
'use strict';

const execa = require('execa');
const Promise = require('promise');
const messages = require('../messages');
const getInstallCmd = require('./get-install-cmd');
const output = require('./output');

module.exports = function install(opts) {
const projectName = opts.projectName;
const projectPath = opts.projectPath;
const packages = opts.packages || [];

if (packages.length === 0) {
console.log('Missing packages in `install`, try running again.');
process.exit(1);
}

const installCmd = getInstallCmd();
const installArgs = getInstallArgs(installCmd, packages);

console.log(messages.installing(packages));
process.chdir(projectPath);

return new Promise(function(resolve, reject) {
const stopInstallSpinner = output.wait('Installing modules');

execa(installCmd, installArgs)
.then(function() {
// Confirm that all dependencies were installed
return execa(installCmd, ['install']);
})
.then(function() {
stopInstallSpinner();
output.success(`Installed dependencies for ${projectName}`);
resolve();
})
.catch(function() {
stopInstallSpinner();
console.log(messages.installError(packages));
return reject(new Error(`${installCmd} installation failed`));
});
});
};

function getInstallArgs(cmd, packages) {
if (cmd === 'npm') {
const args = ['install', '--save', '--save-exact'];
return args.concat(packages, ['--verbose']);
} else if (cmd === 'yarn') {
const args = ['add'];
return args.concat(packages);
}
}
2 changes: 1 addition & 1 deletion create-plone-react-app/package.json
Expand Up @@ -10,7 +10,7 @@
},
"repository": "",
"bin": {
"create-plone-react-app": "./bin/create-plone-react-app"
"create-plone-react-app": "./bin/create-plone-react-app.js"
},
"dependencies": {
"ansi-escapes": "^2.0.0",
Expand Down
19 changes: 19 additions & 0 deletions create-plone-react-app/src/actions/actions/actions.js
@@ -0,0 +1,19 @@
/**
* Actions actions.
* @module actions/actions/actions
*/

import { LIST_ACTIONS } from '../../constants/ActionTypes';

/**
* List actions.
* @function listActions
* @param {string} url Content url.
* @returns {Object} List actions action.
*/
export function listActions(url) {
return {
type: LIST_ACTIONS,
promise: api => api.get(`${url}/@actions`),
};
}
20 changes: 20 additions & 0 deletions create-plone-react-app/src/actions/actions/actions.test.js
@@ -0,0 +1,20 @@
import { listActions } from './actions';
import { LIST_ACTIONS } from '../../constants/ActionTypes';

describe('Actions action', () => {
describe('listActions', () => {
it('should create an action to list the actions', () => {
const url = 'http://localhost';
const action = listActions(url);

expect(action.type).toEqual(LIST_ACTIONS);

const apiMock = {
get: jest.fn(),
};
action.promise(apiMock);

expect(apiMock.get).toBeCalledWith(`${url}/@actions`);
});
});
});
19 changes: 19 additions & 0 deletions create-plone-react-app/src/actions/breadcrumbs/breadcrumbs.js
@@ -0,0 +1,19 @@
/**
* Breadcrumbs actions.
* @module actions/breadcrumbs/breadcrumbs
*/

import { GET_BREADCRUMBS } from '../../constants/ActionTypes';

/**
* Get breadcrumbs.
* @function getBreadcrumbs
* @param {string} url Content url.
* @returns {Object} Get breadcrumbs action.
*/
export function getBreadcrumbs(url) {
return {
type: GET_BREADCRUMBS,
promise: api => api.get(`${url}/@breadcrumbs`),
};
}
20 changes: 20 additions & 0 deletions create-plone-react-app/src/actions/breadcrumbs/breadcrumbs.test.js
@@ -0,0 +1,20 @@
import { getBreadcrumbs } from './breadcrumbs';
import { GET_BREADCRUMBS } from '../../constants/ActionTypes';

describe('Breadcrumbs action', () => {
describe('getBreadcrumbs', () => {
it('should create an action to get the breadcrumbs', () => {
const url = 'http://localhost';
const action = getBreadcrumbs(url);

expect(action.type).toEqual(GET_BREADCRUMBS);

const apiMock = {
get: jest.fn(),
};
action.promise(apiMock);

expect(apiMock.get).toBeCalledWith(`${url}/@breadcrumbs`);
});
});
});
65 changes: 65 additions & 0 deletions create-plone-react-app/src/actions/clipboard/clipboard.js
@@ -0,0 +1,65 @@
/**
* Clipboard actions.
* @module actions/clipboard/clipboard
*/

import {
COPY_CONTENT,
MOVE_CONTENT,
COPY,
CUT,
} from '../../constants/ActionTypes';

/**
* Copy content function.
* @function copyContent
* @param {array} source Source urls.
* @param {string} target Target url.
* @returns {Object} Copy content action.
*/
export function copyContent(source, target) {
return {
type: COPY_CONTENT,
promise: api => api.post(`${target}/@copy`, { data: { source } }),
};
}

/**
* Move content function.
* @function moveContent
* @param {array} source Source urls.
* @param {string} target Target url.
* @returns {Object} Move content action.
*/
export function moveContent(source, target) {
return {
type: MOVE_CONTENT,
promise: api => api.post(`${target}/@move`, { data: { source } }),
};
}

/**
* Copy function.
* @function copy
* @param {array} urls Source urls.
* @returns {Object} Copy action.
*/
export function copy(urls) {
return {
type: COPY,
source: urls,
};
}

/**
* Cut function.
* @function cut
* @param {array} urls Source urls.
* @returns {Object} Cut action.
*/
export function cut(urls) {
return {
type: CUT,
source: urls,
};
}
67 changes: 67 additions & 0 deletions create-plone-react-app/src/actions/clipboard/clipboard.test.js
@@ -0,0 +1,67 @@
import { copy, cut, copyContent, moveContent } from './clipboard';
import {
COPY_CONTENT,
MOVE_CONTENT,
COPY,
CUT,
} from '../../constants/ActionTypes';

describe('Clipboard action', () => {
describe('copyContent', () => {
it('should create an action to copy content', () => {
const source = ['http://source'];
const target = 'http://target';
const action = copyContent(source, target);

expect(action.type).toEqual(COPY_CONTENT);

const apiMock = {
post: jest.fn(),
};
action.promise(apiMock);

expect(apiMock.post).toBeCalledWith(`${target}/@copy`, {
data: { source },
});
});
});

describe('moveContent', () => {
it('should create an action to move content', () => {
const source = ['http://source'];
const target = 'http://target';
const action = moveContent(source, target);

expect(action.type).toEqual(MOVE_CONTENT);

const apiMock = {
post: jest.fn(),
};
action.promise(apiMock);

expect(apiMock.post).toBeCalledWith(`${target}/@move`, {
data: { source },
});
});
});

describe('copy', () => {
it('should create an action to copy', () => {
const source = ['http://source'];
const action = copy(source);

expect(action.type).toEqual(COPY);
expect(action.source).toEqual(source);
});
});

describe('cut', () => {
it('should create an action to cut', () => {
const source = ['http://source'];
const action = cut(source);

expect(action.type).toEqual(CUT);
expect(action.source).toEqual(source);
});
});
});

0 comments on commit a08d857

Please sign in to comment.