How to use the @atomist/sdm/api-helper/misc/spawned.spawnAndWatch function in @atomist/sdm

To help you get started, we’ve selected a few @atomist/sdm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github atomist / sdm-core / src / pack / docker / executeDockerBuild.ts View on Github external
if (options.push) {

        if (!options.user || !options.password) {
            const message = "Required configuration missing for pushing docker image. Please make sure to set " +
                "'registry', 'user' and 'password' in your configuration.";
            progressLog.write(message);
            return { code: 1, message };
        }

        const loginArgs: string[] = ["login", "--username", options.user, "--password", options.password];
        if (/[^A-Za-z0-9]/.test(options.registry)) {
            loginArgs.push(options.registry);
        }

        // 2. run docker login
        let result = await spawnAndWatch(
            {
                command: "docker",
                args: loginArgs,
            },
            {},
            progressLog,
            {
                ...spOpts,
                logCommand: false,
            });

        if (result.code !== 0) {
            return result;
        }

        // 3. run docker push
github atomist / sdm-core / src / pack / docker / executeDockerBuild.ts View on Github external
command: "docker",
                args: loginArgs,
            },
            {},
            progressLog,
            {
                ...spOpts,
                logCommand: false,
            });

        if (result.code !== 0) {
            return result;
        }

        // 3. run docker push
        result = await spawnAndWatch(
            {
                command: "docker",
                args: ["push", image],
            },
            {},
            progressLog,
            spOpts);

        if (result.code !== 0) {
            return result;
        }
    }
}
github atomist / sdm-core / src / pack / docker / executeDockerBuild.ts View on Github external
}

            const opts = {
                cwd: p.baseDir,
            };

            const spOpts = {
                errorFinder: code => code !== 0,
            };

            const imageName = await imageNameCreator(p, sdmGoal, options, context);
            const image = `${imageName.registry}/${imageName.name}:${imageName.version}`;
            const dockerfilePath = await (options.dockerfileFinder ? options.dockerfileFinder(p) : "Dockerfile");

            // 1. run docker build
            let result: ExecuteGoalResult = await spawnAndWatch(
                {
                    command: "docker",
                    args: ["build", ".", "-f", dockerfilePath, "-t", image],
                },
                opts,
                progressLog,
                spOpts);

            if (result.code !== 0) {
                return result;
            }

            result = await dockerPush(image, options, progressLog);

            // 4. create image link
            if (await postLinkImageWebhook(
github atomist / sdm-core / src / internal / delivery / build / local / npm / nodeProjectVersioner.ts View on Github external
export const NodeProjectVersioner: ProjectVersioner = async (sdmGoal, p, log) => {
    const pjFile = await p.getFile("package.json");
    const pj = JSON.parse(await pjFile.getContent());
    const branch = sdmGoal.branch.split("/").join(".");
    const branchSuffix = branch !== sdmGoal.push.repo.defaultBranch ? `${branch}.` : "";
    const version = `${pj.version}-${branchSuffix}${df(new Date(), "yyyymmddHHMMss")}`;

    await spawnAndWatch({
            command: "npm",
            args: ["--no-git-tag-version", "version", version],
        },
        {
            cwd: p.baseDir,
        },
        log,
        {
            errorFinder: code => code !== 0,
        });

    return version;
};
github atomist / sdm-core / src / internal / delivery / build / local / npm / npmBuilder.ts View on Github external
export async function npmCompilePreparation(p: GitProject, goalInvocation: GoalInvocation): Promise {
    return spawnAndWatch({
        command: "npm",
        args: ["run", "compile"],
    }, {
            cwd: p.baseDir,
            ...DevelopmentEnvOptions,
        }, goalInvocation.progressLog,
        {
            errorFinder: code => code != null,
        });
}
github atomist / sdm-core / src / pack / pcf / CommandLineCloudFoundryDeployer.ts View on Github external
public async undeploy(cfi: CloudFoundryInfo, deployment: CloudFoundryDeployment, log: ProgressLog): Promise {
        await spawnAndWatch(asSpawnCommand(
            `cf login -a ${cfi.api} -o ${cfi.org} -u ${cfi.username} -p '${cfi.password}' -s ${cfi.space}`),
            {}, log);

        return spawnAndWatch(asSpawnCommand(`cf delete ${deployment.appName}`), {}, log);
    }
github atomist / sdm-core / src / internal / delivery / build / local / npm / executePublish.ts View on Github external
p.join(__dirname, "..", "..", "..", "..", "..", "scripts", "npm-publish.bash"),
            ];
            if (options.registry) {
                args.push("--registry", options.registry);
            }
            const access = await projectConfigurationValue("npm.publish.access", project, options.access);
            if (access) {
                args.push("--access", access);
            }
            if (options.tag) {
                args.push("--tag", options.tag);
            } else {
                args.push("--tag", gitBranchToNpmTag(id.branch));
            }

            const result: ExecuteGoalResult = await spawnAndWatch(
                { command: "bash", args },
                { cwd: project.baseDir },
                goalInvocation.progressLog,
            );

            if (result.code === 0) {
                const pi = await projectIdentifier(project);
                const url = `${options.registry}/${pi.name}/-/${pi.name}-${pi.version}.tgz`;
                result.targetUrl = url;

                if (options.status) {
                    await createStatus(
                        credentials,
                        id as GitHubRepoRef,
                        {
                            context: "npm/atomist/package",
github atomist / sdm-core / src / internal / delivery / build / local / npm / npmBuilder.ts View on Github external
export async function npmInstallPreparation(p: GitProject, goalInvocation: GoalInvocation): Promise {
    const hasPackageLock = p.fileExistsSync("package-lock.json");
    return spawnAndWatch({
        command: "npm",
        args: [hasPackageLock ? "ci" : "install"],
    }, {
            cwd: p.baseDir,
            ...DevelopmentEnvOptions,
        }, goalInvocation.progressLog,
        {
            errorFinder: code => code != null,
        });
}
github atomist / sdm-core / src / internal / delivery / build / local / npm / executePublish.ts View on Github external
export async function deleteBranchTag(branch: string, p: GitProject, options: NpmOptions): Promise {
    const pj = await p.getFile("package.json");
    if (pj) {
        const tag = gitBranchToNpmTag(branch);
        const name = JSON.parse(await pj.getContent()).name;

        await configure(options, p);
        const result = await spawnAndWatch({
                command: "npm",
                args: ["dist-tags", "rm", name, tag],
            },
            {
                cwd: p.baseDir,
            },
            new LoggingProgressLog("npm dist-tag rm"),
            {
                errorFinder: SuccessIsReturn0ErrorFinder,
            });

        return result;
    }
    return Success;
}