Skip to content

Commit

Permalink
move scripts to utils, add scope to the name in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchen committed Dec 28, 2020
1 parent 4ba1e78 commit 7999189
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup .npmrc file to publish to npm
uses: actions/setup-node@v1
with:
node-version: '10.x'
node-version: '12.x'
registry-url: 'https://registry.npmjs.org'
- name: Install modules
run: npm install
Expand All @@ -25,9 +25,11 @@ jobs:
- name: Setup .npmrc file to publish to GitHub Packages
uses: actions/setup-node@v1
with:
node-version: '12.x'
registry-url: 'https://npm.pkg.github.com'
scope: '@tomchen'
- name: Publish to GitHub Packages
run: npm run addscope
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
"types": "dist/types/index.d.js",
"scripts": {
"build": "npm run build:cjs && npm run build:esm && npm run build:umd && npm run build:types",
"build:cjs": "node cleanup cjs && tsc -p config/tsconfig.cjs.json",
"build:esm": "node cleanup esm && tsc -p config/tsconfig.esm.json",
"build:umd": "node cleanup umd && webpack --config config/webpack.config.js",
"build:types": "node cleanup types && tsc -p config/tsconfig.types.json",
"clean": "node cleanup",
"build:cjs": "node utils/cleanup cjs && tsc -p config/tsconfig.cjs.json",
"build:esm": "node utils/cleanup esm && tsc -p config/tsconfig.esm.json",
"build:umd": "node utils/cleanup umd && webpack --config config/webpack.config.js",
"build:types": "node utils/cleanup types && tsc -p config/tsconfig.types.json",
"clean": "node utils/cleanup",
"package": "npm run build && npm pack",
"test": "jest",
"test:cov": "jest --coverage"
"test:cov": "jest --coverage",
"addscope": "node utils/packagejson name @tomchen/example-typescript-package && prettier --write package.json"
},
"publishConfig": {
"access": "public"
Expand Down
10 changes: 5 additions & 5 deletions cleanup.js → utils/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const deleteFolderRecursive = (path) => {
const folder = process.argv.slice(2)[0]

if (folder) {
deleteFolderRecursive(Path.join('dist', folder))
deleteFolderRecursive(Path.join(__dirname, '../dist', folder))
} else {
deleteFolderRecursive('dist/cjs')
deleteFolderRecursive('dist/esm')
deleteFolderRecursive('dist/umd')
deleteFolderRecursive('dist/types')
deleteFolderRecursive(Path.join(__dirname, '../dist/cjs'))
deleteFolderRecursive(Path.join(__dirname, '../dist/esm'))
deleteFolderRecursive(Path.join(__dirname, '../dist/umd'))
deleteFolderRecursive(Path.join(__dirname, '../dist/types'))
}
26 changes: 26 additions & 0 deletions utils/packagejson.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable */
const fs = require('fs')
const Path = require('path')
const fileName = '../package.json'
const file = require(fileName)
/* eslint-enable */

const args = process.argv.slice(2)

for (let i = 0, l = args.length; i < l; i++) {
if (i % 2 === 0) {
file[args[i]] = args[i + 1]
}
}

fs.writeFile(
Path.join(__dirname, fileName),
JSON.stringify(file),
function writeJSON(err) {
if (err) {
return console.log(err)
}
console.log(JSON.stringify(file))
console.log('Writing to ' + fileName)
}
)

0 comments on commit 7999189

Please sign in to comment.