Skip to content

Commit

Permalink
fix: 将‘创建内部SDK包’的命令分离出来,在构建 docker 镜像时要单独用到;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Jul 26, 2021
1 parent 9509ec5 commit 321b2f0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
30 changes: 30 additions & 0 deletions packages/less-api-framework/init/create-internal-package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const fse = require('fs-extra')
const path = require('path')


/**
* 在 node_modules 中创建 云函数 sdk 包:@, 这个包是为了云函数IDE 加载类型提示文件而创建的,不可发布
*/
function createCloudFunctionDeclarationPackage() {
const source = path.resolve(__dirname, '../dist')
const target = path.resolve(__dirname, '../node_modules/@')

fse.ensureDirSync(target)
fse.copySync(source, target)

console.log(`copy success: ${source} => ${target}`)

const packageJson = `
{
"name": "@",
"version": "0.0.0"
}
`
const pkgJsonPath = path.join(target, 'package.json')
fse.writeFileSync(pkgJsonPath, packageJson)

console.log(`write success: ${pkgJsonPath}`)
}


createCloudFunctionDeclarationPackage()
27 changes: 1 addition & 26 deletions packages/less-api-framework/init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const adminRules = require('./rules/admin.json')
const appRules = require('./rules/app.json')
const { permissions } = require('./permissions')
const { FunctionLoader } = require('./func_loader')
const fse = require('fs-extra')
const path = require('path')


const accessor = new MongoAccessor(Config.db.database, Config.db.uri, {
useNewUrlParser: true,
Expand Down Expand Up @@ -39,8 +38,6 @@ async function main() {
await createBuiltinFunctions()

accessor.close()

createCloudFunctionDeclarationPackage()
}

main()
Expand Down Expand Up @@ -200,26 +197,4 @@ async function createBuiltinFunctions() {
}

return true
}

// 在 node_modules 中创建 云函数 sdk 包:@, 这个包是为了云函数IDE 加载类型提示文件而创建的,不可发布
function createCloudFunctionDeclarationPackage() {
const source = path.resolve(__dirname, '../dist')
const target = path.resolve(__dirname, '../node_modules/@')

fse.ensureDirSync(target)
fse.copySync(source, target)

console.log(`copy success: ${source} => ${target}`)

const packageJson = `
{
"name": "@",
"version": "0.0.0"
}
`
const pkgJsonPath = path.join(target, 'package.json')
fse.writeFileSync(pkgJsonPath, packageJson)

console.log(`write success: ${pkgJsonPath}`)
}
5 changes: 3 additions & 2 deletions packages/less-api-framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"version": "0.2.4",
"description": "less framework base on less-api",
"main": "./dist/index.js",
"typings": "/dist/index.d.ts",
"typings": "./dist/index.d.ts",
"private": "true",
"scripts": {
"start": "node ./dist/index.js",
"build": "npx tsc -p tsconfig.json",
"build": "npx tsc -p tsconfig.json && npm run create-internal-pkg",
"watch": "npx tsc -p tsconfig.json -w",
"init": "node init/index.js",
"create-internal-pkg": "node ./init/create-internal-package.js",
"prepublishOnly": "npm run build",
"trace-gc": "node --trace_gc --trace_gc_verbose ./dist/index.js",
"init-start": "npm run init && npm run start",
Expand Down

0 comments on commit 321b2f0

Please sign in to comment.