Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #213 from plone/scaffold/test-1
Scaffold/test 1
- Loading branch information
Showing
406 changed files
with
36,319 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
const createPloneReact = require('./lib'); | ||
const messages = require('./lib/messages'); | ||
|
||
module.exports = { | ||
messages: messages, | ||
createPloneApp: createPloneReact, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
20
create-plone-react-app/src/actions/actions/actions.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
19
create-plone-react-app/src/actions/breadcrumbs/breadcrumbs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
20
create-plone-react-app/src/actions/breadcrumbs/breadcrumbs.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
67
create-plone-react-app/src/actions/clipboard/clipboard.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.