Skip to content
Closed
Show file tree
Hide file tree
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
15 changes: 9 additions & 6 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import path from "path";
import chalk from "chalk";
import { CommandModule } from "yargs";
import Listr from "listr";
// Tasks
import { buildAndUpload } from "../tasks/buildAndUpload";
// Utils
import { getCurrentLocalVersion } from "../utils/versions/getCurrentLocalVersion";
import { getInstallDnpLink } from "../utils/getLinks";
import { CliGlobalOptions } from "../types";
import { UploadTo } from "../releaseUploader";
import { defaultComposeFileName, defaultDir } from "../params";
import { defaultBuildDir, defaultComposeFileName, defaultDir } from "../params";

interface CliCommandOptions extends CliGlobalOptions {
provider: string;
upload_to: UploadTo;
build_dir: string;
timeout?: string;
skip_save?: boolean;
skip_upload?: boolean;
Expand All @@ -37,6 +36,11 @@ export const build: CommandModule<CliGlobalOptions, CliCommandOptions> = {
choices: ["ipfs", "swarm"] as UploadTo[],
default: "ipfs" as UploadTo
},
build_dir: {
description: "Target directory to write build files",
default: defaultBuildDir,
normalize: true
},
timeout: {
alias: "t",
description: `Overrides default build timeout: "15h", "20min 15s", "5000". Specs npmjs.com/package/timestring`,
Expand Down Expand Up @@ -74,6 +78,7 @@ export async function buildHandler({
provider,
timeout,
upload_to,
build_dir,
skip_save,
skip_upload,
require_git_data,
Expand All @@ -91,13 +96,11 @@ export async function buildHandler({
const skipSave = skip_save;
const skipUpload = skip_save || skip_upload;
const composeFileName = compose_file_name;
const nextVersion = getCurrentLocalVersion({ dir });
const buildDir = path.join(dir, `build_${nextVersion}`);

const buildTasks = new Listr(
buildAndUpload({
dir,
buildDir,
buildDir: build_dir,
contentProvider,
uploadTo,
userTimeout,
Expand Down
4 changes: 3 additions & 1 deletion src/commands/githubActions/build/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandModule } from "yargs";
import { CliGlobalOptions } from "../../../types";
import { defaultDir } from "../../../params";
import { defaultBuildDir, defaultDir } from "../../../params";
import { getGithubContext } from "../../../providers/github/githubActions";
import { buildHandler } from "../../build";
import { Github } from "../../../providers/github/Github";
Expand Down Expand Up @@ -74,6 +74,7 @@ export async function gaBuildHandler({
await buildHandler({
provider: "dappnode",
upload_to: "ipfs",
build_dir: defaultBuildDir,
skip_save: true,
verbose: true
});
Expand All @@ -99,6 +100,7 @@ export async function buildAndComment({
const { releaseMultiHash } = await buildHandler({
provider: "pinata",
upload_to: "ipfs",
build_dir: defaultBuildDir,
require_git_data: true,
delete_old_pins: true,
verbose: true
Expand Down
20 changes: 12 additions & 8 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import defaultAvatar from "../assets/defaultAvatar";
import { shell } from "../utils/shell";
import { releasesRecordFileName } from "../utils/releaseRecord";
import {
defaultBuildDir,
defaultComposeFileName,
defaultDir,
defaultManifestFileName,
Expand Down Expand Up @@ -46,11 +47,7 @@ ENTRYPOINT echo "happy buidl $USERNAME!"

// .gitignore
const gitignorePath = ".gitignore";
const gitignoreCheck = "build_*";
const gitignoreData = `# DAppNodeSDK release directories
build_*
${releasesRecordFileName}
`;
const gitignorePaths = [defaultBuildDir, releasesRecordFileName];

interface CliCommandOptions extends CliGlobalOptions {
yes?: boolean;
Expand Down Expand Up @@ -267,9 +264,16 @@ function getDnpName(name: string): string {
function writeGitIgnore(filepath: string) {
if (fs.existsSync(filepath)) {
const currentGitignore = fs.readFileSync(filepath, "utf8");
if (!currentGitignore.includes(gitignoreCheck))
fs.writeFileSync(filepath, currentGitignore + gitignoreData);
const currentGitignorePaths = currentGitignore.split("\n");

for (const gitignorePath of gitignorePaths) {
if (!currentGitignorePaths.includes(gitignorePath)) {
currentGitignorePaths.push(gitignorePath);
}
}

fs.writeFileSync(filepath, currentGitignorePaths.join("\n"));
} else {
fs.writeFileSync(filepath, gitignoreData);
fs.writeFileSync(filepath, gitignorePaths.join("\n"));
}
}
23 changes: 17 additions & 6 deletions src/commands/publish.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import path from "path";
import Listr from "listr";
import chalk from "chalk";
import { CommandModule } from "yargs";
Expand All @@ -11,7 +10,12 @@ import { getCurrentLocalVersion } from "../utils/versions/getCurrentLocalVersion
import { increaseFromApmVersion } from "../utils/versions/increaseFromApmVersion";
import { verifyEthConnection } from "../utils/verifyEthConnection";
import { getInstallDnpLink, getPublishTxLink } from "../utils/getLinks";
import { defaultComposeFileName, defaultDir, YargsError } from "../params";
import {
defaultBuildDir,
defaultComposeFileName,
defaultDir,
YargsError
} from "../params";
import { CliGlobalOptions, ReleaseType, releaseTypes, TxData } from "../types";
import { printObject } from "../utils/print";
import { UploadTo } from "../releaseUploader";
Expand All @@ -24,6 +28,7 @@ interface CliCommandOptions extends CliGlobalOptions {
eth_provider: string;
content_provider: string;
upload_to: UploadTo;
build_dir: string;
developer_address?: string;
timeout?: string;
github_release?: boolean;
Expand Down Expand Up @@ -67,6 +72,11 @@ export const publish: CommandModule<CliGlobalOptions, CliCommandOptions> = {
choices: ["ipfs", "swarm"],
default: "ipfs" as UploadTo
})
.option("build_dir", {
description: "Target directory to write build files",
default: defaultBuildDir,
normalize: true
})
.option("developer_address", {
alias: "a",
description: `If there is no existing repo for this DNP the publish command needs a developer address. If it is not provided as an option a prompt will request it`,
Expand Down Expand Up @@ -130,6 +140,7 @@ export async function publishHanlder({
developer_address,
timeout,
upload_to,
build_dir,
github_release,
dappnode_team_preset,
require_git_data,
Expand All @@ -154,6 +165,7 @@ export async function publishHanlder({
const composeFileName = compose_file_name;
const requireGitData = require_git_data;
const deleteOldPins = delete_old_pins;
const buildDir = build_dir;

const isCi = process.env.CI;
const tag = process.env.TRAVIS_TAG || process.env.GITHUB_REF;
Expand Down Expand Up @@ -217,20 +229,19 @@ export async function publishHanlder({
else throw e;
}
ctx.nextVersion = nextVersion;
ctx.buildDir = path.join(dir, `build_${nextVersion}`);
task.title = task.title + ` (next version: ${nextVersion})`;
}
},

// 2. Build and upload
{
title: "Build and upload",
task: ctx =>
task: () =>
new Listr(
buildAndUpload({
dir,
composeFileName,
buildDir: ctx.buildDir,
buildDir,
contentProvider,
uploadTo,
userTimeout,
Expand Down Expand Up @@ -265,7 +276,7 @@ export async function publishHanlder({
createGithubRelease({
dir,
compose_file_name,
buildDir: ctx.buildDir,
buildDir,
releaseMultiHash: ctx.releaseMultiHash,
verbose,
silent
Expand Down
4 changes: 4 additions & 0 deletions src/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export class YargsError extends Error {}

export const branchNameRoot = "dappnodebot/bump-upstream/";

// SDK params

export const defaultBuildDir = "./build";

// DAppNode params

export const defaultDir = "./";
Expand Down
2 changes: 1 addition & 1 deletion src/releaseUploader/pinata/addDirFromFs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PinataMetadata, PinataOptions, IpfsUploadResult } from "./PinataSDK";

/**
* Uploads a directory or file from the fs
* @param dirOrFilePath "build_0.1.0/"
* @param dirOrFilePath "./build"
* @param pinataUrl "https://api.pinata.cloud"
* @param onProgress Reports upload progress, 0.4631
* @returns "/ipfs/Qm..."
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/createGithubRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function createGithubRelease({
});

// Clean content hash file so the directory uploaded to IPFS is the same
// as the local build_* dir. User can then `ipfs add -r` and get the same hash
// as the local ./build dir. User can then `ipfs add -r` and get the same hash
fs.unlinkSync(contentHashPath);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/compactManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { readManifest, writeManifest } from "./manifest";
/**
* Reads manifest and extra files in `buildDir` compacts them in the manifest
* and writes the resulting manifest in `buildDir`
* @param buildDir `build_0.1.0`
* @param buildDir `./build`
*/
export function compactManifestIfCore(buildDir: string): void {
const { manifest, format } = readManifest({ dir: buildDir });
Expand Down
1 change: 1 addition & 0 deletions test/commands/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe("Init and build", function () {
dir: testDir,
provider: contentProvider,
upload_to: "ipfs",
build_dir: "build",
timeout: "5min",
verbose: true
});
Expand Down