|
7 | 7 | * You might need to authenticate with NPM before running this script.
|
8 | 8 | */
|
9 | 9 |
|
10 |
| -import { execSync } from 'child_process' |
11 |
| -import { readFileSync, writeFileSync } from 'fs' |
| 10 | +import { execSync } from 'child_process'; |
| 11 | +import { readFileSync, writeFileSync } from 'fs'; |
12 | 12 |
|
13 |
| -import devkit from '@nx/devkit' |
14 |
| -const { readCachedProjectGraph } = devkit |
| 13 | +import devkit from '@nx/devkit'; |
| 14 | +const { readCachedProjectGraph } = devkit; |
15 | 15 |
|
16 | 16 | function invariant(condition, message) {
|
17 | 17 | if (!condition) {
|
18 |
| - console.error(message) |
19 |
| - process.exit(1) |
| 18 | + console.error(message); |
| 19 | + process.exit(1); |
20 | 20 | }
|
21 | 21 | }
|
22 | 22 |
|
23 | 23 | // Executing publish script: node path/to/publish.mjs {name} --version {version} --tag {tag}
|
24 | 24 | // Default "tag" to "next" so we won't publish the "latest" tag by accident.
|
25 |
| -const [, , name, version, tag = 'next'] = process.argv |
| 25 | +const [, , name, version, tag = 'next'] = process.argv; |
26 | 26 |
|
27 | 27 | // A simple SemVer validation to validate the version
|
28 |
| -const validVersion = /^\d+\.\d+\.\d+(-\w+\.\d+)?/ |
| 28 | +const validVersion = /^\d+\.\d+\.\d+(-\w+\.\d+)?/; |
29 | 29 | invariant(
|
30 | 30 | version && validVersion.test(version),
|
31 |
| - `No version provided or version did not match Semantic Versioning, expected: #.#.#-tag.# or #.#.#, got ${version}.`, |
32 |
| -) |
| 31 | + `No version provided or version did not match Semantic Versioning, expected: #.#.#-tag.# or #.#.#, got ${version}.` |
| 32 | +); |
33 | 33 |
|
34 |
| -const graph = readCachedProjectGraph() |
35 |
| -const project = graph.nodes[name] |
| 34 | +const graph = readCachedProjectGraph(); |
| 35 | +const project = graph.nodes[name]; |
36 | 36 |
|
37 |
| -invariant(project, `Could not find project "${name}" in the workspace. Is the project.json configured correctly?`) |
| 37 | +invariant( |
| 38 | + project, |
| 39 | + `Could not find project "${name}" in the workspace. Is the project.json configured correctly?` |
| 40 | +); |
38 | 41 |
|
39 |
| -const outputPath = project.data?.targets?.build?.options?.outputPath |
| 42 | +const outputPath = project.data?.targets?.build?.options?.outputPath; |
40 | 43 | invariant(
|
41 | 44 | outputPath,
|
42 |
| - `Could not find "build.options.outputPath" of project "${name}". Is project.json configured correctly?`, |
43 |
| -) |
| 45 | + `Could not find "build.options.outputPath" of project "${name}". Is project.json configured correctly?` |
| 46 | +); |
44 | 47 |
|
45 |
| -process.chdir(outputPath) |
| 48 | +process.chdir(outputPath); |
46 | 49 |
|
47 | 50 | // Updating the version in "package.json" before publishing
|
48 | 51 | try {
|
49 |
| - const json = JSON.parse(readFileSync(`package.json`).toString()) |
50 |
| - json.version = version |
51 |
| - writeFileSync(`package.json`, JSON.stringify(json, null, 2)) |
| 52 | + const json = JSON.parse(readFileSync(`package.json`).toString()); |
| 53 | + json.version = version; |
| 54 | + writeFileSync(`package.json`, JSON.stringify(json, null, 2)); |
52 | 55 | } catch (e) {
|
53 |
| - console.error(`Error reading package.json file from library build output.`) |
| 56 | + console.error(`Error reading package.json file from library build output.`); |
54 | 57 | }
|
55 | 58 |
|
56 | 59 | // Execute "npm publish" to publish
|
57 |
| -execSync(`npm publish --access public --tag ${tag}`) |
| 60 | +execSync(`npm publish --access public --tag ${tag}`); |
0 commit comments