Skip to content

Commit

Permalink
Fix publishing and testing scripts (#289)
Browse files Browse the repository at this point in the history
* Fix publishing and testing scripts

* Update license copying code
  • Loading branch information
thecrypticace committed Jun 11, 2024
1 parent 5e7b8b5 commit 6ded534
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 34 deletions.
53 changes: 35 additions & 18 deletions scripts/copy-licenses.js
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)),
)
}
34 changes: 22 additions & 12 deletions scripts/install-fixture-deps.js
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 })
}),
)
9 changes: 8 additions & 1 deletion scripts/release-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
// 1.2.3 -> latest (default)
// 0.0.0-insiders.ffaa88 -> insiders
// 4.1.0-alpha.4 -> alpha
import * as fs from 'node:fs/promises'
import * as path from 'node:path'
import { fileURLToPath } from 'node:url'

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 version = process.argv[2] || process.env.npm_package_version || pkg.version

Expand Down
12 changes: 9 additions & 3 deletions scripts/release-notes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
// Given a version, figure out what the release notes are so that we can use this to pre-fill the
// relase notes on a GitHub release for the current version.

import * as fs from 'node:fs'
import * as fs from 'node:fs/promises'
import * as path from 'node:path'
import * as pkg from '../package.json'
import { fileURLToPath } from 'node:url'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

const pkg = JSON.parse(
await fs.readFile(path.resolve(__dirname, '../package.json'), 'utf8'),
)

let version = process.argv[2] || process.env.npm_package_version || pkg.version

let changelog = fs.readFileSync(
let changelog = await fs.readFile(
path.resolve(__dirname, '..', 'CHANGELOG.md'),
'utf8',
)
Expand Down

0 comments on commit 6ded534

Please sign in to comment.