-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22954ad
commit 4c59a0e
Showing
6 changed files
with
115 additions
and
26 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
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,52 @@ | ||
import {ctx} from 'zx-extra' | ||
import {ctx, tempy, fs} from 'zx-extra' | ||
import {copy} from 'git-glob-cp' | ||
import ini from 'ini' | ||
import {traverseDeps} from './deps.js' | ||
import {parseEnv} from './publish.js' | ||
|
||
export const build = (pkg, packages) => ctx(async ($) => { | ||
if (pkg.built) return true | ||
|
||
await traverseDeps(pkg, packages, async (_, {pkg}) => build(pkg, packages)) | ||
|
||
if (pkg.manifest.scripts?.build && pkg.manifest?.release?.build) { | ||
$.cwd = pkg.absPath | ||
await $`npm run build` | ||
console.log(`built '${pkg.name}'`) | ||
if (pkg.changes?.length === 0 && pkg.manifest?.release?.fetch) await fetchPkg(pkg) | ||
|
||
if (!pkg.fetched) { | ||
$.cwd = pkg.absPath | ||
await $`npm run build` | ||
console.log(`built '${pkg.name}'`) | ||
} | ||
} | ||
|
||
pkg.built = true | ||
|
||
return true | ||
}) | ||
|
||
const fetchPkg = (pkg) => ctx(async ($) => { | ||
try { | ||
const cwd = pkg.absPath | ||
const {npmRegistry} = parseEnv($.env) | ||
const temp = tempy.temporaryDirectory() | ||
const npmrc = ini.parse(await fs.readFile(`${cwd}/.npmrc`, 'utf8')) | ||
const token = getAuthToken(npmRegistry, npmrc) | ||
const auth = `Authorization: Bearer ${token}` | ||
const tarball = getTarballUrl(npmRegistry, pkg.name, pkg.version) | ||
|
||
await $`wget --header=${auth} -qO- ${tarball} | tar xvz -C ${temp}` | ||
await copy({from: ['**/*', '!package.json'], to: cwd, cwd: `${temp}/package`}) | ||
|
||
pkg.fetched = true | ||
console.log(`fetched '${pkg.name}@${pkg.version}'`) | ||
} catch (e) { | ||
console.log(`fetching '${pkg.name}@${pkg.version}' failed`, e) | ||
} | ||
}) | ||
|
||
// NOTE registry-auth-token does not work with localhost:4873 | ||
const getAuthToken = (registry, npmrc) => | ||
(Object.entries(npmrc).find(([reg]) => reg.startsWith(registry.replace(/^https?/, ''))) || [])[1] | ||
|
||
// $`npm view ${name}@${version} dist.tarball` | ||
const getTarballUrl = (registry, name, version) => `${registry}/${name}/-/${name.replace(/^.+(%2f|\/)/,'')}-${version}.tgz` |
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 |
---|---|---|
|
@@ -30,24 +30,33 @@ export const createFakeRepo = async ({cwd = tempy.temporaryDirectory(), commits | |
$.cwd = cwd | ||
await $`git init` | ||
|
||
for (let {msg, files, name = 'Semrel-extra Bot', email = '[email protected]', tags = []} of commits) { | ||
await $`git config user.name ${name}` | ||
await $`git config user.email ${email}` | ||
for (let {relpath, contents} of files) { | ||
const _contents = typeof contents === 'string' ? contents : JSON.stringify(contents, null, 2) | ||
await fs.outputFile(path.resolve(cwd, relpath), _contents) | ||
} | ||
await $`git add .` | ||
await $`git commit -m ${msg}` | ||
|
||
for (let tag of tags) { | ||
await $`git tag ${tag} -m ${tag}` | ||
} | ||
} | ||
await addCommits({cwd, commits}) | ||
|
||
const bare = tempy.temporaryDirectory() | ||
await $`git init --bare ${bare}` | ||
await $`git remote add origin ${bare}` | ||
|
||
return cwd | ||
}) | ||
|
||
export const addCommits = async ({cwd, commits = []}) => ctx(async ($) => { | ||
$.cwd = cwd | ||
|
||
for (let {msg, files, name = 'Semrel-extra Bot', email = '[email protected]', tags = []} of commits) { | ||
await $`git config user.name ${name}` | ||
await $`git config user.email ${email}` | ||
for (let {relpath, contents} of files) { | ||
const _contents = typeof contents === 'string' ? contents : JSON.stringify(contents, null, 2) | ||
const file = path.resolve(cwd, relpath) | ||
await fs.outputFile(file, _contents) | ||
|
||
await $`git add ${file}` | ||
} | ||
|
||
await $`git commit -m ${msg}` | ||
|
||
for (let tag of tags) { | ||
await $`git tag ${tag} -m ${tag}` | ||
} | ||
} | ||
}) |
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 |
---|---|---|
|
@@ -1174,10 +1174,10 @@ getpass@^0.1.1: | |
dependencies: | ||
assert-plus "^1.0.0" | ||
|
||
git-glob-cp@^1.6.2: | ||
version "1.6.2" | ||
resolved "https://registry.yarnpkg.com/git-glob-cp/-/git-glob-cp-1.6.2.tgz#1cf9831b2377cdca21007fa0ea8183896ac231b1" | ||
integrity sha512-XUgdmBDHC6v5m3mt9LB5prldOYLMZG5tPRacxIN256xhFh6O3ltGebWmpad9Julm7LAawI+sTa/FEUte7Hq0sg== | ||
git-glob-cp@^1.7.1: | ||
version "1.7.1" | ||
resolved "https://registry.yarnpkg.com/git-glob-cp/-/git-glob-cp-1.7.1.tgz#9019b574e8e5908bed5af46e7efcf07b0a3dfd3b" | ||
integrity sha512-UmcMdJMOzGa/mV7zdU2wHjZ3Yz0SWYyAmEZ+Z3K4mA+DHFWd+rBgOid4vGQ/jbSjHKodLx8BMxOHawdUrlYMCw== | ||
dependencies: | ||
tar "^6.1.11" | ||
zx-extra "^1.7.0" | ||
|
@@ -1380,6 +1380,11 @@ inherits@2, [email protected]: | |
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" | ||
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== | ||
|
||
ini@^3.0.0: | ||
version "3.0.0" | ||
resolved "https://registry.yarnpkg.com/ini/-/ini-3.0.0.tgz#2f6de95006923aa75feed8894f5686165adc08f1" | ||
integrity sha512-TxYQaeNW/N8ymDvwAxPyRbhMBtnEwuvaTYpOQkFx1nSeusgezHniEc/l35Vo4iCq/mMiTJbpD7oYxN98hFlfmw== | ||
|
||
ip-regex@^2.1.0: | ||
version "2.1.0" | ||
resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-2.1.0.tgz#fa78bf5d2e6913c911ce9f819ee5146bb6d844e9" | ||
|