UNPKG

npmize

Version:

Let's create an npm package without worrying about anything.

58 lines (49 loc) 1.87 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; const path_1 = __importDefault(require("path")); const ansi_colors_1 = __importDefault(require("ansi-colors")); const utils_1 = require("../utils"); const fs_1 = require("../utils/fs"); function publishWorkflowTemplate(nodeVersion = 'latest') { return `name: Publish to NPM on: workflow_dispatch: push: paths: - package.json jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: ${nodeVersion} - name: Install dependencies run: npm install - name: Run tests (If exists) run: | if [[ ! -z $(npm show . scripts.test) ]]; then npm run test fi - name: Build the project run: npm run build - name: Set Npm Token run: npm config set //registry.npmjs.org/:_authToken=\${{ secrets.NPM_AUTH_TOKEN }} - name: Publish package to NPM run: npm publish || true - name: Unset Npm Token run: npm config delete //registry.npmjs.org/:_authToken `; } function default_1(baseDir) { var _a; const workflowDir = path_1.default.join(baseDir, './.github/workflows'); const publishWorkflowPath = path_1.default.join(workflowDir, 'npm-publish.yml'); (0, fs_1.writeFileSync)(publishWorkflowPath, publishWorkflowTemplate((_a = (0, utils_1.getNodeVersion)()) === null || _a === void 0 ? void 0 : _a.toString())); console.log(ansi_colors_1.default.bgGreen(' INFO: '), `Set '${ansi_colors_1.default.yellow('NPM_AUTH_TOKEN')}' secret in your repository settings to publish to NPM.`); }