-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypescript_2018.rb
85 lines (67 loc) · 1.94 KB
/
typescript_2018.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
require 'fileutils'
require 'shellwords'
require 'json'
def source_dir
return File.dirname(__FILE__) unless __FILE__ =~ %r{\Ahttps?://}
tmpdir = Dir.mktmpdir('rails-template-')
at_exit { FileUtils.remove_entry(tmpdir) }
git clone: [
'--quiet',
'https://github.com/hyfn/rails-templates.git',
tmpdir,
].map(&:shellescape).join(' ')
tmpdir
end
source_paths.unshift(File.join(source_dir, 'typescript_2018'))
####################################
# WEBPACKER
####################################
rails_command 'webpacker:install:typescript'
remove_file 'app/assets'
# run 'yarn remove coffee-loader coffee-script'
# remove_file 'config/webpack/loaders/coffee.js'
npm_packages = %(
@types/react @types/react-dom
@types/classnames classnames
mobx mobx-react
react-router-dom @types/react-router-dom
axios @types/axios
json2typescript
lodash @types/lodash
raven-js @types/raven-js
).gsub(/\s+/, ' ')
run "yarn add #{npm_packages}"
dev_packages = %(
tslint
prettier
tslint-react
tslint-no-circular-imports
webpack-bundle-analyzer
).gsub(/\s+/, ' ')
run "yarn add #{dev_packages} --dev"
require 'pry'
package_json = JSON.parse(File.read('package.json'))
package_json_updates = {
"scripts": {
"start": 'bin/webpack-dev-server',
"lint": 'tslint -p tsconfig.json --type-check -t verbose',
"lint:fix": 'tslint -p tsconfig.json --type-check --fix -t verbose',
},
"engines": {
"vscode": '^1.0',
"node": '>=7.6.0',
"yarn": '^1.0',
},
"prettier": {
"printWidth": 80,
"semi": false,
"trailingComma": 'es5',
},
}
File.write('package.json', JSON.dump(package_json.merge(package_json_updates)))
remove_file 'app/javascript/packs/application.js'
remove_file 'app/javascript/packs/hello_react.jsx'
remove_file 'app/javascript/packs/hello_typescript.tsx'
directory 'app', 'app', recursive: true, verbose: true
copy_file 'tslint.json', 'tslint.json'
copy_file 'tsconfig.json', 'tsconfig.json'