Skip to content

Commit 563e427

Browse files
committed
Refactor ACG tool for NPM
1 parent 9e86356 commit 563e427

File tree

12 files changed

+1396
-214
lines changed

12 files changed

+1396
-214
lines changed

.github/workflows/publish.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
Prerelease: ${{ github.event.inputs.prerelease || 'false' }}
2828
PushPackage: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/master') || github.event.inputs.push }}
2929
NpmTokenExists: ${{ secrets.NPM_TOKEN != '' }}
30+
Platforms: "linux-x64 linux-musl-x64 osx-x64 osx-arm64"
3031

3132
steps:
3233
- uses: actions/checkout@v4
@@ -65,9 +66,31 @@ jobs:
6566
run: |
6667
ROOT=$(pwd)
6768
cd src/ApiCodeGenerator.Npm
69+
npm install
6870
npm version ${GitVersion_FullSemVer} --no-git-tag-version
6971
npm run pack-ci -- ${ROOT}/${PackageOutputDir}
7072
73+
- name: Pack Npm Binaries
74+
run: |
75+
ROOT=$(pwd)
76+
for PLATFORM in ${{ env.Platforms }}; do
77+
echo "Building for platform: $PLATFORM"
78+
dotnet publish src/ApiCodeGenerator.MSBuild \
79+
-c Release \
80+
-f net8.0 \
81+
-r $PLATFORM \
82+
--self-contained \
83+
-p:PublishTrimmed=false \
84+
-o ./bin/publish/$PLATFORM
85+
86+
# Create tgz archive with platform name only
87+
cd ./bin/publish/$PLATFORM
88+
tar -czf $ROOT/${PackageOutputDir}/${PLATFORM}.tgz *
89+
cd $ROOT
90+
91+
echo "Created archive: ${PLATFORM}.tgz"
92+
done
93+
7194
- name: Nuget Push
7295
if: env.PushPackage == 'true'
7396
working-directory: ${{ env.PackageOutputDir }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
bin/
77
obj/
88
binaries/
9+
coverage/
910
dist/
1011
node_modules/
1112

1213
*.user
1314
msbuild.binlog
1415
package-lock.json
16+
acg.js
17+
acg.d.ts

ApiCodeGenerator.code-workspace

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "."
5+
},
6+
{
7+
"path": "src/ApiCodeGenerator.Npm"
8+
}
9+
],
10+
"settings": {
11+
"autoHide.hideSideBarsOnDebug": false,
12+
"autoHide.hidePanelOnDebug": false
13+
}
14+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
msbuild.binlog
22
dist/
3+
coverage/
4+
tsconfig.base.json
5+
tsconfig.json
6+
jest.config.js
7+
*.ts
8+
!*.d.ts
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env node
2+
"use strict"
3+
4+
const acg = require("./acg");
5+
const fs = require("fs");
6+
7+
const enableVerbose = process.argv.indexOf("-v") > -1;
8+
9+
/**
10+
* Get command line argument value
11+
* @param {string} name - Argument name
12+
* @returns {string | undefined } Argument value
13+
*/
14+
function getArgument(name) {
15+
var flags = process.argv.slice(2),
16+
index = flags.lastIndexOf(name);
17+
18+
if (index === -1 || index + 1 >= flags.length) {
19+
return undefined;
20+
}
21+
22+
return flags[index + 1];
23+
}
24+
25+
/** @param {(Error & {status?: number}) | number} error */
26+
function handleError(error) {
27+
if (error) {
28+
if (typeof error === "number") {
29+
process.exit(error);
30+
} else {
31+
if (!(error instanceof acg.AcgError)) {
32+
console.error("Unexpected error");
33+
}
34+
console.error(error.message);
35+
enableVerbose && console.trace(error);
36+
}
37+
process.exit(error.status && typeof error.status === "number" ? error.status : 1);
38+
}
39+
}
40+
41+
let rc = {};
42+
if (fs.existsSync(".acgrc")) {
43+
var json = fs.readFileSync(".acgrc");
44+
if (json) {
45+
try {
46+
//@ts-ignore
47+
rc = JSON.parse(json)
48+
}
49+
catch (err) {
50+
console.error("Error loading .acgrc file");
51+
//@ts-ignore
52+
handleError(err);
53+
}
54+
}
55+
}
56+
57+
const opt = {
58+
acgBinaryDir: getArgument("--acg-binary-dir")
59+
|| acg.getAcgBinaryDir(rc),
60+
acgBinarySite: getArgument("--acg-binary-site")
61+
|| acg.getAcgBinarySite(rc),
62+
noDownloadBinary: process.argv.indexOf("--no-download-acg-binary") > -1
63+
|| acg.getNoDownloadBinary(rc)
64+
};
65+
66+
enableVerbose && acg.enableVerbose();
67+
68+
acg
69+
.run(process.cwd(), rc, opt)
70+
.catch(handleError);

src/ApiCodeGenerator.Npm/acg.js

Lines changed: 0 additions & 208 deletions
This file was deleted.

0 commit comments

Comments
 (0)