Skip to content

Build itself #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions action/bin.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
3 changes: 1 addition & 2 deletions action/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
#!/usr/bin/env node
export {};
export declare function main(): Promise<void>;
1 change: 1 addition & 0 deletions bob.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
34 changes: 29 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -11,9 +11,32 @@
"url": "[email protected]:kamilkisiela/bob.git",
"type": "git"
},
"main": "dist/index.js",
"bin": {
"bob": "dist/index.js"
"bob": "dist/bin.js"
},
"sideEffects": false,
"main": "dist/index.js",
"module": "dist/index.mjs",
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
},
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"buildOptions": {
"bin": {
"bob": {
"input": "src/bin.ts"
}
}
},
"license": "MIT",
"files": [
@@ -41,8 +64,8 @@
"yargs": "15.3.1"
},
"scripts": {
"prepublish": "yarn build",
"build": "tsc && ncc build src/action.ts -o action"
"build": "ts-node --project tsconfig.tsnode.json src/bin.ts build --single && ncc build src/action.ts -o action",
"release": "cd dist && npm publish"
},
"devDependencies": {
"@actions/core": "1.2.6",
@@ -53,7 +76,8 @@
"@types/mkdirp": "1.0.1",
"@types/node": "13.11.0",
"@types/yargs": "15.0.4",
"typescript": "3.8.3"
"typescript": "3.8.3",
"ts-node": "10.0.0"
},
"publishConfig": {
"access": "public"
3 changes: 3 additions & 0 deletions src/bin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { main } from ".";

main();
23 changes: 23 additions & 0 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
@@ -148,6 +148,29 @@ async function buildSingle({ distDir, distPath = '' }: { distDir: string; distPa
})
);

if (buildOptions?.bin) {
await Promise.all(
Object.keys(buildOptions.bin).map(async (alias) => {
const options = buildOptions.bin![alias];
const binInputOptions = {
...inputOptions,
...options,
};
// create a bundle
const binBundle = await rollup.rollup(binInputOptions);
const targetPath = pkg.bin![alias];
await binBundle.write({
...commonOutputOptions,
banner: `#!/usr/bin/env node`,
preferConst: true,
sourcemap: options.sourcemap,
file: targetPath,
format: "cjs" as const,
});
})
);
}

