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 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 packages/shipjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"inquirer": "7.0.0",
"mkdirp": "^0.5.1",
"prettier": "^1.18.2",
"serialize-javascript": "^2.1.0",
"shell-quote": "^1.7.2",
"shipjs-lib": "0.10.0",
"temp-write": "4.0.0"
Expand Down
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
15 changes: 10 additions & 5 deletions packages/shipjs/src/step/setup/addShipConfig.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import runStep from '../runStep';
import fs from 'fs';
import path from 'path';
import serialize from 'serialize-javascript';
import runStep from '../runStep';
import { runPrettier } from '../../helper';
import { info } from '../../color';
import { print } from '../../util';

export default async ({
isScoped,
isPublic,
baseBranch,
releaseBranch,
useMonorepo,
Expand All @@ -17,6 +20,10 @@ export default async ({
await runStep({ title: 'Creating ship.config.js' }, async () => {
const filePath = path.resolve(dir, 'ship.config.js');
const json = {
publishCommand:
isScoped && isPublic
? ({ defaultCommand }) => `${defaultCommand} --access public`
: undefined,
mergeStrategy:
baseBranch === releaseBranch
? {
Expand All @@ -35,10 +42,8 @@ export default async ({
}
: undefined,
};
fs.writeFileSync(
filePath,
`module.exports = ${JSON.stringify(json, null, 2)};`
);

fs.writeFileSync(filePath, `module.exports = ${serialize(json)};`);
await runPrettier({ filePath, dir });

return () => {
Expand Down
31 changes: 31 additions & 0 deletions packages/shipjs/src/step/setup/askQuestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default async ({ dir }) =>
packagesToPublish,
} = await askMonorepo(dir);

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

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

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

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

if (!isScoped) {
return { isScoped };
}

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 +281,11 @@ function stringArrayValidator(answer) {
return errorMessage;
}
}

function isScopedPackage(name) {
try {
return name[0] === '@' && name.indexOf('/') !== -1;
} catch (err) {
return false;
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7470,6 +7470,11 @@ sentence-case@^2.1.0:
no-case "^2.2.0"
upper-case-first "^1.1.2"

serialize-javascript@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-2.1.0.tgz#9310276819efd0eb128258bb341957f6eb2fc570"
integrity sha512-a/mxFfU00QT88umAJQsNWOnUKckhNCqOl028N48e7wFmo2/EHpTo9Wso+iJJCMrQnmFvcjto5RJdAHEvVhcyUQ==

set-blocking@^2.0.0, set-blocking@~2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
Expand Down