@napi-rs/cli 2.15.1 → 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -78
- package/cli.mjs +12 -0
- package/dist/api/artifacts.d.ts +2 -0
- package/dist/api/artifacts.js +50 -0
- package/dist/api/build.d.ts +14 -0
- package/dist/api/build.js +404 -0
- package/dist/api/create-npm-dirs.d.ts +2 -0
- package/dist/api/create-npm-dirs.js +63 -0
- package/dist/api/new.d.ts +4 -0
- package/dist/api/new.js +154 -0
- package/dist/api/pre-publish.d.ts +2 -0
- package/dist/api/pre-publish.js +157 -0
- package/dist/api/rename.d.ts +2 -0
- package/dist/api/rename.js +28 -0
- package/dist/api/templates/.gitignore.d.ts +1 -0
- package/dist/api/templates/.gitignore.js +198 -0
- package/dist/api/templates/.npmignore.d.ts +1 -0
- package/dist/api/templates/.npmignore.js +14 -0
- package/dist/api/templates/build.rs.d.ts +1 -0
- package/dist/api/templates/build.rs.js +4 -0
- package/dist/api/templates/cargo.toml.d.ts +6 -0
- package/dist/api/templates/cargo.toml.js +25 -0
- package/dist/api/templates/ci-template.d.ts +1 -0
- package/dist/api/templates/ci-template.js +566 -0
- package/dist/api/templates/ci.yml.d.ts +1 -0
- package/dist/api/templates/ci.yml.js +92 -0
- package/dist/api/templates/index.d.ts +8 -0
- package/dist/api/templates/index.js +8 -0
- package/dist/api/templates/js-binding.d.ts +1 -0
- package/dist/api/templates/js-binding.js +124 -0
- package/dist/api/templates/lib.rs.d.ts +1 -0
- package/dist/api/templates/lib.rs.js +10 -0
- package/dist/api/templates/package.json.d.ts +8 -0
- package/dist/api/templates/package.json.js +30 -0
- package/dist/api/universalize.d.ts +2 -0
- package/dist/api/universalize.js +38 -0
- package/dist/api/version.d.ts +2 -0
- package/dist/api/version.js +16 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +25 -0
- package/dist/commands/artifacts.d.ts +6 -0
- package/dist/commands/artifacts.js +19 -0
- package/dist/commands/build.d.ts +6 -0
- package/dist/commands/build.js +34 -0
- package/dist/commands/create-npm-dirs.d.ts +4 -0
- package/dist/commands/create-npm-dirs.js +7 -0
- package/dist/commands/help.d.ts +10 -0
- package/dist/commands/help.js +12 -0
- package/dist/commands/new.d.ts +12 -0
- package/dist/commands/new.js +112 -0
- package/dist/commands/pre-publish.d.ts +4 -0
- package/dist/commands/pre-publish.js +8 -0
- package/dist/commands/rename.d.ts +4 -0
- package/dist/commands/rename.js +7 -0
- package/dist/commands/universalize.d.ts +4 -0
- package/dist/commands/universalize.js +7 -0
- package/dist/commands/version.d.ts +4 -0
- package/dist/commands/version.js +7 -0
- package/dist/def/artifacts.d.ts +50 -0
- package/dist/def/artifacts.js +38 -0
- package/dist/def/build.d.ts +150 -0
- package/dist/def/build.js +105 -0
- package/dist/def/commands/artifacts.d.ts +15 -0
- package/dist/def/commands/artifacts.js +29 -0
- package/dist/def/commands/build.d.ts +53 -0
- package/dist/def/commands/build.js +105 -0
- package/dist/def/commands/create-npm-dirs.d.ts +15 -0
- package/dist/def/commands/create-npm-dirs.js +29 -0
- package/dist/def/commands/new.d.ts +27 -0
- package/dist/def/commands/new.js +53 -0
- package/dist/def/commands/pre-publish.d.ts +23 -0
- package/dist/def/commands/pre-publish.js +45 -0
- package/dist/def/commands/rename.d.ts +25 -0
- package/dist/def/commands/rename.js +49 -0
- package/dist/def/commands/universalize.d.ts +13 -0
- package/dist/def/commands/universalize.js +25 -0
- package/dist/def/commands/version.d.ts +13 -0
- package/dist/def/commands/version.js +25 -0
- package/dist/def/create-npm-dirs.d.ts +50 -0
- package/dist/def/create-npm-dirs.js +38 -0
- package/dist/def/new.d.ts +106 -0
- package/dist/def/new.js +66 -0
- package/dist/def/options/artifacts.d.ts +35 -0
- package/dist/def/options/artifacts.js +11 -0
- package/dist/def/options/build.d.ts +97 -0
- package/dist/def/options/build.js +3 -0
- package/dist/def/options/create-npm-dirs.d.ts +35 -0
- package/dist/def/options/create-npm-dirs.js +11 -0
- package/dist/def/options/new.d.ts +79 -0
- package/dist/def/options/new.js +15 -0
- package/dist/def/options/pre-publish.d.ts +65 -0
- package/dist/def/options/pre-publish.js +13 -0
- package/dist/def/options/rename.d.ts +75 -0
- package/dist/def/options/rename.js +11 -0
- package/dist/def/options/universalize.d.ts +28 -0
- package/dist/def/options/universalize.js +10 -0
- package/dist/def/options/version.d.ts +28 -0
- package/dist/def/options/version.js +10 -0
- package/dist/def/pre-publish.d.ts +88 -0
- package/dist/def/pre-publish.js +56 -0
- package/dist/def/rename.d.ts +100 -0
- package/dist/def/rename.js +58 -0
- package/dist/def/universalize.d.ts +41 -0
- package/dist/def/universalize.js +33 -0
- package/dist/def/version.d.ts +41 -0
- package/dist/def/version.js +33 -0
- package/dist/index.cjs +20641 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +30 -0
- package/dist/utils/__tests__/target.spec.d.ts +1 -0
- package/dist/utils/__tests__/target.spec.js +10 -0
- package/dist/utils/__tests__/typegen.spec.d.ts +1 -0
- package/dist/utils/__tests__/typegen.spec.js +37 -0
- package/dist/utils/__tests__/version.spec.d.ts +1 -0
- package/dist/utils/__tests__/version.spec.js +5 -0
- package/dist/utils/cargo.d.ts +1 -0
- package/dist/utils/cargo.js +33 -0
- package/dist/utils/ci.d.ts +11 -0
- package/dist/utils/ci.js +86 -0
- package/dist/utils/config.d.ts +65 -0
- package/dist/utils/config.js +42 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/log.d.ts +10 -0
- package/dist/utils/log.js +14 -0
- package/dist/utils/metadata.d.ts +24 -0
- package/dist/utils/metadata.js +19 -0
- package/dist/utils/misc.d.ts +13 -0
- package/dist/utils/misc.js +35 -0
- package/dist/utils/target.d.ts +30 -0
- package/dist/utils/target.js +109 -0
- package/dist/utils/typegen.d.ts +3 -0
- package/dist/utils/typegen.js +158 -0
- package/dist/utils/version.d.ts +11 -0
- package/dist/utils/version.js +59 -0
- package/package.json +63 -27
- package/src/api/artifacts.ts +93 -0
- package/src/api/build.ts +549 -0
- package/src/api/create-npm-dirs.ts +105 -0
- package/src/api/new.ts +206 -0
- package/src/api/pre-publish.ts +216 -0
- package/src/api/rename.ts +51 -0
- package/src/api/templates/.gitignore.ts +198 -0
- package/src/api/templates/.npmignore.ts +14 -0
- package/src/api/templates/build.rs.ts +4 -0
- package/src/api/templates/cargo.toml.ts +35 -0
- package/src/api/templates/ci-template.ts +566 -0
- package/src/api/templates/ci.yml.ts +116 -0
- package/src/api/templates/index.ts +8 -0
- package/src/api/templates/js-binding.ts +130 -0
- package/src/api/templates/lib.rs.ts +10 -0
- package/src/api/templates/package.json.ts +44 -0
- package/src/api/universalize.ts +76 -0
- package/src/api/version.ts +26 -0
- package/src/cli.ts +29 -0
- package/src/commands/artifacts.ts +23 -0
- package/src/commands/build.ts +42 -0
- package/src/commands/create-npm-dirs.ts +8 -0
- package/src/commands/help.ts +13 -0
- package/src/commands/new.ts +138 -0
- package/src/commands/pre-publish.ts +9 -0
- package/src/commands/rename.ts +8 -0
- package/src/commands/universalize.ts +8 -0
- package/src/commands/version.ts +8 -0
- package/src/def/artifacts.ts +79 -0
- package/src/def/build.ts +242 -0
- package/src/def/create-npm-dirs.ts +79 -0
- package/src/def/new.ts +144 -0
- package/src/def/pre-publish.ts +120 -0
- package/src/def/rename.ts +122 -0
- package/src/def/universalize.ts +66 -0
- package/src/def/version.ts +65 -0
- package/src/index.ts +31 -0
- package/src/utils/__tests__/__fixtures__/napi_type_def +201 -0
- package/src/utils/__tests__/__snapshots__/target.spec.ts.md +110 -0
- package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +618 -0
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/version.spec.ts.md +20 -0
- package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
- package/src/utils/__tests__/target.spec.ts +19 -0
- package/src/utils/__tests__/typegen.spec.ts +49 -0
- package/src/utils/__tests__/version.spec.ts +13 -0
- package/src/utils/cargo.ts +35 -0
- package/src/utils/ci.ts +102 -0
- package/src/utils/config.ts +123 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/log.ts +34 -0
- package/src/utils/metadata.ts +59 -0
- package/src/utils/misc.ts +45 -0
- package/src/utils/target.ts +145 -0
- package/src/utils/typegen.ts +193 -0
- package/src/utils/version.ts +76 -0
- package/scripts/index.js +0 -153779
package/src/api/new.ts
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
applyDefaultNewOptions,
|
|
5
|
+
NewOptions as RawNewOptions,
|
|
6
|
+
} from '../def/new.js'
|
|
7
|
+
import {
|
|
8
|
+
AVAILABLE_TARGETS,
|
|
9
|
+
CLI_VERSION,
|
|
10
|
+
debugFactory,
|
|
11
|
+
DEFAULT_TARGETS,
|
|
12
|
+
mkdirAsync,
|
|
13
|
+
writeFileAsync,
|
|
14
|
+
} from '../utils/index.js'
|
|
15
|
+
import { napiEngineRequirement } from '../utils/version.js'
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
createBuildRs,
|
|
19
|
+
createCargoToml,
|
|
20
|
+
createGithubActionsCIYml,
|
|
21
|
+
createLibRs,
|
|
22
|
+
createPackageJson,
|
|
23
|
+
gitIgnore,
|
|
24
|
+
npmIgnore,
|
|
25
|
+
} from './templates/index.js'
|
|
26
|
+
|
|
27
|
+
const debug = debugFactory('new')
|
|
28
|
+
|
|
29
|
+
interface Output {
|
|
30
|
+
target: string
|
|
31
|
+
content: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type NewOptions = Required<RawNewOptions>
|
|
35
|
+
|
|
36
|
+
function processOptions(options: RawNewOptions) {
|
|
37
|
+
debug('Processing options...')
|
|
38
|
+
options.path = path.resolve(process.cwd(), options.path)
|
|
39
|
+
debug(`Resolved target path to: ${options.path}`)
|
|
40
|
+
|
|
41
|
+
if (!options.name) {
|
|
42
|
+
options.name = path.parse(options.path).base
|
|
43
|
+
debug(`No project name provided, fix it to dir name: ${options.name}`)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!options.targets?.length) {
|
|
47
|
+
if (options.enableAllTargets) {
|
|
48
|
+
options.targets = AVAILABLE_TARGETS.concat()
|
|
49
|
+
debug('Enable all targets')
|
|
50
|
+
} else if (options.enableDefaultTargets) {
|
|
51
|
+
options.targets = DEFAULT_TARGETS.concat()
|
|
52
|
+
debug('Enable default targets')
|
|
53
|
+
} else {
|
|
54
|
+
throw new Error('At least one target must be enabled')
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return applyDefaultNewOptions(options) as NewOptions
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function newProject(userOptions: RawNewOptions) {
|
|
62
|
+
debug('Will create napi-rs project with given options:')
|
|
63
|
+
debug(userOptions)
|
|
64
|
+
|
|
65
|
+
const options = processOptions(userOptions)
|
|
66
|
+
|
|
67
|
+
debug('Targets to be enabled:')
|
|
68
|
+
debug(options.targets)
|
|
69
|
+
|
|
70
|
+
const outputs = generateFiles(options)
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
debug(`Try to create target directory: ${options.path}`)
|
|
74
|
+
if (!options.dryRun) {
|
|
75
|
+
await mkdirAsync(options.path, { recursive: true })
|
|
76
|
+
}
|
|
77
|
+
} catch (e) {
|
|
78
|
+
throw new Error(`Failed to create target directory: ${options.path}`, {
|
|
79
|
+
cause: e,
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
await dumpOutputs(outputs, options.dryRun)
|
|
84
|
+
debug(`Project created at: ${options.path}`)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function generateFiles(options: NewOptions): Output[] {
|
|
88
|
+
return [
|
|
89
|
+
generateCargoToml,
|
|
90
|
+
generateLibRs,
|
|
91
|
+
generateBuildRs,
|
|
92
|
+
generatePackageJson,
|
|
93
|
+
generateGithubWorkflow,
|
|
94
|
+
generateIgnoreFiles,
|
|
95
|
+
].flatMap((generator) => {
|
|
96
|
+
const output = generator(options)
|
|
97
|
+
|
|
98
|
+
if (!output) {
|
|
99
|
+
return []
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (Array.isArray(output)) {
|
|
103
|
+
return output.map((o) => ({
|
|
104
|
+
...o,
|
|
105
|
+
target: path.join(options.path, o.target),
|
|
106
|
+
}))
|
|
107
|
+
} else {
|
|
108
|
+
return [{ ...output, target: path.join(options.path, output.target) }]
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function generateCargoToml(options: NewOptions): Output {
|
|
114
|
+
return {
|
|
115
|
+
target: './Cargo.toml',
|
|
116
|
+
content: createCargoToml({
|
|
117
|
+
name: options.name,
|
|
118
|
+
license: options.license,
|
|
119
|
+
features: [`napi${options.minNodeApiVersion}`],
|
|
120
|
+
deriveFeatures: options.enableTypeDef ? ['type-def'] : [],
|
|
121
|
+
}),
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function generateLibRs(_options: NewOptions): Output {
|
|
126
|
+
return {
|
|
127
|
+
target: './src/lib.rs',
|
|
128
|
+
content: createLibRs(),
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function generateBuildRs(_options: NewOptions): Output {
|
|
133
|
+
return {
|
|
134
|
+
target: './build.rs',
|
|
135
|
+
content: createBuildRs(),
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function generatePackageJson(options: NewOptions): Output {
|
|
140
|
+
return {
|
|
141
|
+
target: './package.json',
|
|
142
|
+
content: createPackageJson({
|
|
143
|
+
name: options.name,
|
|
144
|
+
binaryName: getBinaryName(options.name),
|
|
145
|
+
targets: options.targets,
|
|
146
|
+
license: options.license,
|
|
147
|
+
engineRequirement: napiEngineRequirement(options.minNodeApiVersion),
|
|
148
|
+
cliVersion: CLI_VERSION,
|
|
149
|
+
}),
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function generateGithubWorkflow(options: NewOptions): Output | null {
|
|
154
|
+
if (!options.enableGithubActions) {
|
|
155
|
+
return null
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
target: './.github/workflows/ci.yml',
|
|
160
|
+
content: createGithubActionsCIYml(
|
|
161
|
+
getBinaryName(options.name),
|
|
162
|
+
options.targets,
|
|
163
|
+
),
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function generateIgnoreFiles(_options: NewOptions): Output[] {
|
|
168
|
+
return [
|
|
169
|
+
{
|
|
170
|
+
target: './.gitignore',
|
|
171
|
+
content: gitIgnore,
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
target: './.npmignore',
|
|
175
|
+
content: npmIgnore,
|
|
176
|
+
},
|
|
177
|
+
]
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function dumpOutputs(outputs: Output[], dryRun?: boolean) {
|
|
181
|
+
for (const output of outputs) {
|
|
182
|
+
if (!output) {
|
|
183
|
+
continue
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
debug(`Writing project file: ${output.target}`)
|
|
187
|
+
// only output content to logger instead of writing to file system
|
|
188
|
+
if (dryRun) {
|
|
189
|
+
debug(output.content)
|
|
190
|
+
continue
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
await mkdirAsync(path.dirname(output.target), { recursive: true })
|
|
195
|
+
await writeFileAsync(output.target, output.content, 'utf-8')
|
|
196
|
+
} catch (e) {
|
|
197
|
+
throw new Error(`Failed to write file: ${output.target}`, { cause: e })
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function getBinaryName(name: string): string {
|
|
203
|
+
return name.split('/').pop()!
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export { NewOptions }
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { execSync } from 'child_process'
|
|
2
|
+
import { existsSync, statSync } from 'fs'
|
|
3
|
+
import { join, relative, resolve } from 'path'
|
|
4
|
+
|
|
5
|
+
import { Octokit } from '@octokit/rest'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
applyDefaultPrePublishOptions,
|
|
9
|
+
PrePublishOptions,
|
|
10
|
+
} from '../def/pre-publish.js'
|
|
11
|
+
import {
|
|
12
|
+
readFileAsync,
|
|
13
|
+
readNapiConfig,
|
|
14
|
+
debugFactory,
|
|
15
|
+
updatePackageJson,
|
|
16
|
+
} from '../utils/index.js'
|
|
17
|
+
|
|
18
|
+
import { version } from './version.js'
|
|
19
|
+
|
|
20
|
+
const debug = debugFactory('pre-publish')
|
|
21
|
+
|
|
22
|
+
interface PackageInfo {
|
|
23
|
+
name: string
|
|
24
|
+
version: string
|
|
25
|
+
tag: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function prePublish(userOptions: PrePublishOptions) {
|
|
29
|
+
debug('Receive pre-publish options:')
|
|
30
|
+
debug(' %O', userOptions)
|
|
31
|
+
|
|
32
|
+
const options = applyDefaultPrePublishOptions(userOptions)
|
|
33
|
+
|
|
34
|
+
const packageJsonPath = relative(options.cwd, options.packageJsonPath)
|
|
35
|
+
|
|
36
|
+
const { packageJson, targets, packageName, binaryName, npmClient } =
|
|
37
|
+
await readNapiConfig(packageJsonPath)
|
|
38
|
+
|
|
39
|
+
async function createGhRelease(packageName: string, version: string) {
|
|
40
|
+
if (!options.ghRelease) {
|
|
41
|
+
return {
|
|
42
|
+
owner: null,
|
|
43
|
+
repo: null,
|
|
44
|
+
pkgInfo: { name: null, version: null, tag: null },
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const { repo, owner, pkgInfo, octokit } = getRepoInfo(packageName, version)
|
|
48
|
+
|
|
49
|
+
if (!repo || !owner) {
|
|
50
|
+
return {
|
|
51
|
+
owner: null,
|
|
52
|
+
repo: null,
|
|
53
|
+
pkgInfo: { name: null, version: null, tag: null },
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!options.dryRun) {
|
|
58
|
+
try {
|
|
59
|
+
await octokit.repos.createRelease({
|
|
60
|
+
owner,
|
|
61
|
+
repo,
|
|
62
|
+
tag_name: pkgInfo.tag,
|
|
63
|
+
name: options.ghReleaseName,
|
|
64
|
+
prerelease:
|
|
65
|
+
version.includes('alpha') ||
|
|
66
|
+
version.includes('beta') ||
|
|
67
|
+
version.includes('rc'),
|
|
68
|
+
})
|
|
69
|
+
} catch (e) {
|
|
70
|
+
debug(
|
|
71
|
+
`Params: ${JSON.stringify(
|
|
72
|
+
{ owner, repo, tag_name: pkgInfo.tag },
|
|
73
|
+
null,
|
|
74
|
+
2,
|
|
75
|
+
)}`,
|
|
76
|
+
)
|
|
77
|
+
console.error(e)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { owner, repo, pkgInfo, octokit }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function getRepoInfo(packageName: string, version: string) {
|
|
84
|
+
const headCommit = execSync('git log -1 --pretty=%B', {
|
|
85
|
+
encoding: 'utf-8',
|
|
86
|
+
}).trim()
|
|
87
|
+
|
|
88
|
+
const { GITHUB_REPOSITORY } = process.env
|
|
89
|
+
if (!GITHUB_REPOSITORY) {
|
|
90
|
+
return {
|
|
91
|
+
owner: null,
|
|
92
|
+
repo: null,
|
|
93
|
+
pkgInfo: { name: null, version: null, tag: null },
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
debug(`Github repository: ${GITHUB_REPOSITORY}`)
|
|
97
|
+
const [owner, repo] = GITHUB_REPOSITORY.split('/')
|
|
98
|
+
const octokit = new Octokit({
|
|
99
|
+
auth: process.env.GITHUB_TOKEN,
|
|
100
|
+
})
|
|
101
|
+
let pkgInfo: PackageInfo | undefined
|
|
102
|
+
if (options.tagStyle === 'lerna') {
|
|
103
|
+
const packagesToPublish = headCommit
|
|
104
|
+
.split('\n')
|
|
105
|
+
.map((line) => line.trim())
|
|
106
|
+
.filter((line, index) => line.length && index)
|
|
107
|
+
.map((line) => line.substring(2))
|
|
108
|
+
.map(parseTag)
|
|
109
|
+
|
|
110
|
+
pkgInfo = packagesToPublish.find(
|
|
111
|
+
(pkgInfo) => pkgInfo.name === packageName,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
if (!pkgInfo) {
|
|
115
|
+
throw new TypeError(
|
|
116
|
+
`No release commit found with ${packageName}, original commit info: ${headCommit}`,
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
pkgInfo = {
|
|
121
|
+
tag: `v${version}`,
|
|
122
|
+
version,
|
|
123
|
+
name: packageName,
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return { owner, repo, pkgInfo, octokit }
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (!options.dryRun) {
|
|
130
|
+
await version(userOptions)
|
|
131
|
+
await updatePackageJson(packageJsonPath, {
|
|
132
|
+
optionalDependencies: targets.reduce((deps, target) => {
|
|
133
|
+
deps[`${packageName}-${target.platformArchABI}`] = packageJson.version
|
|
134
|
+
|
|
135
|
+
return deps
|
|
136
|
+
}, {} as Record<string, string>),
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const { owner, repo, pkgInfo, octokit } = options.ghReleaseId
|
|
141
|
+
? getRepoInfo(packageName, packageJson.version)
|
|
142
|
+
: await createGhRelease(packageName, packageJson.version)
|
|
143
|
+
|
|
144
|
+
for (const target of targets) {
|
|
145
|
+
const pkgDir = resolve(
|
|
146
|
+
options.cwd,
|
|
147
|
+
options.npmDir,
|
|
148
|
+
`${target.platformArchABI}`,
|
|
149
|
+
)
|
|
150
|
+
const filename = `${binaryName}.${target.platformArchABI}.node`
|
|
151
|
+
const dstPath = join(pkgDir, filename)
|
|
152
|
+
|
|
153
|
+
if (!options.dryRun) {
|
|
154
|
+
if (!existsSync(dstPath)) {
|
|
155
|
+
debug.warn(`%s doesn't exist`, dstPath)
|
|
156
|
+
continue
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
execSync(`${npmClient} publish`, {
|
|
160
|
+
cwd: pkgDir,
|
|
161
|
+
env: process.env,
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
if (options.ghRelease && repo && owner) {
|
|
165
|
+
debug.info(`Creating GitHub release ${pkgInfo.tag}`)
|
|
166
|
+
try {
|
|
167
|
+
const releaseId = options.ghReleaseId
|
|
168
|
+
? Number(options.ghReleaseId)
|
|
169
|
+
: (
|
|
170
|
+
await octokit!.repos.getReleaseByTag({
|
|
171
|
+
repo: repo,
|
|
172
|
+
owner: owner,
|
|
173
|
+
tag: pkgInfo.tag,
|
|
174
|
+
})
|
|
175
|
+
).data.id
|
|
176
|
+
const dstFileStats = statSync(dstPath)
|
|
177
|
+
const assetInfo = await octokit!.repos.uploadReleaseAsset({
|
|
178
|
+
owner: owner,
|
|
179
|
+
repo: repo,
|
|
180
|
+
name: filename,
|
|
181
|
+
release_id: releaseId,
|
|
182
|
+
mediaType: { format: 'raw' },
|
|
183
|
+
headers: {
|
|
184
|
+
'content-length': dstFileStats.size,
|
|
185
|
+
'content-type': 'application/octet-stream',
|
|
186
|
+
},
|
|
187
|
+
data: await readFileAsync(dstPath, { encoding: 'utf-8' }),
|
|
188
|
+
})
|
|
189
|
+
debug.info(`GitHub release created`)
|
|
190
|
+
debug.info(`Download URL: %s`, assetInfo.data.browser_download_url)
|
|
191
|
+
} catch (e) {
|
|
192
|
+
debug.error(
|
|
193
|
+
`Param: ${JSON.stringify(
|
|
194
|
+
{ owner, repo, tag: pkgInfo.tag, filename: dstPath },
|
|
195
|
+
null,
|
|
196
|
+
2,
|
|
197
|
+
)}`,
|
|
198
|
+
)
|
|
199
|
+
debug.error(e)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function parseTag(tag: string) {
|
|
207
|
+
const segments = tag.split('@')
|
|
208
|
+
const version = segments.pop()!
|
|
209
|
+
const name = segments.join('@')
|
|
210
|
+
|
|
211
|
+
return {
|
|
212
|
+
name,
|
|
213
|
+
version,
|
|
214
|
+
tag,
|
|
215
|
+
}
|
|
216
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { resolve } from 'path'
|
|
2
|
+
|
|
3
|
+
import { isNil, merge, omitBy, pick } from 'lodash-es'
|
|
4
|
+
|
|
5
|
+
import { applyDefaultRenameOptions, RenameOptions } from '../def/rename.js'
|
|
6
|
+
import { readFileAsync, writeFileAsync } from '../utils/index.js'
|
|
7
|
+
|
|
8
|
+
import { createNpmDirs } from './create-npm-dirs.js'
|
|
9
|
+
|
|
10
|
+
export async function renameProject(userOptions: RenameOptions) {
|
|
11
|
+
const options = applyDefaultRenameOptions(userOptions)
|
|
12
|
+
|
|
13
|
+
const packageJsonPath = resolve(options.cwd, options.packageJsonPath)
|
|
14
|
+
const cargoTomlPath = resolve(options.cwd, options.manifestPath)
|
|
15
|
+
|
|
16
|
+
const packageJsonContent = await readFileAsync(packageJsonPath, 'utf8')
|
|
17
|
+
const packageJsonData = JSON.parse(packageJsonContent)
|
|
18
|
+
|
|
19
|
+
merge(
|
|
20
|
+
packageJsonData,
|
|
21
|
+
omitBy(pick(options, ['name', 'description', 'author', 'license']), isNil),
|
|
22
|
+
{
|
|
23
|
+
napi: omitBy(
|
|
24
|
+
{
|
|
25
|
+
binaryName: options.binaryName,
|
|
26
|
+
packageName: options.packageName,
|
|
27
|
+
},
|
|
28
|
+
isNil,
|
|
29
|
+
),
|
|
30
|
+
},
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
await writeFileAsync(
|
|
34
|
+
packageJsonPath,
|
|
35
|
+
JSON.stringify(packageJsonData, null, 2),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
let tomlContent = await readFileAsync(cargoTomlPath, 'utf8')
|
|
39
|
+
tomlContent = tomlContent.replace(
|
|
40
|
+
/name\s?=\s?"([\w+])"/,
|
|
41
|
+
`name = "${options.binaryName}"`,
|
|
42
|
+
)
|
|
43
|
+
await writeFileAsync(cargoTomlPath, tomlContent)
|
|
44
|
+
|
|
45
|
+
await createNpmDirs({
|
|
46
|
+
cwd: options.cwd,
|
|
47
|
+
packageJsonPath: options.packageJsonPath,
|
|
48
|
+
npmDir: options.npmDir,
|
|
49
|
+
dryRun: false,
|
|
50
|
+
})
|
|
51
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
export const gitIgnore = `# Created by https://www.toptal.com/developers/gitignore/api/node
|
|
2
|
+
# Edit at https://www.toptal.com/developers/gitignore?templates=node
|
|
3
|
+
|
|
4
|
+
### Node ###
|
|
5
|
+
# Logs
|
|
6
|
+
logs
|
|
7
|
+
*.log
|
|
8
|
+
npm-debug.log*
|
|
9
|
+
yarn-debug.log*
|
|
10
|
+
yarn-error.log*
|
|
11
|
+
lerna-debug.log*
|
|
12
|
+
|
|
13
|
+
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
14
|
+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
15
|
+
|
|
16
|
+
# Runtime data
|
|
17
|
+
pids
|
|
18
|
+
*.pid
|
|
19
|
+
*.seed
|
|
20
|
+
*.pid.lock
|
|
21
|
+
|
|
22
|
+
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
23
|
+
lib-cov
|
|
24
|
+
|
|
25
|
+
# Coverage directory used by tools like istanbul
|
|
26
|
+
coverage
|
|
27
|
+
*.lcov
|
|
28
|
+
|
|
29
|
+
# nyc test coverage
|
|
30
|
+
.nyc_output
|
|
31
|
+
|
|
32
|
+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
33
|
+
.grunt
|
|
34
|
+
|
|
35
|
+
# Bower dependency directory (https://bower.io/)
|
|
36
|
+
bower_components
|
|
37
|
+
|
|
38
|
+
# node-waf configuration
|
|
39
|
+
.lock-wscript
|
|
40
|
+
|
|
41
|
+
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
42
|
+
build/Release
|
|
43
|
+
|
|
44
|
+
# Dependency directories
|
|
45
|
+
node_modules/
|
|
46
|
+
jspm_packages/
|
|
47
|
+
|
|
48
|
+
# TypeScript v1 declaration files
|
|
49
|
+
typings/
|
|
50
|
+
|
|
51
|
+
# TypeScript cache
|
|
52
|
+
*.tsbuildinfo
|
|
53
|
+
|
|
54
|
+
# Optional npm cache directory
|
|
55
|
+
.npm
|
|
56
|
+
|
|
57
|
+
# Optional eslint cache
|
|
58
|
+
.eslintcache
|
|
59
|
+
|
|
60
|
+
# Microbundle cache
|
|
61
|
+
.rpt2_cache/
|
|
62
|
+
.rts2_cache_cjs/
|
|
63
|
+
.rts2_cache_es/
|
|
64
|
+
.rts2_cache_umd/
|
|
65
|
+
|
|
66
|
+
# Optional REPL history
|
|
67
|
+
.node_repl_history
|
|
68
|
+
|
|
69
|
+
# Output of 'npm pack'
|
|
70
|
+
*.tgz
|
|
71
|
+
|
|
72
|
+
# Yarn Integrity file
|
|
73
|
+
.yarn-integrity
|
|
74
|
+
|
|
75
|
+
# dotenv environment variables file
|
|
76
|
+
.env
|
|
77
|
+
.env.test
|
|
78
|
+
|
|
79
|
+
# parcel-bundler cache (https://parceljs.org/)
|
|
80
|
+
.cache
|
|
81
|
+
|
|
82
|
+
# Next.js build output
|
|
83
|
+
.next
|
|
84
|
+
|
|
85
|
+
# Nuxt.js build / generate output
|
|
86
|
+
.nuxt
|
|
87
|
+
dist
|
|
88
|
+
|
|
89
|
+
# Gatsby files
|
|
90
|
+
.cache/
|
|
91
|
+
# Comment in the public line in if your project uses Gatsby and not Next.js
|
|
92
|
+
# https://nextjs.org/blog/next-9-1#public-directory-support
|
|
93
|
+
# public
|
|
94
|
+
|
|
95
|
+
# vuepress build output
|
|
96
|
+
.vuepress/dist
|
|
97
|
+
|
|
98
|
+
# Serverless directories
|
|
99
|
+
.serverless/
|
|
100
|
+
|
|
101
|
+
# FuseBox cache
|
|
102
|
+
.fusebox/
|
|
103
|
+
|
|
104
|
+
# DynamoDB Local files
|
|
105
|
+
.dynamodb/
|
|
106
|
+
|
|
107
|
+
# TernJS port file
|
|
108
|
+
.tern-port
|
|
109
|
+
|
|
110
|
+
# Stores VSCode versions used for testing VSCode extensions
|
|
111
|
+
.vscode-test
|
|
112
|
+
|
|
113
|
+
# End of https://www.toptal.com/developers/gitignore/api/node
|
|
114
|
+
|
|
115
|
+
# Created by https://www.toptal.com/developers/gitignore/api/macos
|
|
116
|
+
# Edit at https://www.toptal.com/developers/gitignore?templates=macos
|
|
117
|
+
|
|
118
|
+
### macOS ###
|
|
119
|
+
# General
|
|
120
|
+
.DS_Store
|
|
121
|
+
.AppleDouble
|
|
122
|
+
.LSOverride
|
|
123
|
+
|
|
124
|
+
# Icon must end with two \r
|
|
125
|
+
Icon
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
# Thumbnails
|
|
129
|
+
._*
|
|
130
|
+
|
|
131
|
+
# Files that might appear in the root of a volume
|
|
132
|
+
.DocumentRevisions-V100
|
|
133
|
+
.fseventsd
|
|
134
|
+
.Spotlight-V100
|
|
135
|
+
.TemporaryItems
|
|
136
|
+
.Trashes
|
|
137
|
+
.VolumeIcon.icns
|
|
138
|
+
.com.apple.timemachine.donotpresent
|
|
139
|
+
|
|
140
|
+
# Directories potentially created on remote AFP share
|
|
141
|
+
.AppleDB
|
|
142
|
+
.AppleDesktop
|
|
143
|
+
Network Trash Folder
|
|
144
|
+
Temporary Items
|
|
145
|
+
.apdisk
|
|
146
|
+
|
|
147
|
+
### macOS Patch ###
|
|
148
|
+
# iCloud generated files
|
|
149
|
+
*.icloud
|
|
150
|
+
|
|
151
|
+
# End of https://www.toptal.com/developers/gitignore/api/macos
|
|
152
|
+
|
|
153
|
+
# Created by https://www.toptal.com/developers/gitignore/api/windows
|
|
154
|
+
# Edit at https://www.toptal.com/developers/gitignore?templates=windows
|
|
155
|
+
|
|
156
|
+
### Windows ###
|
|
157
|
+
# Windows thumbnail cache files
|
|
158
|
+
Thumbs.db
|
|
159
|
+
Thumbs.db:encryptable
|
|
160
|
+
ehthumbs.db
|
|
161
|
+
ehthumbs_vista.db
|
|
162
|
+
|
|
163
|
+
# Dump file
|
|
164
|
+
*.stackdump
|
|
165
|
+
|
|
166
|
+
# Folder config file
|
|
167
|
+
[Dd]esktop.ini
|
|
168
|
+
|
|
169
|
+
# Recycle Bin used on file shares
|
|
170
|
+
$RECYCLE.BIN/
|
|
171
|
+
|
|
172
|
+
# Windows Installer files
|
|
173
|
+
*.cab
|
|
174
|
+
*.msi
|
|
175
|
+
*.msix
|
|
176
|
+
*.msm
|
|
177
|
+
*.msp
|
|
178
|
+
|
|
179
|
+
# Windows shortcuts
|
|
180
|
+
*.lnk
|
|
181
|
+
|
|
182
|
+
# End of https://www.toptal.com/developers/gitignore/api/windows
|
|
183
|
+
|
|
184
|
+
#Added by cargo
|
|
185
|
+
|
|
186
|
+
/target
|
|
187
|
+
Cargo.lock
|
|
188
|
+
|
|
189
|
+
.pnp.*
|
|
190
|
+
.yarn/*
|
|
191
|
+
!.yarn/patches
|
|
192
|
+
!.yarn/plugins
|
|
193
|
+
!.yarn/releases
|
|
194
|
+
!.yarn/sdks
|
|
195
|
+
!.yarn/versions
|
|
196
|
+
|
|
197
|
+
*.node
|
|
198
|
+
`
|