mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-20 14:35:07 +00:00
New build
This commit is contained in:
@@ -110,15 +110,14 @@ func main() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
services := []service{}
|
services := []service{}
|
||||||
tsExportsMap := map[string]string{}
|
tsFileList := []string{"esm", "index.js", "index.d.ts"}
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
if strings.Contains(f.Name(), "clients") || strings.Contains(f.Name(), "examples") {
|
if strings.Contains(f.Name(), "clients") || strings.Contains(f.Name(), "examples") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if f.IsDir() && !strings.HasPrefix(f.Name(), ".") {
|
if f.IsDir() && !strings.HasPrefix(f.Name(), ".") {
|
||||||
serviceName := f.Name()
|
serviceName := f.Name()
|
||||||
// see https://stackoverflow.com/questions/44345257/import-from-subfolder-of-npm-package
|
tsFileList = append(tsFileList, serviceName)
|
||||||
tsExportsMap["./"+serviceName] = "./dist/" + serviceName + "/index.js"
|
|
||||||
serviceDir := filepath.Join(workDir, f.Name())
|
serviceDir := filepath.Join(workDir, f.Name())
|
||||||
cmd := exec.Command("make", "api")
|
cmd := exec.Command("make", "api")
|
||||||
cmd.Dir = serviceDir
|
cmd.Dir = serviceDir
|
||||||
@@ -187,12 +186,12 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.MkdirAll(filepath.Join(tsPath, serviceName), 0777)
|
err = os.MkdirAll(filepath.Join(tsPath, "src", serviceName), 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
f, err := os.OpenFile(filepath.Join(tsPath, serviceName, "index.ts"), os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0744)
|
f, err := os.OpenFile(filepath.Join(tsPath, "src", serviceName, "index.ts"), os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0744)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Failed to open schema file", err)
|
fmt.Println("Failed to open schema file", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -204,7 +203,7 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
cmd = exec.Command("prettier", "-w", "index.ts")
|
cmd = exec.Command("prettier", "-w", "index.ts")
|
||||||
cmd.Dir = filepath.Join(tsPath, serviceName)
|
cmd.Dir = filepath.Join(tsPath, "src", serviceName)
|
||||||
outp, err = cmd.CombinedOutput()
|
outp, err = cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(fmt.Sprintf("Problem formatting '%v' client: %v %s", serviceName, string(outp), err.Error()))
|
fmt.Println(fmt.Sprintf("Problem formatting '%v' client: %v %s", serviceName, string(outp), err.Error()))
|
||||||
@@ -554,6 +553,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
newV := latest.IncPatch()
|
newV := latest.IncPatch()
|
||||||
|
|
||||||
|
// add file list to gitignore
|
||||||
|
f, err = os.OpenFile(filepath.Join(tsPath, ".gitignore"), os.O_APPEND, 0744)
|
||||||
|
for _, sname := range tsFileList {
|
||||||
|
_, err := f.Write([]byte(sname + "\n"))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("failed to append service to gitignore", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// bump package to latest version
|
// bump package to latest version
|
||||||
fmt.Println("Bumping to ", newV.String())
|
fmt.Println("Bumping to ", newV.String())
|
||||||
repl := exec.Command("sed", "-i", "-e", "s/1.0.1/"+newV.String()+"/g", "package.json")
|
repl := exec.Command("sed", "-i", "-e", "s/1.0.1/"+newV.String()+"/g", "package.json")
|
||||||
@@ -576,7 +585,7 @@ func main() {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
m["exports"] = tsExportsMap
|
m["files"] = tsFileList
|
||||||
pakJS, err := json.MarshalIndent(m, "", " ")
|
pakJS, err := json.MarshalIndent(m, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|||||||
91
cmd/clients/ts/build.js
Normal file
91
cmd/clients/ts/build.js
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
const chalk = require('chalk');
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
const rimraf = require('rimraf');
|
||||||
|
const { ncp } = require('ncp');
|
||||||
|
|
||||||
|
function getTmpEsmDirectories() {
|
||||||
|
return fs
|
||||||
|
.readdirSync('./tmp/esm')
|
||||||
|
.filter(file => fs.statSync(`./tmp/esm/${file}`).isDirectory());
|
||||||
|
}
|
||||||
|
|
||||||
|
function log(text) {
|
||||||
|
console.log(`${chalk.cyan('M3O JS:')} ${text}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeModulePackageJsonFile(location) {
|
||||||
|
fs.writeFileSync(
|
||||||
|
`${location}/package.json`,
|
||||||
|
`{"module": "./esm/index.js"}`,
|
||||||
|
'utf8'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteDirectory(directory) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
rimraf(directory, err => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyAllTmpFolders() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// Now copy to root level
|
||||||
|
ncp(path.join(__dirname, 'tmp'), __dirname, err => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function moveToLocalEsmFolders() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const esmDirs = getTmpEsmDirectories();
|
||||||
|
|
||||||
|
// Move the files around in tmp...
|
||||||
|
esmDirs.forEach(dir => {
|
||||||
|
const currentPath = path.join(__dirname, 'tmp/esm', dir);
|
||||||
|
|
||||||
|
fs.readdirSync(currentPath).forEach(async file => {
|
||||||
|
const currentFilePath = path.join(currentPath, file);
|
||||||
|
const newFilePath = path.join(__dirname, 'tmp', dir, 'esm', file);
|
||||||
|
const esmFolderLocation = path.join(__dirname, 'tmp', dir, 'esm');
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!fs.existsSync(esmFolderLocation)) {
|
||||||
|
fs.mkdirSync(esmFolderLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.renameSync(currentFilePath, newFilePath);
|
||||||
|
writeModulePackageJsonFile(`./tmp/${dir}`);
|
||||||
|
await deleteDirectory(`./tmp/esm/${dir}`);
|
||||||
|
} catch (err) {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
log('Moved local esm folders');
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function build() {
|
||||||
|
log('Moving to correct folders');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await moveToLocalEsmFolders();
|
||||||
|
await copyAllTmpFolders();
|
||||||
|
writeModulePackageJsonFile('./tmp/esm');
|
||||||
|
await deleteDirectory('./tmp');
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
build();
|
||||||
6482
cmd/clients/ts/package-lock.json
generated
6482
cmd/clients/ts/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,26 +1,31 @@
|
|||||||
{
|
{
|
||||||
"name": "m3o",
|
"name": "@micro/services",
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"description": "",
|
"types": "index.d.ts",
|
||||||
"main": "dist",
|
"main": "index.js",
|
||||||
"types": "dist/index.d.ts",
|
"module": "esm/index.js",
|
||||||
"type": "module",
|
"files": [],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/micro/services"
|
"url": "https://github.com/micro/services"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"clean": "rimraf ./tmp",
|
||||||
"prepare": "npm run build",
|
"build": "npm run clean && tsc && tsc --p tsconfig.es.json && node build.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"prepare": "npm run build"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"dependencies": {
|
||||||
"typescript": "^3.5.1"
|
"@m3o/m3o-node": "^0.0.24",
|
||||||
},
|
"@types/estree": "^0.0.47",
|
||||||
"dependencies": {
|
"chalk": "^2.4.2",
|
||||||
"@m3o/m3o-node": "^0.0.24"
|
"move-file": "^3.0.0",
|
||||||
},
|
"ncp": "^2.0.0",
|
||||||
"exports": {}
|
"rimraf": "^3.0.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"prettier": "^2.4.1",
|
||||||
|
"typescript": "^3.5.1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
cmd/clients/ts/tsconfig.es.json
Normal file
16
cmd/clients/ts/tsconfig.es.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "ES2015",
|
||||||
|
"target": "ES6",
|
||||||
|
"declaration": true,
|
||||||
|
"lib": ["es2015", "dom"],
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"outDir": "./tmp/esm",
|
||||||
|
"strict": true,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"esModuleInterop": true
|
||||||
|
},
|
||||||
|
"include": ["src/index.ts", "src/**/*"],
|
||||||
|
"exclude": ["./dist", "./node_modules"]
|
||||||
|
}
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"module": "es6",
|
"module": "CommonJS",
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"lib": ["es2015", "dom"],
|
"lib": ["es2015", "dom"],
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
"outDir": "./dist",
|
"outDir": "./tmp",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"esModuleInterop": true
|
"esModuleInterop": true
|
||||||
},
|
},
|
||||||
"include": ["index.ts", "./*"],
|
"include": ["src/index.ts", "src/**/*"],
|
||||||
"exclude": ["src/**/*.spec.*", "./dist", "./node_modules"]
|
"exclude": ["./dist", "./node_modules"]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user