-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix publishing and testing scripts (#289)
* Fix publishing and testing scripts * Update license copying code
- Loading branch information
1 parent
5e7b8b5
commit 6ded534
Showing
4 changed files
with
74 additions
and
34 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 |
---|---|---|
@@ -1,32 +1,49 @@ | ||
import * as fs from 'node:fs' | ||
import * as fs from 'node:fs/promises' | ||
import * as path from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import checker from 'license-checker' | ||
import * as pkg from '../package.json' | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
|
||
const pkg = JSON.parse( | ||
await fs.readFile(path.resolve(__dirname, '../package.json'), 'utf8'), | ||
) | ||
|
||
let exclude = [ | ||
'cpy-cli', | ||
'esbuild', | ||
'jest', | ||
'vitest', | ||
'license-checker', | ||
'prettier', | ||
'rimraf', | ||
'svelte', | ||
'tsup', | ||
'@microsoft/api-extractor', | ||
] | ||
|
||
checker.init({ start: path.resolve(__dirname, '..') }, (_err, packages) => { | ||
for (let key in packages) { | ||
let name = key.split(/(?<=.)@/)[0] | ||
if ( | ||
name in pkg.devDependencies && | ||
!exclude.includes(name) && | ||
packages[key].licenseFile | ||
) { | ||
let dir = path.resolve(__dirname, '../dist/licenses', name) | ||
fs.mkdirSync(dir, { recursive: true }) | ||
fs.copyFileSync( | ||
packages[key].licenseFile, | ||
path.resolve(dir, path.basename(packages[key].licenseFile)), | ||
) | ||
/** @type {checker.ModuleInfo} */ | ||
let packages = await new Promise((resolve, reject) => { | ||
checker.init({ start: path.resolve(__dirname, '..') }, (_err, packages) => { | ||
if (_err) { | ||
reject(_err) | ||
} else { | ||
resolve(packages) | ||
} | ||
} | ||
}) | ||
}) | ||
|
||
for (let key in packages) { | ||
let dep = packages[key] | ||
let name = key.split(/(?<=.)@/)[0] | ||
|
||
if (exclude.includes(name)) continue | ||
if (!dep.licenseFile) continue | ||
if (!(name in pkg.devDependencies)) continue | ||
|
||
let dir = path.resolve(__dirname, '../dist/licenses', name) | ||
await fs.mkdir(dir, { recursive: true }) | ||
await fs.copyFile( | ||
dep.licenseFile, | ||
path.resolve(dir, path.basename(dep.licenseFile)), | ||
) | ||
} |
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 |
---|---|---|
@@ -1,18 +1,28 @@ | ||
import { execSync } from 'node:child_process' | ||
import * as fs from 'node:fs' | ||
import { exec } from 'node:child_process' | ||
import * as fs from 'node:fs/promises' | ||
import * as path from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { promisify } from 'node:util' | ||
|
||
const __filename = fileURLToPath(import.meta.url) | ||
const __dirname = path.dirname(__filename) | ||
const execAsync = promisify(exec) | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
|
||
let fixturesDir = path.resolve(__dirname, '../tests/fixtures') | ||
let fixtures = fs | ||
.readdirSync(fixturesDir) | ||
.map((name) => path.join(fixturesDir, name)) | ||
let fixtureDirs = await fs.readdir(fixturesDir) | ||
let fixtures = fixtureDirs.map((name) => path.join(fixturesDir, name)) | ||
|
||
await Promise.all( | ||
fixtures.map(async (fixture) => { | ||
let exists = await fs.access(path.join(fixture, 'package.json')).then( | ||
() => true, | ||
() => false, | ||
) | ||
|
||
if (!exists) return | ||
|
||
console.log(`Installing dependencies for ${fixture}`) | ||
|
||
for (let fixture of fixtures) { | ||
if (fs.existsSync(path.join(fixture, 'package.json'))) { | ||
execSync('npm install', { cwd: fixture }) | ||
} | ||
} | ||
await execAsync('npm install', { cwd: fixture }) | ||
}), | ||
) |
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