Skip to content

Commit

Permalink
ts_library problem bazelbuild/rules_typescript#263
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Smetanin committed Oct 26, 2018
1 parent 754dc17 commit 952c322
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 4 deletions.
18 changes: 18 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,22 @@ exports_files([
"tsconfig.build.json",
])

filegroup(
name = "node_modules",
srcs = glob(
include = ["node_modules/**/*"],
exclude = [
# Files under test & docs may contain file names that
# are not legal Bazel labels (e.g.,
# node_modules/ecstatic/test/public/中文/檔案.html)
"node_modules/test/**",
"node_modules/docs/**",
# Files with spaces are not allowed in Bazel runfiles
# See https://github.com/bazelbuild/bazel/issues/4327
"node_modules/**/* */**",
"node_modules/**/* *",
],
),
)

# gazelle proto:disable_global
58 changes: 58 additions & 0 deletions dist/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package(default_visibility = ["//visibility:public"])

load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")

# nodejs_binary(
# name = "web",
# visibility = ["//visibility:public"],
# entry_point = "gobazel/build/copy.js",
# data = [
# ":copy.js",
# "//web:copy"
# ]
# )

nodejs_binary(
name = "copy",
visibility = ["//visibility:public"],
# entry_point = "gobazel/node_modules/ts-node/dist/bin.js",
entry_point = "gobazel/build/copy.js",
install_source_map_support = False,
# node_modules = "//:node_modules",

# node_modules = "@npm//:node_modules"
data = [
":copy.js"
# "//:tsconfig.build.json",
],
)


genrule(
name = "build",
srcs = [
# "//web:copy",
":copy.js",
"//web:lib",
"//backend/cmd/service:service"
# "//publicapi:publicapi"

],
outs = ["service", "frontend"],
cmd = "node dist/copy.js $(location //backend/cmd/service:service) $(location //web:lib) $(@D)",
# cmd = "echo \"hello\"; pwd; echo $(location tsnode); $(location tsnode) $(location copy.ts)",
# cmd = "$(location tsnode) $(location copy.ts) $(location web)",
# cmd = "$(location babel) src --out-dir $@",
tools = [":copy"],
)


genrule(
name = "ls",
srcs = [
"//web:lib",
],
outs = ['qwe'],

cmd = "ls `dirname $(locations //web:lib)`; ls `dirname $(location //web:lib)`; echo qwe > $(location qwe)",
)
64 changes: 64 additions & 0 deletions dist/copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

// console.log(process.env)
console.log(process.argv)



const path = require('path');
const fs = require('fs');
const shell = require('shelljs');

// function readFile(srcPath) {
// return new Promise(function (resolve, reject) {
// fs.readFile(srcPath, 'utf8', function (err, data) {
// if (err) {
// reject(err)
// } else {
// resolve(data);
// }
// });
// })
// }

// function writeFile(savPath, data) {
// return new Promise(function (resolve, reject) {
// fs.writeFile(savPath, data, function (err) {
// if (err) {
// reject(err)
// } else {
// resolve();
// }
// });
// })
// }

// const wsDir = process.env.BUILD_WORKSPACE_DIRECTORY;



// const in_file = process.argv[2]
// const out_file = process.argv[3]
const dest = process.argv[process.argv.length-1]

// console.log('Read ', in_file)
console.log('pwd:', process.cwd())
console.log(shell.ls(process.cwd()))

console.log('Write ', dest)

shell.mkdir('-p', path.join(dest, 'frontend'))
shell.cp(process.argv[2], dest)
console.log('front path', path.dirname(process.argv[3]))
console.log(shell.ls('-R', path.resolve(path.dirname(process.argv[3]), '../' )))
shell.cp(path.dirname(process.argv[3]), path.join(dest, 'frontend'))
// shell.cp(process.argv[3], path.join(dest, 'frontend'))



// readFile(in_file)
// .then(function(results){
// results+=" test manipulation";
// return writeFile(path.join(out_file, 'qwe.txt'), results);
// }).then(function(){
// //done writing file, can do other things
// })
3 changes: 3 additions & 0 deletions dist/copy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

console.log('TS!!!!')
console.log(process.argv)
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
"build-frontend": "bazel build //web:devserver",
"start": "npm run build-frontend && npm run build-backend && concurrently \"npm run start-frontend\" \"npm run start-backend\"",
"start-backend": "ibazel run //backend/cmd/service:service",
"start-frontend": "ibazel run //web:devserver"
"start-frontend": "ibazel run //web:devserver",
"start-dist": "ibazel build //dist:build"
},
"dependencies": {
"@bazel/ibazel": "0.4.0",
"@bazel/typescript": "0.20.3",
"@types/node": "10.12.0",
"concurrently": "3.5.1",
"shelljs": "0.8.2",
"ts-node": "7.0.1",
"tsutils": "3.2.0",
"typescript": "3.1.1"
}
Expand Down
16 changes: 14 additions & 2 deletions web/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package(default_visibility = ["//visibility:public"])
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")

ts_library(
name = "src",
name = "lib",
srcs = ["index.tsx"],
tsconfig = "//:tsconfig.build.json",
deps = [
Expand All @@ -25,10 +25,22 @@ ts_devserver(
port = 9999,
serving_path = "/bundle.min.js",
#entry_module = "gobazel/src/frontend/main",
deps = [":src"],
deps = [":lib"],
static_files = [
":index.html",
"@npm//node_modules/react:umd/react.development.js",
"@npm//node_modules/react-dom:umd/react-dom.development.js"
],
)

load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")

nodejs_binary(
name = "copy",
visibility = ["//visibility:public"],
entry_point = "gobazel/web/copy.js",
data = [
":copy.js",
":index.html"
]
)
42 changes: 42 additions & 0 deletions web/copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

// console.log(process.env)
// console.log(process.argv)

const path = require('path');
const fs = require('fs');

function readFile(srcPath) {
return new Promise(function (resolve, reject) {
fs.readFile(srcPath, 'utf8', function (err, data) {
if (err) {
reject(err)
} else {
resolve(data);
}
});
})
}

function writeFile(savPath, data) {
return new Promise(function (resolve, reject) {
fs.writeFile(savPath, data, function (err) {
if (err) {
reject(err)
} else {
resolve();
}
});
})
}

// const wsDir = process.env.BUILD_WORKSPACE_DIRECTORY;

console.log('Copy ', path.join(__dirname, 'index.html'))

readFile(path.join(__dirname, 'index.html'))
.then(function(results){
results+=" test manipulation";
return writeFile(path.join(__dirname, 'index1.html'),results);
}).then(function(){
//done writing file, can do other things
})
2 changes: 1 addition & 1 deletion web/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let user: IUser = {

ReactDOM.render(
<div>
<div>This is app</div>
<div>This is app!!!!!!</div>
<Qwe/>
<div>{JSON.stringify(user)}</div>
</div>,
Expand Down

0 comments on commit 952c322

Please sign in to comment.