Skip to content

Typescript #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 10, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions packages/cycle-scripts/scripts/init/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const path = require('path')
const chalk = require('chalk')
const spawn = require('cross-spawn')

const flavorConfig = require('../../configs/flavor')
const success = require('./success')

module.exports = function setup (appPath, appName, options) {
Expand All @@ -16,7 +15,7 @@ module.exports = function setup (appPath, appName, options) {

// STEP #1 - Create boilerplate files
const flavorPath = path.join(appPath, 'node_modules', 'cycle-scripts')
const templateStrings = flavorConfig.replacements
const templateStrings = require(path.join(flavorPath, 'template/config', language, 'flavor.js')).replacements
const templatePath = path.join(flavorPath, 'template/src', language)
// Create ./public directory
fs.ensureDirSync(path.join(appPath, 'public'))
Expand Down Expand Up @@ -70,10 +69,8 @@ module.exports = function setup (appPath, appName, options) {
// Taking into consideration user choices for language and stream library
// All the dependency locks and configurations can be found in /configs/flavor.js
const basicDependencies = flavorConfig.dependencies.basics
const languageDependencies = flavorConfig.dependencies.language[language]
const streamLibDependencies = flavorConfig.dependencies.streamLib[streamLib]
const dependenciesToInstall = basicDependencies
.concat(languageDependencies)
.concat(streamLibDependencies)
const dependecyList = dependenciesToInstall
.slice(0, (dependenciesToInstall.length - 1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ const dependencies = {
basics: [
'@cycle/[email protected]'
],
language: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure there won't be any specific language dependency that we'll need to install? (I didn't know about typescript to much that's why i left this here)

Copy link
Collaborator Author

@jvanbruegge jvanbruegge Apr 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but as this file is splitted you can add them to the basics array. We could split the file, so the basics, and stream lib stuff is common and there is an additional entry in the flavor.js for language specific imports

'javascript': [],
'typescript': []
},
streamLib: {
xstream: [
'@cycle/[email protected]',
Expand Down
48 changes: 48 additions & 0 deletions packages/cycle-scripts/template/config/Typescript/flavor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const dependencies = {
basics: [
'@cycle/[email protected]'
],
streamLib: {
xstream: [
'@cycle/[email protected]',
'[email protected]'
],
rxjs: [
'@cycle/[email protected]',
'[email protected]'
],
most: [
'@cycle/[email protected]',
'[email protected]'
]
}
}

const replacements = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't make sense to just move replacements within template as the dependencies cofnig is not related to this?

xstream: {
run: '@cycle/run',
import: 'import xs from \'xstream\'',
typeImport: 'import {Stream} from \'xstream\'',
stream: 'xs',
streamType: 'Stream'
},
rxjs: {
run: '@cycle/rxjs-run',
import: 'import Rx from \'rxjs/Rx\'',
typeImport: 'import {Observable} from \'rxjs\'',
stream: 'Rx.Observable',
streamType: 'Observable'
},
most: {
run: '@cycle/most-run',
import: 'import * as most from \'most\'',
typeImport: 'import {Stream} from \'most\'',
stream: 'most',
streamType: 'Stream'
}
}

module.exports = {
dependencies,
replacements
}
8 changes: 8 additions & 0 deletions packages/cycle-scripts/template/src/Typescript/app.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = replacements => `// import assert from 'assert'

// describe('App', function () {
// it('should test something', function () {
// // TODO: Add your tests here
// })
// })
`
13 changes: 13 additions & 0 deletions packages/cycle-scripts/template/src/Typescript/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = replacements => `${replacements.import}
import {Sources, Sinks} from './interfaces'

export function App(sources : Sources) : Sinks {
const vtree$ = ${replacements.stream}.of(
<div>My Awesome Cycle.js app</div>
)

return {
DOM: vtree$
}
}
`
14 changes: 14 additions & 0 deletions packages/cycle-scripts/template/src/Typescript/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = replacements => `import {run} from '${replacements.run}'
import {makeDOMDriver} from '@cycle/dom'
import {Component} from './interfaces'

import {App} from './app'

const main : Component = App

const drivers = {
DOM: makeDOMDriver('#root')
}

run(main, drivers)
`
13 changes: 13 additions & 0 deletions packages/cycle-scripts/template/src/Typescript/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = replacements => `${replacements.import}
import {DOMSource, VNode} from '@cycle/dom'

export type Sources = {
DOM : DOMSource;
}

export type Sinks = {
DOM : ${replacements.streamType}<VNode>;
}

export type Component = (s : Sources) => Sinks;
`