// move README.md and LICENSE
await copyToDist(
cwd,
6 changes: 3 additions & 3 deletions src/commands/pack-flat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import globby from "globby";
import pLimit from "p-limit";
import fs, { readJSON } from "fs-extra";
import fs from "fs-extra";
import { resolve, join } from "path";
import { execSync } from "child_process";
import { Consola } from "consola";
@@ -50,7 +50,7 @@ export const packFlatCommand = createCommand<

async function pack(packagePath: string, commit: string, config: BobConfig, reporter: Consola) {
const cwd = packagePath.replace("/package.json", "");
const pkg = await readJSON(packagePath);
const pkg = await fs.readJSON(packagePath);
const fullName: string = pkg.name;

if ((config.ignore || []).includes(fullName)) {
@@ -62,7 +62,7 @@ async function pack(packagePath: string, commit: string, config: BobConfig, repo
const bobDir = resolve(process.cwd(), ".bob-packed");

// replace version to 0.0.0-canary-${commit}
const distPkg = await readJSON(join(projectDistDir, 'package.json'));
const distPkg = await fs.readJSON(join(projectDistDir, 'package.json'));
const version = `0.0.0-canary-${commit}`;
distPkg.version = version;
await fs.writeFile(join(projectDistDir, 'package.json'), JSON.stringify(distPkg, null, 2), {
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env node
import yargs, { Argv } from "yargs";
import consola from "consola";
import { useConfig } from "./config";
@@ -10,7 +9,7 @@ import { runCommand } from "./commands/run";
import { validateCommand } from "./commands/validate";
import { runifyCommand } from "./commands/runify";

async function main() {
export async function main() {
const config = await useConfig();

const root: Argv = yargs.scriptName("bob").detectLocale(false).version();
@@ -32,4 +31,3 @@ async function main() {
.showHelpOnFail(false).argv;
}

main();
4 changes: 2 additions & 2 deletions src/rollup-plugins/auto-external.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IsExternal, Plugin } from "rollup";
import { readJSONSync } from "fs-extra";
import fs from "fs-extra";
import getBuiltins from "builtins";

type Options = {
@@ -10,7 +10,7 @@ export function autoExternal({ packageJSONPath }: Options): Plugin {
const plugin: Plugin = {
name: "auto-external",
options(opts) {
const pkg = readJSONSync(packageJSONPath);
const pkg = fs.readJSONSync(packageJSONPath);
const externalModules = [];
if (typeof pkg.dependencies === "object") {
externalModules.push(...Object.keys(pkg.dependencies));
7 changes: 5 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "commonjs",
"module": "esnext",
"strictNullChecks": true,
"target": "es2018",
"lib": ["esnext"],
@@ -15,5 +15,8 @@
"noUnusedParameters": true
},
"exclude": ["node_modules", "dist"],
"include": ["src/index.ts", "src/typings.d.ts"]
"include": ["src/index.ts", "src/bin.ts", "src/typings.d.ts"],
"ts-node": {
"transpileOnly": true
}
}
9 changes: 9 additions & 0 deletions tsconfig.tsnode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs"
},
"ts-node": {
"transpileOnly": true
}
}
79 changes: 79 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -69,6 +69,26 @@
dependencies:
estree-walker "^1.0.1"

"@tsconfig/node10@^1.0.7":
version "1.0.8"
resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.8.tgz#c1e4e80d6f964fbecb3359c43bd48b40f7cadad9"
integrity sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg==

"@tsconfig/node12@^1.0.7":
version "1.0.8"
resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.8.tgz#a883d62f049a64fea1e56a6bbe66828d11c6241b"
integrity sha512-LM6XwBhjZRls1qJGpiM/It09SntEwe9M0riXRfQ9s6XlJQG0JPGl92ET18LtGeYh/GuOtafIXqwZeqLOd0FNFQ==

"@tsconfig/node14@^1.0.0":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.1.tgz#95f2d167ffb9b8d2068b0b235302fafd4df711f2"
integrity sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg==

"@tsconfig/node16@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.1.tgz#a6ca6a9a0ff366af433f42f5f0e124794ff6b8f1"
integrity sha512-FTgBI767POY/lKNDNbIzgAX6miIDBs6NTCbdlDb8TrWovHsSvaVIZDlTqym29C6UqhzwcJx4CYr+AlrMywA0cA==

"@types/color-name@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
@@ -171,6 +191,11 @@ ansi-styles@^4.0.0:
"@types/color-name" "^1.1.1"
color-convert "^2.0.1"

arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==

array-union@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d"
@@ -201,6 +226,11 @@ braces@^3.0.1:
dependencies:
fill-range "^7.0.1"

buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==

builtin-modules@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.1.0.tgz#aad97c15131eb76b65b50ef208e7584cd76a7484"
@@ -291,6 +321,11 @@ [email protected]:
path-type "^4.0.0"
yaml "^1.7.2"

create-require@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==

[email protected]:
version "7.0.1"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.1.tgz#0ab56286e0f7c24e153d04cc2aa027e43a9a5d14"
@@ -310,6 +345,11 @@ detect-indent@^5.0.0:
resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-5.0.0.tgz#3871cc0a6a002e8c3e5b3cf7f336264675f06b9d"
integrity sha1-OHHMCmoALow+Wzz38zYmRnXwa50=

diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==

dir-glob@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f"
@@ -590,6 +630,11 @@ make-dir@^3.0.2:
dependencies:
semver "^6.0.0"

make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==

merge2@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.3.0.tgz#5b366ee83b2f1582c48f87e47cf1a9352103ca81"
@@ -845,6 +890,19 @@ sort-keys@^2.0.0:
dependencies:
is-plain-obj "^1.0.0"

source-map-support@^0.5.17:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==

spdx-correct@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.1.0.tgz#fb83e504445268f154b074e218c87c003cd31df4"
@@ -901,6 +959,22 @@ to-regex-range@^5.0.1:
dependencies:
is-number "^7.0.0"

[email protected]:
version "10.0.0"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.0.0.tgz#05f10b9a716b0b624129ad44f0ea05dac84ba3be"
integrity sha512-ROWeOIUvfFbPZkoDis0L/55Fk+6gFQNZwwKPLinacRl6tsxstTF1DbAcLKkovwnpKMVvOMHP1TIbnwXwtLg1gg==
dependencies:
"@tsconfig/node10" "^1.0.7"
"@tsconfig/node12" "^1.0.7"
"@tsconfig/node14" "^1.0.0"
"@tsconfig/node16" "^1.0.1"
arg "^4.1.0"
create-require "^1.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.17"
yn "3.1.1"

[email protected], tslib@^1.11.1:
version "1.11.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.11.1.tgz#eb15d128827fbee2841549e171f45ed338ac7e35"
@@ -1036,3 +1110,8 @@ [email protected]:
which-module "^2.0.0"
y18n "^4.0.0"
yargs-parser "^18.1.1"

[email protected]:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==