Skip to content

Commit

Permalink
Merge pull request #574 from alphagov/create-package-json-in-prerelease
Browse files Browse the repository at this point in the history
Create package.json for new components in `pre-release` step
  • Loading branch information
Jani Kraner authored Mar 7, 2018
2 parents 8bdbfc2 + e3ce1e0 commit b2d2b89
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 26 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

Note: We're not following semantic versioning yet, we are going to talk about this soon.

## Unreleased

Internal:

- Update pre-release step to check for new components
(PR [#574](https://github.com/alphagov/govuk-frontend/pull/574))

## 0.0.25-alpha (Breaking release)

Breaking changes:
Expand Down
46 changes: 46 additions & 0 deletions bin/check-and-create-package-json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh
set -e

PACKAGES_DIR="./packages/";

# assume there are no new components
ALL_PACKAGE_JSON_FILES_PRESENT=true;

# function to create a sample package.json
# and add latest published version of globals as dependency (as it's most common)
create_package_json()
{
GLOBALS_PACKAGE_VERSION=$(node -p "require('./packages/globals/package.json').version")
PACKAGE_JSON='
{
"name": "@govuk-frontend/'${D##*/}'",
"version": "0.0.0",
"dependencies": {
"@govuk-frontend/globals": "'$GLOBALS_PACKAGE_VERSION'"
}
}'

# create a package.json file
echo "$PACKAGE_JSON" >> "${D}/package.json"
}


# check in all folders inside /packages to see if any new components have been added
for D in $PACKAGES_DIR*; do
if [ -d "${D}" ]; then
# if there are new folders (components then they will be missing package.json)
ALL_PACKAGE_JSON_FILES_PRESENT=false

if ! [ -e ${D}/package.json ]; then
# ${D##*/} strips everything before /
COMPONENT_NAME=${D##*/}
echo "⚠️ 🆕 $COMPONENT_NAME 🆕 component is missing a package.json file.\n"
echo "⚠️ I've created a sample package.json file. Please amended it with correct data.\n"

create_package_json ${D}

echo "⚠️ Remember to add the 🆕 $COMPONENT_NAME 🆕 component to all/package.json\n"
read -n 1 -s -r -p "Once done, come back and press any key to continue: "
fi
fi
done
Binary file added docs/img/new-component-prompt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 11 additions & 25 deletions docs/publishing.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ version bumped.
Run `chmod u+x **/*.sh` which will give the permission to all shell
scripts in the current directory.*

**If you have a new component to add, follow [these](#adding-a-new-component) steps**

1. Create a new branch that's up to date with master and:

2. Update `CHANGELOG` version heading with the next version number.
Expand All @@ -26,6 +24,16 @@ scripts in the current directory.*
This will:
- run `npm build:packages` that copies any changes from`src/component-name` to `packages/component-name` and runs `after-build-packages.test.js` test
to ensure the contents of `packages` matches `src`.


If you have a new component was added to `src` and copied over to `packages` in the above task, then then script will detect those components, notify the developer, create a sample `package.json` file for each.

It will reminnd the developer to check the version number, dependencies and add new components to `all/package.json` dependencies.

It will also prompt the develoeper to signal to the scipt once changes have been made, so that the rest of the `npm run pre-release` tasks can run.**
![New component added](./img/new-component-prompt.png)


- run `lerna publish --skip-git --skip-npm` which will check for updated packages and
suggest a version for each as seen below.
Lerna will prompt you to select the new version for each package. If you
Expand Down Expand Up @@ -60,31 +68,9 @@ scripts in the current directory.*
6. Create a release in Github interface, ddd release notes to and attach the ZIP.

7. Add Trello cards to "This Sprint" column for
- updating GOV.UK Design System to use the latest release
- updating GOV.UK Design System to use the latest releasex
- updating the Prototype Kit to use the latest release

#### Adding a new component

1. In Frontend, for any new components inside `/packages`, add a `package.json`
inside `packages/component-name`:
```
{
"name": "@govuk-frontend/component-name",
"version": "0.0.21-alpha",
"dependencies": {
"@govuk-frontend/globals": "version-number"
}
}
```

2. Include new components in `packages/all/package.json` with blank version
numbers. Do not update the version numbers of existing packages manually here,
Lerna will do this as part of `lerna publish`.

3. Commit changes made so far
```
git add packages/* -f
git commit -m "chore(packages): <component-name> added to packages"
```
#### Test published packages
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"heroku": "gulp copy-assets && node app/app.js",
"pre-release": "node bin/check-nvmrc.js && ./bin/pre-release.sh",
"release": "node bin/check-nvmrc.js && ./bin/release.sh",
"build:packages": "node bin/check-nvmrc.js && gulp build:packages --destination 'packages' && npm run test:build:packages",
"build:packages": "node bin/check-nvmrc.js && gulp build:packages --destination 'packages' && ./bin/check-and-create-package-json.sh && npm run test:build:packages",
"build:dist": "node bin/check-nvmrc.js && gulp build:dist --destination 'dist' && npm run test:build:dist",
"test": "standard && gulp test && npm run test:app && npm run test:components && npm run test:generate:readme",
"test:app": "jest app/__tests__/app.test.js --forceExit # express server fails to end process",
Expand Down

0 comments on commit b2d2b89

Please sign in to comment.