diff --git a/src/commands/build.ts b/src/commands/build.ts index 2dbfd8d4..5ad6f043 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -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; @@ -37,6 +36,11 @@ export const build: CommandModule = { 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`, @@ -74,6 +78,7 @@ export async function buildHandler({ provider, timeout, upload_to, + build_dir, skip_save, skip_upload, require_git_data, @@ -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, diff --git a/src/commands/githubActions/build/index.ts b/src/commands/githubActions/build/index.ts index 1a967de9..0f6f9b08 100644 --- a/src/commands/githubActions/build/index.ts +++ b/src/commands/githubActions/build/index.ts @@ -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"; @@ -74,6 +74,7 @@ export async function gaBuildHandler({ await buildHandler({ provider: "dappnode", upload_to: "ipfs", + build_dir: defaultBuildDir, skip_save: true, verbose: true }); @@ -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 diff --git a/src/commands/init.ts b/src/commands/init.ts index f6e6743e..4246073e 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -10,6 +10,7 @@ import defaultAvatar from "../assets/defaultAvatar"; import { shell } from "../utils/shell"; import { releasesRecordFileName } from "../utils/releaseRecord"; import { + defaultBuildDir, defaultComposeFileName, defaultDir, defaultManifestFileName, @@ -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; @@ -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")); } } diff --git a/src/commands/publish.ts b/src/commands/publish.ts index b37922d9..fad1a07e 100644 --- a/src/commands/publish.ts +++ b/src/commands/publish.ts @@ -1,4 +1,3 @@ -import path from "path"; import Listr from "listr"; import chalk from "chalk"; import { CommandModule } from "yargs"; @@ -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"; @@ -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; @@ -67,6 +72,11 @@ export const publish: CommandModule = { 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`, @@ -130,6 +140,7 @@ export async function publishHanlder({ developer_address, timeout, upload_to, + build_dir, github_release, dappnode_team_preset, require_git_data, @@ -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; @@ -217,7 +229,6 @@ export async function publishHanlder({ else throw e; } ctx.nextVersion = nextVersion; - ctx.buildDir = path.join(dir, `build_${nextVersion}`); task.title = task.title + ` (next version: ${nextVersion})`; } }, @@ -225,12 +236,12 @@ export async function publishHanlder({ // 2. Build and upload { title: "Build and upload", - task: ctx => + task: () => new Listr( buildAndUpload({ dir, composeFileName, - buildDir: ctx.buildDir, + buildDir, contentProvider, uploadTo, userTimeout, @@ -265,7 +276,7 @@ export async function publishHanlder({ createGithubRelease({ dir, compose_file_name, - buildDir: ctx.buildDir, + buildDir, releaseMultiHash: ctx.releaseMultiHash, verbose, silent diff --git a/src/params.ts b/src/params.ts index fed298e4..30621395 100644 --- a/src/params.ts +++ b/src/params.ts @@ -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 = "./"; diff --git a/src/releaseUploader/pinata/addDirFromFs.ts b/src/releaseUploader/pinata/addDirFromFs.ts index 2fb5b0b9..b28bc7d7 100644 --- a/src/releaseUploader/pinata/addDirFromFs.ts +++ b/src/releaseUploader/pinata/addDirFromFs.ts @@ -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..." diff --git a/src/tasks/createGithubRelease.ts b/src/tasks/createGithubRelease.ts index cffd311f..3f51904e 100644 --- a/src/tasks/createGithubRelease.ts +++ b/src/tasks/createGithubRelease.ts @@ -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); } } diff --git a/src/utils/compactManifest.ts b/src/utils/compactManifest.ts index 6a461696..2a4b7ea8 100644 --- a/src/utils/compactManifest.ts +++ b/src/utils/compactManifest.ts @@ -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 }); diff --git a/test/commands/build.test.ts b/test/commands/build.test.ts index b661f80c..bd71ac83 100644 --- a/test/commands/build.test.ts +++ b/test/commands/build.test.ts @@ -31,6 +31,7 @@ describe("Init and build", function () { dir: testDir, provider: contentProvider, upload_to: "ipfs", + build_dir: "build", timeout: "5min", verbose: true });