diff --git a/.gitignore b/.gitignore index daf24c023..8f706a7fc 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ lib dist umd storybook-static +local-pack.sh # Config files .npmrc @@ -65,3 +66,8 @@ npm-debug.log* yarn-debug.log* yarn-error.log* pnpm-debug.log* + +#local build artifacts +carbon-vue-*.tgz +local-dev/npm-registry/storage/* +!local-dev/npm-registry/storage/.gitkeep diff --git a/README.md b/README.md index eb5a9aa0a..6d143d12c 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,25 @@ If you just want to build an individual package you can limit the scope: To start the storybook in a local server use `yarn start`. +## Test publish + +To test publishing to a npm registry: + +```shell +cd local-dev +docker-compose up +# open a new terminal +yarn build +npm add-user --registry http://0.0.0.0:4873/ +# any username, password, & email will work +# try: carbon, vue, & carbon-vue@example.com +yarn test:publish +# maybe change some things and try again +yarn build +yarn test:unpublish +yarn test:publish +``` + ## How to run the storybook Just follow the steps listed below and you will be able to run the storybook. diff --git a/local-dev/compose.yaml b/local-dev/compose.yaml new file mode 100644 index 000000000..f2e83bbbb --- /dev/null +++ b/local-dev/compose.yaml @@ -0,0 +1,14 @@ +services: + npm-registry: + # npm add-user --registry http://0.0.0.0:4873/ + # carbon + # vue + # carbon-vue@example.com + image: docker.io/verdaccio/verdaccio:nightly-master + ports: + - '4873:4873' + volumes: + - './npm-registry/storage:/verdaccio/storage' +volumes: + verdaccio: + driver: local diff --git a/local-dev/npm-registry/storage/.gitkeep b/local-dev/npm-registry/storage/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/package.json b/package.json index 7af23ea02..d3c2af33d 100644 --- a/package.json +++ b/package.json @@ -7,13 +7,8 @@ "main": "dist/carbon-vue-3.umd.min.js", "types": "src/index.d.ts", "web-types": "dist/web-types.json", - "packrat": { - "prod_setup": "npx ibmtelemetry --config=telemetry.yml || true" - }, "scripts": { - "postinstall": "node devPreinstall.js && node .storybook/postinstall.js", - "prepack": "node packrat.js --disable", - "postpack": "node packrat.js --enable", + "postinstall": "node postinstall.js", "build": "vue-cli-service build --target lib --name carbon-vue-3 ./src/index.js --no-clean", "lint": "vue-cli-service lint", "build-web-types": "vue-docgen-web-types --outFile dist/web-types.json", @@ -26,6 +21,8 @@ "lint:es": "eslint src/**/*.{js,vue}", "lint:style": "vue-cli-service lint:style", "serve:storybook": "cd ./storybook && yarn run serve", + "test:publish": "npm publish --registry http://0.0.0.0:4873", + "test:unpublish": "rm -rf local-dev/npm-registry/storage/data/@carbon/vue", "test": "vue-cli-service test:unit --no-coverage" }, "workspaces": [ @@ -163,6 +160,7 @@ "files": [ "/dist", "/src", + "postinstall.js", "telemetry.yml" ], "commitlint": { diff --git a/packrat.js b/packrat.js deleted file mode 100644 index 1b7997d88..000000000 --- a/packrat.js +++ /dev/null @@ -1,51 +0,0 @@ -/* eslint no-console: 0 */ - -const PackageJson = require('@npmcli/package-json'); - -const devPostinstall = 'dev_setup'; -const packPostinstall = 'prod_setup'; - -async function prepack() { - const pkgJson = await PackageJson.load('./'); - pkgJson.content['packrat'][devPostinstall] = - pkgJson.content.scripts['postinstall']; - pkgJson.content.scripts['postinstall'] = - pkgJson.content['packrat'][packPostinstall]; - await pkgJson.save(); - console.log('postinstall:', pkgJson.content.scripts['postinstall']); - console.log(pkgJson.content['packrat']); -} -async function postpack() { - const pkgJson = await PackageJson.load('./'); - pkgJson.content.scripts['postinstall'] = - pkgJson.content['packrat'][devPostinstall]; - delete pkgJson.content['packrat'][devPostinstall]; - await pkgJson.save(); - console.log('postinstall:', pkgJson.content.scripts['postinstall']); - console.log(pkgJson.content['packrat']); -} - -if (process.argv.length !== 3) { - console.error( - 'The pinst package not working for us anymore. We need two different postinstall hooks.' - ); - console.error( - '1. postinstall that runs git pre-commit hooks - this is dev only' - ); - console.error('2. postinstall that runs production hooks like ibmtelemetry'); - console.error('This script toggles between the 2'); - console.error('usage: node packrat.js'); - console.error('Options'); - console.error('\t--enable Enable pack (production) postinstall hook'); - console.error(`\t\tmove postinstall to "packrat".${devPostinstall}`); - console.error(`\t\tcopy "packrat".${packPostinstall} to postinstall`); - console.error('\t--disable Disable pack (production) postinstall hook'); - console.error(`\t\tmove "packrat".${devPostinstall} to postinstall`); - process.exit(1); -} - -if (process.argv[2] === '--disable') { - prepack().then(() => console.log('updated package.json')); -} else if (process.argv[2] === '--enable') { - postpack().then(() => console.log('updated package.json')); -} else console.error('unknown argument', process.argv[2]); diff --git a/postinstall.js b/postinstall.js new file mode 100644 index 000000000..c6221b856 --- /dev/null +++ b/postinstall.js @@ -0,0 +1,9 @@ +const fs = require('fs'); +const { spawnSync } = require('child_process'); + +if (fs.existsSync('./devPreinstall.js')) { + require('./devPreinstall.js'); + require('./.storybook/postinstall.js'); +} else { + spawnSync('npx', ['ibmtelemetry', '--config=telemetry.yml']); +}