-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ecfe356
commit 7386e80
Showing
10 changed files
with
210 additions
and
1 deletion.
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,58 @@ | ||
var path = require('path'); | ||
var fse = require('fs-extra'); | ||
var glob = require('glob'); | ||
|
||
async function copyFile(file){ | ||
const buildPath = path.resolve(__dirname,'../build/',path.basename(file)); | ||
await fse.copy(file,buildPath); | ||
console.log(`Copied ${file} to ${buildPath}`); | ||
} | ||
|
||
async function createPackageFile() { | ||
const packageData = await fse.readFile(path.resolve(__dirname,'../package.json'),'utf-8'); | ||
const {nyc, scripts, devDependencies, workspaces, ...packageDataOther} = JSON.parse(packageData); | ||
|
||
const newPackageData = { | ||
...packageDataOther, | ||
main:'./index.js', | ||
private:false, | ||
}; | ||
|
||
const buildPath = path.resolve(__dirname,'../build/package.json'); | ||
|
||
await fse.writeFile(buildPath,JSON.stringify(newPackageData,null,2),'utf8'); | ||
console.log(`Created package.json in ${buildPath}`); | ||
|
||
return newPackageData; | ||
} | ||
|
||
async function prepend(file,string) { | ||
const data = await fse.readFile(file,'utf8'); | ||
await fse.writeFile(file,string+data,'utf8'); | ||
} | ||
|
||
async function addLicense(packageData){ | ||
const license = `/** @license Redux solace v${packageData.version} | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
`; | ||
|
||
await Promise.all( | ||
[ | ||
'../build/index.js', | ||
].map(file => prepend(path.resolve(__dirname, file), license)), | ||
); | ||
|
||
} | ||
|
||
async function run(){ | ||
await Promise.all( | ||
['./README.md','./CHANGELOG.md','./LICENSE.md'].map(file => copyFile(file)), | ||
); | ||
const packageData = await createPackageFile(); | ||
await addLicense(packageData); | ||
} | ||
|
||
run(); |
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,49 @@ | ||
'use strict'; | ||
|
||
// Do this as the first thing so that any code reading it knows the right env. | ||
process.env.NODE_ENV = 'test'; | ||
|
||
// Makes the script crash on unhandled rejections instead of silently | ||
// ignoring them. In the future, promise rejections that are not handled will | ||
// terminate the Node.js process with a non-zero exit code. | ||
process.on('unhandledRejection', err => { | ||
throw err; | ||
}); | ||
|
||
// Ensure environment variables are read. | ||
|
||
const jest = require('jest'); | ||
const execSync = require('child_process').execSync; | ||
let argv = process.argv.slice(2); | ||
|
||
function isInGitRepository() { | ||
try { | ||
execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' }); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
function isInMercurialRepository() { | ||
try { | ||
execSync('hg --cwd . root', { stdio: 'ignore' }); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
// Watch unless on CI, in coverage mode, or explicitly running all tests | ||
if ( | ||
!process.env.CI && | ||
argv.indexOf('--coverage') === -1 && | ||
argv.indexOf('--watchAll') === -1 | ||
) { | ||
// https://github.com/facebook/create-react-app/issues/5210 | ||
const hasSourceControl = isInGitRepository() || isInMercurialRepository(); | ||
argv.push(hasSourceControl ? '--watch' : '--watchAll'); | ||
} | ||
|
||
|
||
jest.run(argv); |
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,8 @@ | ||
import { Store } from 'redux'; | ||
import { Action } from 'redux-actions'; | ||
|
||
export type ActionHandlerParams = { | ||
action:Action<any>, | ||
store:Store<any>, | ||
next:Function, | ||
} |
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,5 @@ | ||
import init from './init'; | ||
|
||
init(); | ||
|
||
export { default as createSolaceMiddleware } from './middleware'; |
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,23 @@ | ||
import solace from 'solclientjs/lib-browser/solclient'; | ||
|
||
import SolaceContext from './utils/SolaceContext'; | ||
|
||
declare const window; | ||
|
||
export interface IInitState { | ||
solace:any, | ||
solaceContext:SolaceContext, | ||
} | ||
|
||
export const initState:IInitState = { | ||
solace: solace, | ||
solaceContext: null, | ||
}; | ||
|
||
function init() { | ||
initState.solaceContext = new SolaceContext(solace); | ||
window.solace = solace; | ||
window.solaceContext = initState.solaceContext; | ||
} | ||
|
||
export default init; |
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,28 @@ | ||
import { ActionHandlerParams } from './GlobalTypes'; | ||
|
||
import { initState } from './init'; | ||
|
||
declare const window; | ||
|
||
const actionHandlers = { | ||
|
||
}; | ||
|
||
export default () => { | ||
|
||
return (store)=>(next)=>(action)=>{ | ||
const actionHandlerParams:ActionHandlerParams = { | ||
store, next, action, | ||
// solace:initState.solace, | ||
// solaceContext:initState.solaceContext, | ||
}; | ||
|
||
const handler = actionHandlers[action.type]; | ||
if (handler){ | ||
handler(actionHandlerParams); | ||
}else{ | ||
return next(action); | ||
} | ||
}; | ||
|
||
} |
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,27 @@ | ||
import {createAction, ActionFunctionAny, Action} from 'redux-actions'; | ||
|
||
import noop from './noop'; | ||
|
||
export type ActionCreator<T> = ((options:T)=> Action<any>) | ||
|
||
export default function createFSA<T>(type:string, payloadCreator:(payload:T)=>any):ActionCreator<T> { | ||
|
||
const actionCreator:ActionFunctionAny<Action<any>> = createAction(type,payloadCreator); | ||
|
||
return (payload:any) => { | ||
|
||
let oriPayload:Action<any> = actionCreator(payload); | ||
|
||
oriPayload.payload = oriPayload.payload?oriPayload.payload:{}; | ||
|
||
// oriPayload.payload.callback = oriPayload.payload.callback?oriPayload.payload.callback:noop; | ||
// oriPayload.payload.errorCallback = oriPayload.payload.errorCallback?oriPayload.payload.errorCallback:noop; | ||
|
||
return <Action<any>> { | ||
...oriPayload, | ||
error:payload && payload.name === 'Error', | ||
} | ||
|
||
} | ||
|
||
} |
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,4 @@ | ||
export const PREFIX:string = 'REDUX_SOLACE'; | ||
export const DELIMITER:string = '::'; | ||
|
||
export default (type:string) => `${PREFIX}${DELIMITER}${type}`; |
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 @@ | ||
export default (...args:any[]) => {}; |