Skip to content

Commit fa4ae97

Browse files
committed
Add typescript template
1 parent 351825a commit fa4ae97

File tree

7 files changed

+97
-8
lines changed

7 files changed

+97
-8
lines changed

packages/cycle-scripts/scripts/init/setup.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const path = require('path')
55
const chalk = require('chalk')
66
const spawn = require('cross-spawn')
77

8-
const flavorConfig = require('../../configs/flavor')
98
const success = require('./success')
109

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

1716
// STEP #1 - Create boilerplate files
1817
const flavorPath = path.join(appPath, 'node_modules', 'cycle-scripts')
19-
const templateStrings = flavorConfig.replacements
18+
const templateStrings = require(path.join(flavorPath, 'template/config', language, 'flavor.js'))
2019
const templatePath = path.join(flavorPath, 'template/src', language)
2120
// Create ./public directory
2221
fs.ensureDirSync(path.join(appPath, 'public'))
@@ -70,10 +69,8 @@ module.exports = function setup (appPath, appName, options) {
7069
// Taking into consideration user choices for language and stream library
7170
// All the dependency locks and configurations can be found in /configs/flavor.js
7271
const basicDependencies = flavorConfig.dependencies.basics
73-
const languageDependencies = flavorConfig.dependencies.language[language]
7472
const streamLibDependencies = flavorConfig.dependencies.streamLib[streamLib]
7573
const dependenciesToInstall = basicDependencies
76-
.concat(languageDependencies)
7774
.concat(streamLibDependencies)
7875
const dependecyList = dependenciesToInstall
7976
.slice(0, (dependenciesToInstall.length - 1))

packages/cycle-scripts/configs/flavor.js renamed to packages/cycle-scripts/template/config/JavaScript/flavor.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ const dependencies = {
22
basics: [
33
'@cycle/dom@17.1.0'
44
],
5-
language: {
6-
'javascript': [],
7-
'typescript': []
8-
},
95
streamLib: {
106
xstream: [
117
'@cycle/run@3.1.0',
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const dependencies = {
2+
basics: [
3+
'@cycle/dom@17.1.0'
4+
],
5+
streamLib: {
6+
xstream: [
7+
'@cycle/run@3.1.0',
8+
'xstream@10.5.0'
9+
],
10+
rxjs: [
11+
'@cycle/rxjs-run@7.0.0',
12+
'rxjs@5.3.0'
13+
],
14+
most: [
15+
'@cycle/most-run@7.1.0',
16+
'most@1.2.2'
17+
]
18+
}
19+
}
20+
21+
const replacements = {
22+
xstream: {
23+
run: '@cycle/run',
24+
import: 'import xs from \'xstream\'',
25+
typeImport: 'import {Stream} from \'xstream\'',
26+
stream: 'xs',
27+
streamType: 'Stream'
28+
},
29+
rxjs: {
30+
run: '@cycle/rxjs-run',
31+
import: 'import Rx from \'rxjs/Rx\'',
32+
typeImport: 'import {Observable} from \'rxjs\'',
33+
stream: 'Rx.Observable',
34+
streamType: 'Observable'
35+
},
36+
most: {
37+
run: '@cycle/most-run',
38+
import: 'import * as most from \'most\'',
39+
typeImport: 'import {Stream} from \'most\'',
40+
stream: 'most',
41+
streamType: 'Stream'
42+
}
43+
}
44+
45+
module.exports = {
46+
dependencies,
47+
replacements
48+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = replacements => `${replacements.import}
2+
import {Sources, Sinks} from './interfaces'
3+
4+
export function App(sources : Sources) : Sinks {
5+
const vtree$ = ${replacements.stream}.of(
6+
<div>My Awesome Cycle.js app</div>
7+
)
8+
9+
return {
10+
DOM: vtree$
11+
}
12+
}
13+
`
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = replacements => `// import assert from 'assert'
2+
3+
// describe('App', function () {
4+
// it('should test something', function () {
5+
// // TODO: Add your tests here
6+
// })
7+
// })
8+
`
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = replacements => `import {run} from '${replacements.run}'
2+
import {makeDOMDriver} from '@cycle/dom'
3+
import {Component} from './interfaces'
4+
5+
import {App} from './app'
6+
7+
const main : Component = App
8+
9+
const drivers = {
10+
DOM: makeDOMDriver('#root')
11+
}
12+
13+
run(main, drivers)
14+
`
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = replacements => `${replacements.import}
2+
import {DOMSource, VNode} from '@cycle/dom'
3+
4+
export type Sources = {
5+
DOM : DOMSource;
6+
}
7+
8+
export type Sinks = {
9+
DOM : ${replacements.streamType}<VNode>;
10+
}
11+
12+
export type Component = (s : Sources) => Sinks;
13+
`

0 commit comments

Comments
 (0)