Skip to content
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

feat: add support for scoped packages #451

Merged
merged 6 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion packages/shipjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"globby": "^10.0.1",
"inquirer": "7.0.0",
"mkdirp": "^0.5.1",
"npm-package-arg": "^7.0.0",
"prettier": "^1.18.2",
"shell-quote": "^1.7.2",
"shipjs-lib": "0.10.0",
Expand All @@ -65,4 +66,4 @@
"jest": "24.9.0",
"jest-watch-typeahead": "0.4.2"
}
}
}
4 changes: 4 additions & 0 deletions packages/shipjs/src/flow/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ async function setup({ help = false, dir = '.' }) {
mainVersionFile,
packagesToBump,
packagesToPublish,
isScoped,
isPublic,
} = await askQuestions({ dir });
const outputs = [
addDevDependencies({ dependencies: ['shipjs'], dir }),
addScriptsToPackageJson({ dir }),
await addShipConfig({
isScoped,
isPublic,
baseBranch,
releaseBranch,
useMonorepo,
Expand Down
17 changes: 17 additions & 0 deletions packages/shipjs/src/step/setup/addShipConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { info } from '../../color';
import { print } from '../../util';

export default async ({
isScoped,
isPublic,
baseBranch,
releaseBranch,
useMonorepo,
Expand All @@ -17,6 +19,9 @@ export default async ({
await runStep({ title: 'Creating ship.config.js' }, async () => {
const filePath = path.resolve(dir, 'ship.config.js');
const json = {
publishCommand: !xor(isPublic, isScoped)
? createPublishCommand(isPublic)
: undefined,
mergeStrategy:
baseBranch === releaseBranch
? {
Expand Down Expand Up @@ -47,3 +52,15 @@ export default async ({
print(' > https://github.com/algolia/shipjs/blob/master/GUIDE.md');
};
});

function createPublishCommand(isPublic) {
const command = isPublic
? ({ defaultCommand }) => `${defaultCommand} --access public`
: ({ defaultCommand }) => `${defaultCommand} --access restricted`;

return command.toString();
}

function xor(a, b) {
return (a && !b) || (!a && b);
}
28 changes: 28 additions & 0 deletions packages/shipjs/src/step/setup/askQuestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import inquirer from 'inquirer';
import { getRemoteBranches } from 'shipjs-lib';
import fs from 'fs';
import path from 'path';
import npa from 'npm-package-arg';
import runStep from '../runStep';
import { grey, reset } from '../../color';

Expand All @@ -27,6 +28,8 @@ export default async ({ dir }) =>
packagesToPublish,
} = await askMonorepo(dir);

const { isScoped, isPublic } = await askPackageAccess(dir);

return {
baseBranch,
releaseBranch,
Expand All @@ -37,6 +40,8 @@ export default async ({ dir }) =>
mainVersionFile,
packagesToBump,
packagesToPublish,
isScoped,
isPublic,
};
});

Expand Down Expand Up @@ -195,6 +200,21 @@ async function askMonorepo(dir) {
return { useMonorepo, mainVersionFile, packagesToBump, packagesToPublish };
}

async function askPackageAccess(dir) {
const isScoped = isScopedPackage(getJson(dir, 'package.json').name);

const { isPublic } = await inquirer.prompt([
{
type: 'confirm',
name: 'isPublic',
message: 'Publish public package?',
default: true,
},
]);

return { isScoped, isPublic };
}

function detectMonorepo(dir) {
if (fs.existsSync(path.resolve(dir, 'lerna.json'))) {
return true;
Expand Down Expand Up @@ -258,3 +278,11 @@ function stringArrayValidator(answer) {
return errorMessage;
}
}

function isScopedPackage(name) {
jeetiss marked this conversation as resolved.
Show resolved Hide resolved
try {
return npa(name).scope !== null;
} catch (err) {
return false;
}
}
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4391,6 +4391,13 @@ hosted-git-info@^2.1.4, hosted-git-info@^2.6.0:
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.7.1.tgz#97f236977bd6e125408930ff6de3eec6281ec047"
integrity sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w==

hosted-git-info@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-3.0.2.tgz#8b7e3bd114b59b51786f8bade0f39ddc80275a97"
integrity sha512-ezZMWtHXm7Eb7Rq4Mwnx2vs79WUx2QmRg3+ZqeGroKzfDO+EprOcgRPYghsOP9JuYBfK18VojmRTGCg8Ma+ktw==
dependencies:
lru-cache "^5.1.1"

html-encoding-sniffer@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/html-encoding-sniffer/-/html-encoding-sniffer-1.0.2.tgz#e70d84b94da53aa375e11fe3a351be6642ca46f8"
Expand Down Expand Up @@ -6290,6 +6297,16 @@ npm-lifecycle@^3.1.2:
semver "^5.5.0"
validate-npm-package-name "^3.0.0"

npm-package-arg@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/npm-package-arg/-/npm-package-arg-7.0.0.tgz#52cdf08b491c0c59df687c4c925a89102ef794a5"
integrity sha512-xXxr8y5U0kl8dVkz2oK7yZjPBvqM2fwaO5l3Yg13p03v8+E3qQcD0JNhHzjL1vyGgxcKkD0cco+NLR72iuPk3g==
dependencies:
hosted-git-info "^3.0.2"
osenv "^0.1.5"
semver "^5.6.0"
validate-npm-package-name "^3.0.0"

npm-packlist@^1.1.6, npm-packlist@^1.4.4:
version "1.4.4"
resolved "https://registry.yarnpkg.com/npm-packlist/-/npm-packlist-1.4.4.tgz#866224233850ac534b63d1a6e76050092b5d2f44"
Expand Down