Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Commit 8d2a1f7

Browse files
committed
refactor: added publishing script
1 parent 471b154 commit 8d2a1f7

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

.github/workflows/publish-npm.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Publish Packages on NPM
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
npmTag:
6+
description: 'NPM Tag'
7+
required: true
8+
default: 'latest'
9+
10+
jobs:
11+
publishing:
12+
name: Package Publishing
13+
runs-on: ubuntu-latest
14+
env:
15+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v2
19+
20+
- name: Setup node
21+
uses: actions/setup-node@v2
22+
with:
23+
node-version: "16"
24+
registry-url: "https://registry.npmjs.org/"
25+
scope: "@vue-storefront"
26+
- run: echo "" >> .npmrc && echo "@vue-storefront:registry=https://registry.npmjs.org/" >> .npmrc
27+
- run: yarn publish:driver "${{ github.event.inputs.npmTag }}" "$NODE_AUTH_TOKEN"
28+
env:
29+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

scripts/lib/publishNpm.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* eslint-disable unicorn/no-process-exit, unicorn/prefer-module */
2+
const { exec } = require("child_process");
3+
4+
const publishPackages = (pkgPath, labels) => {
5+
return new Promise((_res, _rej) => {
6+
try {
7+
const command = `npm publish ${pkgPath} --access public --tag ${labels}`;
8+
9+
console.log(command)
10+
11+
exec(command, (error, stdout, stderr) => {
12+
if (error) {
13+
console.log(`error: ${error.message}`);
14+
return;
15+
}
16+
if (stderr) {
17+
console.log(`stderr: ${stderr}`);
18+
return;
19+
}
20+
console.log(`stdout: ${stdout}`);
21+
});
22+
} catch (e) {
23+
console.error(e);
24+
}
25+
});
26+
}
27+
28+
module.exports = {
29+
publishPackages,
30+
}

scripts/publishDriver.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* eslint-disable unicorn/no-process-exit, unicorn/prefer-module */
2+
const path = require('path');
3+
const { publishPackages } = require('./lib/publishNpm');
4+
5+
const myArgs = process.argv.slice(2);
6+
const labels = myArgs[0];
7+
8+
publishPackages(path.join(process.cwd()), labels)
9+
.then(console.log)
10+
.catch((e) => {
11+
console.error(e);
12+
});

0 commit comments

Comments
 (0)