-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: download npm node native modules
- Loading branch information
1 parent
aa3812e
commit aa4f94f
Showing
10 changed files
with
156 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,15 +15,7 @@ jobs: | |
|
||
strategy: | ||
matrix: | ||
os: [macos-13, macos-latest, windows-latest, ubuntu-latest] | ||
arch: [x64, arm64] | ||
exclude: | ||
- os: windows-latest | ||
arch: arm64 | ||
- os: macos-latest | ||
arch: x64 | ||
- os: macos-13 | ||
arch: arm64 | ||
os: [macos-latest, windows-latest, ubuntu-latest] | ||
|
||
steps: | ||
- name: Check out Git repository | ||
|
@@ -33,7 +25,6 @@ jobs: | |
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
arch: ${{ matrix.arch }} | ||
|
||
- name: Install corepack | ||
run: corepack enable && corepack prepare [email protected] --activate | ||
|
@@ -57,32 +48,34 @@ jobs: | |
|
||
- name: Build Linux | ||
if: matrix.os == 'ubuntu-latest' | ||
run: yarn build:linux | ||
run: | | ||
yarn download:npm linux | ||
yarn build:linux | ||
env: | ||
GH_TOKEN: ${{ secrets.GH_TOKEN }} | ||
ARCH: ${{ matrix.arch }} | ||
|
||
- name: Build Mac | ||
if: matrix.os == 'macos-13' || matrix.os == 'macos-latest' | ||
run: yarn build:mac && mv dist/latest-mac.yml dist/latest-mac-${{ matrix.arch }}.yml | ||
if: matrix.os == 'macos-latest' | ||
run: | | ||
yarn download:npm darwin | ||
yarn build:mac | ||
env: | ||
CSC_LINK: ${{ secrets.CSC_LINK }} | ||
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }} | ||
APPLE_ID: ${{ vars.APPLE_ID }} | ||
APPLE_APP_SPECIFIC_PASSWORD: ${{ vars.APPLE_APP_SPECIFIC_PASSWORD }} | ||
APPLE_TEAM_ID: ${{ vars.APPLE_TEAM_ID }} | ||
GH_TOKEN: ${{ secrets.GH_TOKEN }} | ||
ARCH: ${{ matrix.arch }} | ||
|
||
- name: Build Windows | ||
if: matrix.os == 'windows-latest' | ||
run: yarn build:win | ||
env: | ||
GH_TOKEN: ${{ secrets.GH_TOKEN }} | ||
ARCH: ${{ matrix.arch }} | ||
|
||
- name: Replace spaces in filenames | ||
run: node scripts/replaceSpaces.js | ||
run: node scripts/replace-spaces.js | ||
|
||
- name: Release | ||
uses: softprops/action-gh-release@v2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const { Arch } = require('electron-builder') | ||
const { default: removeLocales } = require('./remove-locales') | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
exports.default = async function (context) { | ||
await removeLocales(context) | ||
const platform = context.packager.platform.name | ||
const arch = context.arch | ||
|
||
if (platform === 'mac') { | ||
const nodeModulesPath = path.join( | ||
context.appOutDir, | ||
'Cherry Studio.app', | ||
'Contents', | ||
'Resources', | ||
'app.asar.unpacked', | ||
'node_modules', | ||
'@libsql' | ||
) | ||
|
||
keepLibsqlNodeModules(nodeModulesPath, arch === Arch.arm64 ? ['darwin-arm64'] : ['darwin-x64']) | ||
} | ||
|
||
if (platform === 'linux') { | ||
const nodeModulesPath = path.join(context.appOutDir, 'resources', 'app.asar.unpacked', 'node_modules', '@libsql') | ||
keepLibsqlNodeModules( | ||
nodeModulesPath, | ||
arch === Arch.arm64 ? ['linux-arm64-gnu', 'linux-arm64-musl'] : ['linux-x64-gnu', 'linux-x64-musl'] | ||
) | ||
} | ||
} | ||
|
||
function keepLibsqlNodeModules(modulePath, arch) { | ||
const dirs = fs.readdirSync(modulePath) | ||
dirs | ||
.filter((dir) => !arch.includes(dir)) | ||
.forEach((dir) => { | ||
fs.rmSync(path.join(modulePath, dir), { recursive: true, force: true }) | ||
console.log(`Removed dir: ${dir}`, arch) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { downloadNpmPackage } = require('./utils') | ||
|
||
async function downloadNpm(platform) { | ||
if (!platform || platform === 'darwin') { | ||
downloadNpmPackage('@libsql', '0.4.7', 'darwin', ['arm64', 'x64']) | ||
} | ||
|
||
if (!platform || platform === 'linux') { | ||
downloadNpmPackage('@libsql', '0.4.7', 'linux', ['arm64-gnu', 'x64-gnu']) | ||
} | ||
} | ||
|
||
const platformArg = process.argv[2] | ||
downloadNpm(platformArg) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const os = require('os') | ||
|
||
function downloadNpmPackage(package, version, platform, architectures = ['x64', 'arm64']) { | ||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'npm-download-')) | ||
|
||
for (const arch of architectures) { | ||
const targetDir = path.join('./node_modules/', package, `${platform}-${arch}`) | ||
|
||
// Skip if directory already exists | ||
if (fs.existsSync(targetDir)) { | ||
console.log(`${targetDir} already exists, skipping download...`) | ||
continue | ||
} | ||
|
||
const filename = path.join(tempDir, `${platform}-${arch}-${version}.tgz`) | ||
const url = `https://registry.npmjs.org/${package}/${platform}-${arch}/-/${platform}-${arch}-${version}.tgz` | ||
|
||
try { | ||
console.log(`Downloading ${filename}...`, url) | ||
const { execSync } = require('child_process') | ||
execSync(`curl --fail -o ${filename} ${url}`) | ||
|
||
console.log(`Extracting ${filename}...`) | ||
execSync(`tar -xvf ${filename}`) | ||
execSync(`rm -rf ${filename}`) | ||
execSync(`mv package ${targetDir}`) | ||
} catch (error) { | ||
console.error(`Error processing ${filename}: ${error.message}`) | ||
if (fs.existsSync(filename)) { | ||
fs.unlinkSync(filename) | ||
} | ||
throw error | ||
} | ||
} | ||
|
||
fs.rmSync(tempDir, { recursive: true, force: true }) | ||
} | ||
|
||
module.exports = { | ||
downloadNpmPackage | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters