@napi-rs/cli 3.0.0-alpha.1 → 3.0.0-alpha.100

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.
Files changed (176) hide show
  1. package/cli.mjs +1 -1
  2. package/dist/api/__tests__/create-npm-dirs.spec.d.ts +1 -0
  3. package/dist/api/__tests__/new.spec.d.ts +1 -0
  4. package/dist/api/build.d.ts +2 -2
  5. package/dist/api/create-npm-dirs.d.ts +5 -0
  6. package/dist/api/templates/index.d.ts +0 -7
  7. package/dist/api/templates/js-binding.d.ts +2 -1
  8. package/dist/api/templates/load-wasi-template.d.ts +2 -0
  9. package/dist/api/templates/wasi-worker-template.d.ts +2 -0
  10. package/dist/cli.js +3961 -14
  11. package/dist/def/artifacts.d.ts +21 -1
  12. package/dist/def/build.d.ts +167 -4
  13. package/dist/def/create-npm-dirs.d.ts +10 -0
  14. package/dist/def/new.d.ts +25 -7
  15. package/dist/def/pre-publish.d.ts +21 -2
  16. package/dist/def/rename.d.ts +16 -6
  17. package/dist/def/universalize.d.ts +10 -0
  18. package/dist/def/version.d.ts +10 -0
  19. package/dist/index.cjs +10142 -20524
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.js +3711 -29
  22. package/dist/utils/__tests__/config.spec.d.ts +1 -0
  23. package/dist/utils/config.d.ts +70 -6
  24. package/dist/utils/index.d.ts +1 -1
  25. package/dist/utils/metadata.d.ts +13 -1
  26. package/dist/utils/misc.d.ts +3 -3
  27. package/dist/utils/read-config.d.ts +7 -0
  28. package/dist/utils/target.d.ts +9 -6
  29. package/dist/utils/typegen.d.ts +4 -1
  30. package/dist/utils/version.d.ts +2 -1
  31. package/package.json +60 -24
  32. package/src/api/__tests__/create-npm-dirs.spec.ts +210 -0
  33. package/src/api/__tests__/new.spec.ts +429 -0
  34. package/src/api/artifacts.ts +83 -8
  35. package/src/api/build.ts +682 -134
  36. package/src/api/create-npm-dirs.ts +64 -13
  37. package/src/api/new.ts +389 -125
  38. package/src/api/pre-publish.ts +27 -16
  39. package/src/api/rename.ts +103 -17
  40. package/src/api/templates/index.ts +0 -7
  41. package/src/api/templates/js-binding.ts +212 -107
  42. package/src/api/templates/load-wasi-template.ts +216 -0
  43. package/src/api/templates/wasi-worker-template.ts +122 -0
  44. package/src/api/universalize.ts +13 -8
  45. package/src/api/version.ts +5 -2
  46. package/src/commands/artifacts.ts +2 -2
  47. package/src/commands/build.ts +1 -1
  48. package/src/commands/new.ts +46 -49
  49. package/src/def/artifacts.ts +22 -3
  50. package/src/def/build.ts +83 -8
  51. package/src/def/create-npm-dirs.ts +9 -0
  52. package/src/def/new.ts +28 -3
  53. package/src/def/pre-publish.ts +24 -3
  54. package/src/def/rename.ts +11 -2
  55. package/src/def/universalize.ts +9 -0
  56. package/src/def/version.ts +9 -0
  57. package/src/index.ts +2 -0
  58. package/src/utils/__tests__/__fixtures__/napi_type_def +130 -130
  59. package/src/utils/__tests__/__snapshots__/config.spec.ts.md +97 -0
  60. package/src/utils/__tests__/__snapshots__/config.spec.ts.snap +0 -0
  61. package/src/utils/__tests__/__snapshots__/target.spec.ts.md +56 -0
  62. package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
  63. package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +703 -164
  64. package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
  65. package/src/utils/__tests__/__snapshots__/version.spec.ts.md +9 -8
  66. package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
  67. package/src/utils/__tests__/config.spec.ts +81 -0
  68. package/src/utils/__tests__/typegen.spec.ts +19 -4
  69. package/src/utils/cargo.ts +2 -2
  70. package/src/utils/config.ts +147 -13
  71. package/src/utils/index.ts +1 -1
  72. package/src/utils/log.ts +1 -1
  73. package/src/utils/metadata.ts +52 -14
  74. package/src/utils/misc.ts +21 -7
  75. package/src/utils/read-config.ts +20 -0
  76. package/src/utils/target.ts +53 -9
  77. package/src/utils/typegen.ts +100 -40
  78. package/src/utils/version.ts +11 -9
  79. package/dist/api/artifacts.js +0 -50
  80. package/dist/api/build.js +0 -404
  81. package/dist/api/create-npm-dirs.js +0 -63
  82. package/dist/api/new.js +0 -154
  83. package/dist/api/pre-publish.js +0 -157
  84. package/dist/api/rename.js +0 -28
  85. package/dist/api/templates/.gitignore.d.ts +0 -1
  86. package/dist/api/templates/.gitignore.js +0 -198
  87. package/dist/api/templates/.npmignore.d.ts +0 -1
  88. package/dist/api/templates/.npmignore.js +0 -14
  89. package/dist/api/templates/build.rs.d.ts +0 -1
  90. package/dist/api/templates/build.rs.js +0 -4
  91. package/dist/api/templates/cargo.toml.d.ts +0 -6
  92. package/dist/api/templates/cargo.toml.js +0 -25
  93. package/dist/api/templates/ci-template.d.ts +0 -1
  94. package/dist/api/templates/ci-template.js +0 -566
  95. package/dist/api/templates/ci.yml.d.ts +0 -1
  96. package/dist/api/templates/ci.yml.js +0 -92
  97. package/dist/api/templates/index.js +0 -8
  98. package/dist/api/templates/js-binding.js +0 -124
  99. package/dist/api/templates/lib.rs.d.ts +0 -1
  100. package/dist/api/templates/lib.rs.js +0 -10
  101. package/dist/api/templates/package.json.d.ts +0 -8
  102. package/dist/api/templates/package.json.js +0 -30
  103. package/dist/api/universalize.js +0 -38
  104. package/dist/api/version.js +0 -16
  105. package/dist/commands/artifacts.js +0 -19
  106. package/dist/commands/build.js +0 -34
  107. package/dist/commands/create-npm-dirs.js +0 -7
  108. package/dist/commands/help.js +0 -12
  109. package/dist/commands/new.js +0 -112
  110. package/dist/commands/pre-publish.js +0 -8
  111. package/dist/commands/rename.js +0 -7
  112. package/dist/commands/universalize.js +0 -7
  113. package/dist/commands/version.js +0 -7
  114. package/dist/def/artifacts.js +0 -38
  115. package/dist/def/build.js +0 -105
  116. package/dist/def/commands/artifacts.d.ts +0 -15
  117. package/dist/def/commands/artifacts.js +0 -29
  118. package/dist/def/commands/build.d.ts +0 -53
  119. package/dist/def/commands/build.js +0 -105
  120. package/dist/def/commands/create-npm-dirs.d.ts +0 -15
  121. package/dist/def/commands/create-npm-dirs.js +0 -29
  122. package/dist/def/commands/new.d.ts +0 -27
  123. package/dist/def/commands/new.js +0 -53
  124. package/dist/def/commands/pre-publish.d.ts +0 -23
  125. package/dist/def/commands/pre-publish.js +0 -45
  126. package/dist/def/commands/rename.d.ts +0 -25
  127. package/dist/def/commands/rename.js +0 -49
  128. package/dist/def/commands/universalize.d.ts +0 -13
  129. package/dist/def/commands/universalize.js +0 -25
  130. package/dist/def/commands/version.d.ts +0 -13
  131. package/dist/def/commands/version.js +0 -25
  132. package/dist/def/create-npm-dirs.js +0 -38
  133. package/dist/def/new.js +0 -66
  134. package/dist/def/options/artifacts.d.ts +0 -35
  135. package/dist/def/options/artifacts.js +0 -11
  136. package/dist/def/options/build.d.ts +0 -97
  137. package/dist/def/options/build.js +0 -3
  138. package/dist/def/options/create-npm-dirs.d.ts +0 -35
  139. package/dist/def/options/create-npm-dirs.js +0 -11
  140. package/dist/def/options/new.d.ts +0 -79
  141. package/dist/def/options/new.js +0 -15
  142. package/dist/def/options/pre-publish.d.ts +0 -65
  143. package/dist/def/options/pre-publish.js +0 -13
  144. package/dist/def/options/rename.d.ts +0 -75
  145. package/dist/def/options/rename.js +0 -11
  146. package/dist/def/options/universalize.d.ts +0 -28
  147. package/dist/def/options/universalize.js +0 -10
  148. package/dist/def/options/version.d.ts +0 -28
  149. package/dist/def/options/version.js +0 -10
  150. package/dist/def/pre-publish.js +0 -56
  151. package/dist/def/rename.js +0 -58
  152. package/dist/def/universalize.js +0 -33
  153. package/dist/def/version.js +0 -33
  154. package/dist/utils/__tests__/target.spec.js +0 -10
  155. package/dist/utils/__tests__/typegen.spec.js +0 -37
  156. package/dist/utils/__tests__/version.spec.js +0 -5
  157. package/dist/utils/cargo.js +0 -33
  158. package/dist/utils/ci.d.ts +0 -11
  159. package/dist/utils/ci.js +0 -86
  160. package/dist/utils/config.js +0 -42
  161. package/dist/utils/index.js +0 -9
  162. package/dist/utils/log.js +0 -14
  163. package/dist/utils/metadata.js +0 -19
  164. package/dist/utils/misc.js +0 -35
  165. package/dist/utils/target.js +0 -109
  166. package/dist/utils/typegen.js +0 -158
  167. package/dist/utils/version.js +0 -59
  168. package/src/api/templates/.gitignore.ts +0 -198
  169. package/src/api/templates/.npmignore.ts +0 -14
  170. package/src/api/templates/build.rs.ts +0 -4
  171. package/src/api/templates/cargo.toml.ts +0 -35
  172. package/src/api/templates/ci-template.ts +0 -566
  173. package/src/api/templates/ci.yml.ts +0 -116
  174. package/src/api/templates/lib.rs.ts +0 -10
  175. package/src/api/templates/package.json.ts +0 -44
  176. package/src/utils/ci.ts +0 -102
@@ -1,124 +0,0 @@
1
- /* eslint-disable @typescript-eslint/switch-exhaustiveness-check */
2
- function loadNapiModule(binaryName, packageName) {
3
- const { existsSync, readFileSync } = require('fs');
4
- const { join } = require('path');
5
- const { platform, arch } = process;
6
- const candidates = [];
7
- function isMusl() {
8
- // For Node 10
9
- if (!process.report || typeof process.report.getReport !== 'function') {
10
- try {
11
- const lddPath = require('child_process')
12
- .execSync('which ldd')
13
- .toString()
14
- .trim();
15
- return readFileSync(lddPath, 'utf8').includes('musl');
16
- }
17
- catch (e) {
18
- return true;
19
- }
20
- }
21
- else {
22
- // @ts-expect-error
23
- const { glibcVersionRuntime } = process.report.getReport().header;
24
- return !glibcVersionRuntime;
25
- }
26
- }
27
- switch (platform) {
28
- case 'android':
29
- switch (arch) {
30
- case 'arm64':
31
- candidates.push('android-arm64');
32
- break;
33
- case 'arm':
34
- candidates.push('android-arm-eabi');
35
- break;
36
- }
37
- break;
38
- case 'win32':
39
- switch (arch) {
40
- case 'x64':
41
- candidates.push('win32-x64-msvc');
42
- break;
43
- case 'ia32':
44
- candidates.push('win32-ia32-msvc');
45
- break;
46
- case 'arm64':
47
- candidates.push('win32-arm64-msvc');
48
- break;
49
- }
50
- break;
51
- case 'darwin':
52
- candidates.push('darwin-universal');
53
- switch (arch) {
54
- case 'x64':
55
- candidates.push('darwin-x64');
56
- break;
57
- case 'arm64':
58
- candidates.push('darwin-arm64');
59
- break;
60
- }
61
- break;
62
- case 'freebsd':
63
- if (arch === 'x64') {
64
- candidates.push('freebsd-x64');
65
- }
66
- break;
67
- case 'linux':
68
- switch (arch) {
69
- case 'x64':
70
- if (isMusl()) {
71
- candidates.push('linux-x64-musl');
72
- }
73
- else {
74
- candidates.push('linux-x64-gnu');
75
- }
76
- break;
77
- case 'arm64':
78
- if (isMusl()) {
79
- candidates.push('linux-arm64-musl');
80
- }
81
- else {
82
- candidates.push('linux-arm64-gnu');
83
- }
84
- break;
85
- case 'arm':
86
- candidates.push('linux-arm-gnueabihf');
87
- break;
88
- }
89
- break;
90
- }
91
- let nativeBinding;
92
- let loadError;
93
- for (const suffix of candidates) {
94
- const localPath = join(__dirname, `${binaryName}.${suffix}.node`);
95
- const pkgPath = `${packageName}-${suffix}`;
96
- try {
97
- if (existsSync(localPath)) {
98
- nativeBinding = require(localPath);
99
- }
100
- else {
101
- nativeBinding = require(pkgPath);
102
- }
103
- }
104
- catch (e) {
105
- loadError = e;
106
- continue;
107
- }
108
- loadError = null;
109
- break;
110
- }
111
- if (!nativeBinding) {
112
- if (loadError) {
113
- throw loadError;
114
- }
115
- throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
116
- }
117
- return nativeBinding;
118
- }
119
- export function createJsBinding(localName, pkgName) {
120
- return `${loadNapiModule.toString()}
121
-
122
- module.exports = loadNapiModule('${localName}', '${pkgName}')
123
- `;
124
- }
@@ -1 +0,0 @@
1
- export declare const createLibRs: () => string;
@@ -1,10 +0,0 @@
1
- export const createLibRs = () => `#![deny(clippy::all)]
2
-
3
- #[macro_use]
4
- extern crate napi_derive;
5
-
6
- #[napi]
7
- pub fn sum(a: i32, b: i32) -> i32 {
8
- a + b
9
- }
10
- `;
@@ -1,8 +0,0 @@
1
- export declare const createPackageJson: ({ name, binaryName, targets, license, engineRequirement, cliVersion, }: {
2
- name: string;
3
- binaryName: string;
4
- targets: string[];
5
- license: string;
6
- engineRequirement: string;
7
- cliVersion: string;
8
- }) => string;
@@ -1,30 +0,0 @@
1
- export const createPackageJson = ({ name, binaryName, targets, license, engineRequirement, cliVersion, }) => {
2
- return `{
3
- "name": "${name}",
4
- "version": "1.0.0",
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "license": "${license}",
8
- "engines": {
9
- "node": "${engineRequirement}"
10
- },
11
- "napi": {
12
- "name": "${binaryName}",
13
- "targets": [
14
- ${targets.map((t) => `"${t}"`).join(',\n ')}
15
- ]
16
- },
17
- "scripts": {
18
- "test": "yarn build:debug --platform && node -e \\"assert(require('.').sum(1, 2) === 3)\\"",
19
- "build": "napi build --release --platform --strip",
20
- "build:debug": "napi build",
21
- "prepublishOnly": "napi prepublish -t npm",
22
- "artifacts": "napi artifacts",
23
- "universal": "napi universal",
24
- "version": "napi version"
25
- },
26
- "devDependencies": {
27
- "@napi-rs/cli": "^${cliVersion}"
28
- }
29
- }`;
30
- };
@@ -1,38 +0,0 @@
1
- import { spawnSync } from 'child_process';
2
- import { join, resolve } from 'path';
3
- import { applyDefaultUniversalizeOptions, } from '../def/universalize.js';
4
- import { readNapiConfig } from '../utils/config.js';
5
- import { debugFactory } from '../utils/log.js';
6
- import { fileExists } from '../utils/misc.js';
7
- import { UniArchsByPlatform } from '../utils/target.js';
8
- const debug = debugFactory('universalize');
9
- const universalizers = {
10
- darwin: (inputs, output) => {
11
- spawnSync('lipo', ['-create', '-output', output, ...inputs], {
12
- stdio: 'inherit',
13
- });
14
- },
15
- };
16
- export async function universalizeBinaries(userOptions) {
17
- const options = applyDefaultUniversalizeOptions(userOptions);
18
- const packageJsonPath = join(options.cwd, options.packageJsonPath);
19
- const config = await readNapiConfig(packageJsonPath);
20
- const target = config.targets.find((t) => t.platform === process.platform && t.arch === 'universal');
21
- if (!target) {
22
- throw new Error(`'universal' arch for platform '${process.platform}' not found in config!`);
23
- }
24
- const srcFiles = UniArchsByPlatform[process.platform]?.map((arch) => `${config.binaryName}.${process.platform}-${arch}.node`);
25
- if (!srcFiles || !universalizers[process.platform]) {
26
- throw new Error(`'universal' arch for platform '${process.platform}' not supported.`);
27
- }
28
- debug(`Looking up source binaries to combine: `);
29
- debug(' %O', srcFiles);
30
- const srcFileLookup = await Promise.all(srcFiles.map((f) => fileExists(resolve(options.cwd, options.outputDir, f))));
31
- const notFoundFiles = srcFiles.filter((_, i) => !srcFileLookup[i]);
32
- if (notFoundFiles.length) {
33
- throw new Error(`Some binary files were not found: ${JSON.stringify(notFoundFiles)}`);
34
- }
35
- const output = resolve(options.cwd, options.outputDir, `${config.binaryName}.${process.platform}-universal.node`);
36
- universalizers[process.platform]?.(srcFiles, output);
37
- debug(`Produced universal binary: ${output}`);
38
- }
@@ -1,16 +0,0 @@
1
- import { join, resolve } from 'path';
2
- import { applyDefaultVersionOptions } from '../def/version.js';
3
- import { readNapiConfig, debugFactory, updatePackageJson, } from '../utils/index.js';
4
- const debug = debugFactory('version');
5
- export async function version(userOptions) {
6
- const options = applyDefaultVersionOptions(userOptions);
7
- const packageJsonPath = resolve(options.cwd, options.packageJsonPath);
8
- const config = await readNapiConfig(packageJsonPath);
9
- for (const target of config.targets) {
10
- const pkgDir = resolve(options.cwd, options.npmDir, target.platformArchABI);
11
- debug(`Update version to %i in [%i]`, config.packageJson.version, pkgDir);
12
- await updatePackageJson(join(pkgDir, 'package.json'), {
13
- version: config.packageJson.version,
14
- });
15
- }
16
- }
@@ -1,19 +0,0 @@
1
- import { Command } from 'clipanion';
2
- import { collectArtifacts } from '../api/artifacts.js';
3
- import { BaseArtifactsCommand } from '../def/artifacts.js';
4
- export class ArtifactsCommand extends BaseArtifactsCommand {
5
- static usage = Command.Usage({
6
- description: 'Copy artifacts from Github Actions into specified dir',
7
- examples: [
8
- [
9
- '$0 artifacts --dir . --dist ./npm',
10
- `Copy [binaryName].[platform].node under current dir(.) into packages under npm dir.
11
- e.g: index.linux-x64-gnu.node --> ./npm/linux-x64-gnu/index.node`,
12
- ],
13
- ],
14
- });
15
- static paths = [['artifacts']];
16
- async execute() {
17
- await collectArtifacts(this.getOptions());
18
- }
19
- }
@@ -1,34 +0,0 @@
1
- import { execSync } from 'child_process';
2
- import { Option } from 'clipanion';
3
- import { buildProject } from '../api/build.js';
4
- import { BaseBuildCommand } from '../def/build.js';
5
- import { debugFactory } from '../utils/index.js';
6
- const debug = debugFactory('build');
7
- export class BuildCommand extends BaseBuildCommand {
8
- pipe = Option.String('--pipe', {
9
- description: 'Pipe all outputs file to given command. e.g. `napi build --pipe "npx prettier --write"`',
10
- });
11
- cargoOptions = Option.Rest();
12
- async execute() {
13
- const { task } = await buildProject({
14
- ...this.getOptions(),
15
- cargoOptions: this.cargoOptions,
16
- });
17
- const outputs = await task;
18
- if (this.pipe) {
19
- for (const output of outputs) {
20
- debug('Piping output file to command: %s', this.pipe);
21
- try {
22
- execSync(`${this.pipe} ${output.path}`, {
23
- stdio: 'inherit',
24
- cwd: this.cwd,
25
- });
26
- }
27
- catch (e) {
28
- debug.error(`Failed to pipe output file ${output.path} to command`);
29
- debug.error(e);
30
- }
31
- }
32
- }
33
- }
34
- }
@@ -1,7 +0,0 @@
1
- import { createNpmDirs } from '../api/create-npm-dirs.js';
2
- import { BaseCreateNpmDirsCommand } from '../def/create-npm-dirs.js';
3
- export class CreateNpmDirsCommand extends BaseCreateNpmDirsCommand {
4
- async execute() {
5
- await createNpmDirs(this.getOptions());
6
- }
7
- }
@@ -1,12 +0,0 @@
1
- import { Command } from 'clipanion';
2
- /**
3
- * A command that prints the usage of all commands.
4
- *
5
- * Paths: `-h`, `--help`
6
- */
7
- export class HelpCommand extends Command {
8
- static paths = [[`-h`], [`--help`]];
9
- async execute() {
10
- await this.context.stdout.write(this.cli.usage());
11
- }
12
- }
@@ -1,112 +0,0 @@
1
- import path from 'path';
2
- import { Option } from 'clipanion';
3
- import inquirer from 'inquirer';
4
- import { newProject } from '../api/new.js';
5
- import { BaseNewCommand } from '../def/new.js';
6
- import { AVAILABLE_TARGETS, debugFactory, DEFAULT_TARGETS, } from '../utils/index.js';
7
- import { napiEngineRequirement } from '../utils/version.js';
8
- const debug = debugFactory('new');
9
- export class NewCommand extends BaseNewCommand {
10
- interactive = Option.Boolean('--interactive,-i', false, {
11
- description: 'Ask project basic information interactively without just using the default.',
12
- });
13
- async execute() {
14
- try {
15
- const options = await this.fetchOptions();
16
- await newProject(options);
17
- return 0;
18
- }
19
- catch (e) {
20
- debug('Failed to create new project');
21
- debug.error(e);
22
- return 1;
23
- }
24
- }
25
- async fetchOptions() {
26
- const cmdOptions = super.getOptions();
27
- if (this.interactive) {
28
- return {
29
- ...cmdOptions,
30
- name: await this.fetchName(path.parse(cmdOptions.path).base),
31
- minNodeApiVersion: await this.fetchNapiVersion(),
32
- targets: await this.fetchTargets(),
33
- license: await this.fetchLicense(),
34
- enableTypeDef: await this.fetchTypeDef(),
35
- enableGithubActions: await this.fetchGithubActions(),
36
- };
37
- }
38
- return cmdOptions;
39
- }
40
- async fetchName(defaultName) {
41
- return (this.$$name ??
42
- (await inquirer
43
- .prompt({
44
- type: 'input',
45
- name: 'name',
46
- message: 'Package name (the name field in your package.json file)',
47
- default: defaultName,
48
- })
49
- .then(({ name }) => name)));
50
- }
51
- async fetchLicense() {
52
- return inquirer
53
- .prompt({
54
- type: 'input',
55
- name: 'license',
56
- message: 'License for open-sourced project',
57
- default: this.license,
58
- })
59
- .then(({ license }) => license);
60
- }
61
- async fetchNapiVersion() {
62
- return inquirer
63
- .prompt({
64
- type: 'list',
65
- name: 'minNodeApiVersion',
66
- message: 'Minimum node-api version (with node version requirement)',
67
- loop: false,
68
- choices: new Array(8).fill(0).map((_, i) => ({
69
- name: `napi${i + 1} (${napiEngineRequirement(i + 1)})`,
70
- value: i + 1,
71
- })),
72
- // choice index
73
- default: this.minNodeApiVersion - 1,
74
- })
75
- .then(({ minNodeApiVersion }) => minNodeApiVersion);
76
- }
77
- async fetchTargets() {
78
- if (this.enableDefaultTargets) {
79
- return DEFAULT_TARGETS.concat();
80
- }
81
- if (this.enableAllTargets) {
82
- return AVAILABLE_TARGETS.concat();
83
- }
84
- const { targets } = await inquirer.prompt({
85
- name: 'targets',
86
- type: 'checkbox',
87
- loop: false,
88
- message: 'Choose target(s) your crate will be compiled to',
89
- default: DEFAULT_TARGETS,
90
- choices: AVAILABLE_TARGETS,
91
- });
92
- return targets;
93
- }
94
- async fetchTypeDef() {
95
- const { enableTypeDef } = await inquirer.prompt({
96
- name: 'enableTypeDef',
97
- type: 'confirm',
98
- message: 'Enable type definition auto-generation',
99
- default: this.enableTypeDef,
100
- });
101
- return enableTypeDef;
102
- }
103
- async fetchGithubActions() {
104
- const { enableGithubActions } = await inquirer.prompt({
105
- name: 'enableGithubActions',
106
- type: 'confirm',
107
- message: 'Enable Github Actions CI',
108
- default: this.enableGithubActions,
109
- });
110
- return enableGithubActions;
111
- }
112
- }
@@ -1,8 +0,0 @@
1
- import { prePublish } from '../api/pre-publish.js';
2
- import { BasePrePublishCommand } from '../def/pre-publish.js';
3
- export class PrePublishCommand extends BasePrePublishCommand {
4
- async execute() {
5
- // @ts-expect-error const 'npm' | 'lerna' to string
6
- await prePublish(this.getOptions());
7
- }
8
- }
@@ -1,7 +0,0 @@
1
- import { renameProject } from '../api/rename.js';
2
- import { BaseRenameCommand } from '../def/rename.js';
3
- export class RenameCommand extends BaseRenameCommand {
4
- async execute() {
5
- await renameProject(this.getOptions());
6
- }
7
- }
@@ -1,7 +0,0 @@
1
- import { universalizeBinaries } from '../api/universalize.js';
2
- import { BaseUniversalizeCommand } from '../def/universalize.js';
3
- export class UniversalizeCommand extends BaseUniversalizeCommand {
4
- async execute() {
5
- await universalizeBinaries(this.getOptions());
6
- }
7
- }
@@ -1,7 +0,0 @@
1
- import { version } from '../api/version.js';
2
- import { BaseVersionCommand } from '../def/version.js';
3
- export class VersionCommand extends BaseVersionCommand {
4
- async execute() {
5
- await version(this.getOptions());
6
- }
7
- }
@@ -1,38 +0,0 @@
1
- // This file is generated by codegen/index.ts
2
- // Do not edit this file manually
3
- import { Command, Option } from 'clipanion';
4
- export class BaseArtifactsCommand extends Command {
5
- static paths = [['artifacts']];
6
- static usage = Command.Usage({
7
- description: 'Copy artifacts from Github Actions into npm packages and ready to publish',
8
- });
9
- cwd = Option.String('--cwd', process.cwd(), {
10
- description: 'The working directory of where napi command will be executed in, all other paths options are relative to this path',
11
- });
12
- packageJsonPath = Option.String('--package-json-path', 'package.json', {
13
- description: 'Path to `package.json`',
14
- });
15
- outputDir = Option.String('--output-dir,-o', './', {
16
- description: 'Path to the folder where all built `.node` files put, same as `--output-dir` of build command',
17
- });
18
- npmDir = Option.String('--npm-dir', 'npm', {
19
- description: 'Path to the folder where the npm packages put',
20
- });
21
- getOptions() {
22
- return {
23
- cwd: this.cwd,
24
- packageJsonPath: this.packageJsonPath,
25
- outputDir: this.outputDir,
26
- npmDir: this.npmDir,
27
- };
28
- }
29
- }
30
- export function applyDefaultArtifactsOptions(options) {
31
- return {
32
- cwd: process.cwd(),
33
- packageJsonPath: 'package.json',
34
- outputDir: './',
35
- npmDir: 'npm',
36
- ...options,
37
- };
38
- }
package/dist/def/build.js DELETED
@@ -1,105 +0,0 @@
1
- // This file is generated by codegen/index.ts
2
- // Do not edit this file manually
3
- import { Command, Option } from 'clipanion';
4
- export class BaseBuildCommand extends Command {
5
- static paths = [['build']];
6
- static usage = Command.Usage({
7
- description: 'Build the napi-rs project',
8
- });
9
- target = Option.String('--target,-t', {
10
- description: 'Build for the target triple, bypassed to `cargo build --target`',
11
- });
12
- cwd = Option.String('--cwd', {
13
- description: 'The working directory of where napi command will be executed in, all other paths options are relative to this path',
14
- });
15
- manifestPath = Option.String('--manifest-path', {
16
- description: 'Path to `Cargo.toml`',
17
- });
18
- packageJsonPath = Option.String('--package-json-path', {
19
- description: 'Path to `package.json`',
20
- });
21
- targetDir = Option.String('--target-dir', {
22
- description: 'Directory for all crate generated artifacts, see `cargo build --target-dir`',
23
- });
24
- outputDir = Option.String('--output-dir,-o', {
25
- description: 'Path to where all the built files would be put. Default to the crate folder',
26
- });
27
- platform = Option.Boolean('--platform', {
28
- description: 'Add platform triple to the generated nodejs binding file, eg: `[name].linux-x64-gnu.node`',
29
- });
30
- jsPackageName = Option.String('--js-package-name', {
31
- description: 'Package name in generated js binding file. Only works with `--platform` flag',
32
- });
33
- jsBinding = Option.String('--js', {
34
- description: 'Path and filename of generated JS binding file. Only works with `--platform` flag. Relative to `--output_dir`.',
35
- });
36
- noJsBinding = Option.Boolean('--no-js', {
37
- description: 'Whether to disable the generation JS binding file. Only works with `--platform` flag.',
38
- });
39
- dts = Option.String('--dts', {
40
- description: 'Path and filename of generated type def file. Relative to `--output_dir`',
41
- });
42
- dtsHeader = Option.String('--dts-header', {
43
- description: 'Custom file header for generated type def file. Only works when `typedef` feature enabled.',
44
- });
45
- noDtsHeader = Option.Boolean('--no-dts-header', {
46
- description: 'Whether to disable the default file header for generated type def file. Only works when `typedef` feature enabled.',
47
- });
48
- strip = Option.Boolean('--strip,-s', {
49
- description: 'Whether strip the library to achieve the minimum file size',
50
- });
51
- release = Option.Boolean('--release,-r', {
52
- description: 'Build in release mode',
53
- });
54
- verbose = Option.Boolean('--verbose,-v', {
55
- description: 'Verbosely log build command trace',
56
- });
57
- bin = Option.String('--bin', {
58
- description: 'Build only the specified binary',
59
- });
60
- package = Option.String('--package,-p', {
61
- description: 'Build the specified library or the one at cwd',
62
- });
63
- crossCompile = Option.Boolean('--cross-compile,-x', {
64
- description: '[experimental] cross-compile for the specified target with `cargo-xwin` on windows and `cargo-zigbuild` on other platform',
65
- });
66
- watch = Option.Boolean('--watch,-w', {
67
- description: 'watch the crate changes and build continiously with `cargo-watch` crates',
68
- });
69
- features = Option.Array('--features,-F', {
70
- description: 'Space-separated list of features to activate',
71
- });
72
- allFeatures = Option.Boolean('--all-features', {
73
- description: 'Activate all available features',
74
- });
75
- noDefaultFeatures = Option.Boolean('--no-default-features', {
76
- description: 'Do not activate the `default` feature',
77
- });
78
- getOptions() {
79
- return {
80
- target: this.target,
81
- cwd: this.cwd,
82
- manifestPath: this.manifestPath,
83
- packageJsonPath: this.packageJsonPath,
84
- targetDir: this.targetDir,
85
- outputDir: this.outputDir,
86
- platform: this.platform,
87
- jsPackageName: this.jsPackageName,
88
- jsBinding: this.jsBinding,
89
- noJsBinding: this.noJsBinding,
90
- dts: this.dts,
91
- dtsHeader: this.dtsHeader,
92
- noDtsHeader: this.noDtsHeader,
93
- strip: this.strip,
94
- release: this.release,
95
- verbose: this.verbose,
96
- bin: this.bin,
97
- package: this.package,
98
- crossCompile: this.crossCompile,
99
- watch: this.watch,
100
- features: this.features,
101
- allFeatures: this.allFeatures,
102
- noDefaultFeatures: this.noDefaultFeatures,
103
- };
104
- }
105
- }
@@ -1,15 +0,0 @@
1
- import { Command } from 'clipanion';
2
- export declare abstract class BaseArtifactsCommand extends Command {
3
- static paths: string[][];
4
- static usage: import("clipanion").Usage;
5
- cwd: string;
6
- packageJsonPath: string;
7
- outputDir: string;
8
- npmDir: string;
9
- getOptions(): {
10
- cwd: string;
11
- packageJsonPath: string;
12
- outputDir: string;
13
- npmDir: string;
14
- };
15
- }
@@ -1,29 +0,0 @@
1
- // This file is generated by codegen/index.ts
2
- // Do not edit this file manually
3
- import { Command, Option } from 'clipanion';
4
- export class BaseArtifactsCommand extends Command {
5
- static paths = [['artifacts']];
6
- static usage = Command.Usage({
7
- description: 'Copy artifacts from Github Actions into npm packages and ready to publish',
8
- });
9
- cwd = Option.String('--cwd', process.cwd(), {
10
- description: 'The working directory of where napi command will be executed in, all other paths options are relative to this path',
11
- });
12
- packageJsonPath = Option.String('--package-json-path', 'package.json', {
13
- description: 'Path to `package.json`',
14
- });
15
- outputDir = Option.String('--output-dir,-o', './', {
16
- description: 'Path to the folder where all built `.node` files put, same as `--output-dir` of build command',
17
- });
18
- npmDir = Option.String('--npm-dir', 'npm', {
19
- description: 'Path to the folder where the npm packages put',
20
- });
21
- getOptions() {
22
- return {
23
- cwd: this.cwd,
24
- packageJsonPath: this.packageJsonPath,
25
- outputDir: this.outputDir,
26
- npmDir: this.npmDir,
27
- };
28
- }
29
- }