diff --git a/.gitignore b/.gitignore index dd87e2d73f9fa1fc3f4ec8b39d194d04c52c7c1a..9d656d8632d23b76f8d5a4c2fe01dbda31fe1a0b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules +.packages +.npmrc build diff --git a/arkoala/ets-plugin/package.json b/arkoala/ets-plugin/package.json index 990563885cf8690c95458728664bd6c230549670..1aa2187fba6c37cca555e5be9dc84401e09ddad9 100644 --- a/arkoala/ets-plugin/package.json +++ b/arkoala/ets-plugin/package.json @@ -9,18 +9,16 @@ "build/lib/**/*.d.ts" ], "scripts": { - "patch-ts-patch": "node ../tools/patch-ts-patch.mjs ../node_modules/ts-patch", - "patch-ohos-typescript": "cd ../node_modules/ohos-typescript && ts-patch install", - "compile": "npm run patch-ts-patch && npm run patch-ohos-typescript && node ../node_modules/ohos-typescript/bin/tsc -b .", + "compile": "node ../node_modules/@koalaui/ets-tsc/bin/ets-tsc -b .", "clean": "rimraf build dist test/dump test/generated test/ets/specification test/specification/ets2bundle", - "ets:test": "cd test/ets; ../../../node_modules/ohos-typescript/bin/tsc", + "ets:test": "cd test/ets; ../../../node_modules/@koalaui/ets-tsc/bin/ets-tsc", "test": "npm run compile && npm run ets:test && mocha --reporter-option maxDiffSize=0", "test:coverage": "nyc mocha", "canonize": "cp -r test/generated/. test/golden/", - "compile:spec": "cd test/ets && ../../../node_modules/ohos-typescript/bin/tsc -p spec-tsconfig.json", + "compile:spec": "cd test/ets && ../../../node_modules/@koalaui/ets-tsc/bin/ets-tsc -p spec-tsconfig.json", "test:spec": "npm run compile && npm run sync:spec && npm run compile:spec && mocha --config spec.mocharc.json", - "compile:sync:spec": "cd test/scripts && ../../../node_modules/typescript/bin/tsc -p tsconfig-sync-specification.json", + "compile:sync:spec": "cd test/scripts && ../../../node_modules/@koalaui/memo-tsc/bin/memo-tsc -p tsconfig-sync-specification.json", "sync:spec": "npm run compile:sync:spec && cd build/test/scripts && node sync-specification.js" }, "keywords": [], diff --git a/arkoala/ets-plugin/tsconfig.json b/arkoala/ets-plugin/tsconfig.json index 86da8a45156add8565f6b1cf4558ba0273f071fc..171b3f3c01903c9062749de715a490e5d4528f3d 100644 --- a/arkoala/ets-plugin/tsconfig.json +++ b/arkoala/ets-plugin/tsconfig.json @@ -4,8 +4,7 @@ "outDir": "build/lib", "rootDirs": ["src", "test"], "module": "CommonJS", - "moduleResolution": "node", - "baseUrl": "./ohos-typescript/node_modules" + "moduleResolution": "node" }, "include": ["src/**/*"] } diff --git a/arkoala/package.json b/arkoala/package.json index 497136a1439d89e6524bdc4f5950bfe1336a2ad6..cd6600e814ecc5f029dd8ed2dc41294617d304d6 100644 --- a/arkoala/package.json +++ b/arkoala/package.json @@ -1,31 +1,44 @@ { - "name": "workspace", - "private": true, - "workspaces": [ - "framework", - "arkui-common", - "ets-plugin", - "../incremental/build-common", - "../incremental/compat", - "../incremental/common", - "../incremental/runtime", - "../incremental/compiler-plugin", - "../incrementalets-plugin", - "../interop" - ], - "devDependencies": { - "ohos-typescript": "4.9.5-r4", - "typescript": "4.9.5", - "bin-links": "^4.0.4", - "read-package-json-fast": "^3.0.2", - "ts-patch": "^2.1.0", - "tslib": "^2.3.1", - "ts-node": "^10.7.0", - "chai": "^4.3.6", - "@types/chai": "^4.3.1" - }, - "scripts": { - "prepare": "cd node_modules/typescript && ts-patch install", - "postinstall": "node tools/force_tsc.js" - } + "name": "workspace", + "private": true, + "workspaces": [ + "framework", + "arkui-common", + "ets-plugin", + "../incremental/build-common", + "../incremental/compat", + "../incremental/common", + "../incremental/runtime", + "../incremental/compiler-plugin", + "../incrementalets-plugin", + "../interop" + ], + "devDependencies": { + "@koalaui/ets-tsc": "4.9.5-r4", + "@koalaui/memo-tsc": "4.9.5", + "ohos-typescript": "4.9.5-r4", + "typescript": "4.9.5", + "bin-links": "^4.0.4", + "read-package-json-fast": "^3.0.2", + "ts-patch": "^2.1.0", + "tslib": "^2.3.1", + "ts-node": "^10.7.0", + "chai": "^4.3.6", + "@types/chai": "^4.3.1" + }, + "scripts": { + "clean": "rimraf .packages", + "copy-tsc": "mkdir -p .packages && cp -rf ./node_modules/typescript .packages", + "copy-ohos-tsc": "mkdir -p .packages && cp -rf ./node_modules/ohos-typescript .packages", + "patch-tsc": "cd .packages/typescript && ts-patch install", + "patch-ts-patch": "node tools/patch-ts-patch.mjs ./node_modules/ts-patch", + "patch-ohos-tsc": "npm run patch-ts-patch && cd .packages/ohos-typescript && ts-patch install", + "rename-ohos-tsc": "node tools/rename_package.mjs ets-tsc .packages/ohos-typescript/", + "rename-tsc": "node tools/rename_package.mjs memo-tsc .packages/typescript/", + "pack-memo-tsc": "npm run copy-tsc && npm run patch-tsc && npm run rename-tsc && npm pack .packages/typescript/ --pack-destination .packages/", + "pack-ets-tsc": "npm run copy-ohos-tsc && npm run patch-ohos-tsc && npm run rename-ohos-tsc && npm pack .packages/ohos-typescript/ --pack-destination .packages/", + "upload-bz": "npm run pack-memo-tsc && npm run pack-ets-tsc && KOALA_BZ=1 node tools/publish.mjs", + "upload-gz": "npm run pack-memo-tsc && npm run pack-ets-tsc && KOALA_BZ=0 node tools/publish.mjs", + "upload": "npm run pack-memo-tsc && npm run pack-ets-tsc && node tools/publish.mjs" + } } diff --git a/arkoala/tools/publish.mjs b/arkoala/tools/publish.mjs new file mode 100644 index 0000000000000000000000000000000000000000..98e2290ae6431c64aa6b1519b81310c801199943 --- /dev/null +++ b/arkoala/tools/publish.mjs @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as fs from 'fs' +import path from 'path' +import process from "process" +import { execSync } from "child_process" +import chalk from "chalk" + +const CWD = process.cwd() +const packagePath = path.join(CWD, ".packages") + +const keyKoalaRegistry = "@koalaui:registry" +const koalaRegistry = "https://rnd-gitlab-msc.huawei.com/api/v4/projects/3921/packages/npm/" +const openlabRegistry = "https://nexus.bz-openlab.ru:10443/repository/koala-npm/" + +function setRegistry(key, value) { + execSync(`npm config --location project set ${key} ${value}`) +} + +function getRegistry(key) { + execSync(`npm config --location project get ${key}`) +} + +function publishToOpenlab() { + + setRegistry(keyKoalaRegistry, openlabRegistry) + setRegistry("strict-ssl", false) + + fs.readdirSync(packagePath).map(file => { + if (path.extname(file) === ".tgz") { + console.log(chalk.green(`> Publishing ${file}...`)) + execSync(`npm publish ${path.join(packagePath, file)}`) + } + }) + +} + +function publishToGitlab() { + + setRegistry(keyKoalaRegistry, koalaRegistry) + setRegistry("strict-ssl", false) + + fs.readdirSync(packagePath).map(file => { + if (path.extname(file) === ".tgz") { + console.log(chalk.green(`> Publishing ${file}...`)) + execSync(`npm publish ${path.join(packagePath, file)}`) + } + }) +} + +function publish() { + process.env.KOALA_BZ == true ? publishToOpenlab() : publishToGitlab() +} + +publish() \ No newline at end of file diff --git a/arkoala/tools/rename_package.mjs b/arkoala/tools/rename_package.mjs new file mode 100644 index 0000000000000000000000000000000000000000..1782ad652d4233965ccbdf9007d6e18d3a0e92fa --- /dev/null +++ b/arkoala/tools/rename_package.mjs @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as fs from 'fs' +import path from 'path' + +const newName = process.argv[2] +const packagePath = process.argv[3] +const packageKey = "@koalaui" + +function renamePackage() { + const packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, "package.json"))) + console.log(`> Renaming ${packageJson.name} to ${newName}`) + packageJson.name = packageKey + "/" + newName + fs.writeFileSync(path.join(packagePath, "package.json"), JSON.stringify(packageJson, null, 2), 'utf8') +} + +function renameBin() { + const tscPath = path.join(packagePath, "bin/tsc") + if (!fs.existsSync(tscPath)) throw new Error("bin/tsc not found") + const newPath = path.join(packagePath, `bin/${newName}`) + fs.renameSync(tscPath, newPath) +} + +function rename() { + if (newName !== "memo-tsc") { + renameBin() + renamePackage() + } else { + renamePackage() + } +} + +rename() \ No newline at end of file diff --git a/incremental/package.json b/incremental/package.json index 85d2922c4e39d0f3ebe267d86994bd2b93537f18..7728853206b91ea4a396da2790ae75852664f6c2 100644 --- a/incremental/package.json +++ b/incremental/package.json @@ -6,7 +6,7 @@ "compat", "common", "runtime", - "compiler-plugin", + "compiler-plugin" ], "devDependencies": { "@types/chai": "4.3.10",