@jspreadsheet/install 1.0.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.
Files changed (2) hide show
  1. package/index.js +322 -0
  2. package/package.json +21 -0
package/index.js ADDED
@@ -0,0 +1,322 @@
1
+ #!/usr/bin/env node
2
+
3
+ const prompts = require('prompts');
4
+ const { execSync } = require('child_process');
5
+ const https = require('https');
6
+
7
+ const PACKAGES = {
8
+ pro: {
9
+ vanilla: 'jspreadsheet',
10
+ react: '@jspreadsheet/react',
11
+ vue: '@jspreadsheet/vue',
12
+ angular: 'jspreadsheet',
13
+ },
14
+ ce: {
15
+ vanilla: 'jspreadsheet-ce',
16
+ react: '@jspreadsheet-ce/react',
17
+ vue: '@jspreadsheet-ce/vue',
18
+ angular: 'jspreadsheet-ce',
19
+ },
20
+ };
21
+
22
+ /**
23
+ * Detect the package manager used in the current project
24
+ * @returns {string}
25
+ */
26
+ function detectPackageManager() {
27
+ const fs = require('fs');
28
+ const path = require('path');
29
+ const cwd = process.cwd();
30
+
31
+ if (fs.existsSync(path.join(cwd, 'yarn.lock'))) {
32
+ return 'yarn';
33
+ }
34
+ if (fs.existsSync(path.join(cwd, 'pnpm-lock.yaml'))) {
35
+ return 'pnpm';
36
+ }
37
+ if (fs.existsSync(path.join(cwd, 'bun.lockb'))) {
38
+ return 'bun';
39
+ }
40
+ return 'npm';
41
+ }
42
+
43
+ /**
44
+ * Build the install command for a given package
45
+ * @param {string} pkg
46
+ * @returns {string}
47
+ */
48
+ function getInstallCommand(pkg) {
49
+ const pm = detectPackageManager();
50
+ if (pm === 'yarn') {
51
+ return `yarn add ${pkg}`;
52
+ }
53
+ if (pm === 'pnpm') {
54
+ return `pnpm add ${pkg}`;
55
+ }
56
+ if (pm === 'bun') {
57
+ return `bun add ${pkg}`;
58
+ }
59
+ return `npm install ${pkg}`;
60
+ }
61
+
62
+ /**
63
+ * Register email and get a trial license
64
+ * @param {string} email
65
+ * @returns {Promise<string|null>}
66
+ */
67
+ function registerEmail(email) {
68
+ return new Promise((resolve) => {
69
+ const data = JSON.stringify({ email });
70
+
71
+ const options = {
72
+ hostname: 'jspreadsheet.com',
73
+ port: 443,
74
+ path: '/me/register',
75
+ method: 'POST',
76
+ headers: {
77
+ 'Content-Type': 'application/json',
78
+ 'Content-Length': Buffer.byteLength(data),
79
+ },
80
+ };
81
+
82
+ const req = https.request(options, (res) => {
83
+ let body = '';
84
+ res.on('data', (chunk) => body += chunk);
85
+ res.on('end', () => {
86
+ try {
87
+ const result = JSON.parse(body);
88
+ resolve(result.license || null);
89
+ } catch (e) {
90
+ resolve(null);
91
+ }
92
+ });
93
+ });
94
+
95
+ req.on('error', () => resolve(null));
96
+ req.write(data);
97
+ req.end();
98
+ });
99
+ }
100
+
101
+ async function main() {
102
+ console.log('');
103
+ console.log('');
104
+ console.log(' Welcome to Jspreadsheet');
105
+ console.log('');
106
+ console.log(' The JavaScript data grid component for building');
107
+ console.log(' enterprise-grade spreadsheet applications.');
108
+ console.log('');
109
+ console.log('');
110
+
111
+ // Step 1: Choose distribution
112
+ const { distribution } = await prompts({
113
+ type: 'select',
114
+ name: 'distribution',
115
+ message: 'Choose a distribution',
116
+ choices: [
117
+ {
118
+ title: 'Jspreadsheet Pro',
119
+ description: 'High-performance data grids with advanced Excel and Google Sheets compatibility. Ideal for enterprise and data-intensive applications.',
120
+ value: 'pro',
121
+ },
122
+ {
123
+ title: 'Jspreadsheet CE (Community Edition)',
124
+ description: 'Lightweight and open source. Great for prototypes, MVPs, and community-driven projects.',
125
+ value: 'ce',
126
+ },
127
+ ],
128
+ });
129
+
130
+ if (!distribution) {
131
+ console.log('\nSetup cancelled.');
132
+ process.exit(0);
133
+ }
134
+
135
+ console.log('');
136
+
137
+ // Step 2: Choose framework
138
+ const { framework } = await prompts({
139
+ type: 'select',
140
+ name: 'framework',
141
+ message: 'Select your framework',
142
+ choices: [
143
+ { title: 'React', value: 'react' },
144
+ { title: 'Vue', value: 'vue' },
145
+ { title: 'Angular', value: 'angular' },
146
+ { title: 'Vanilla JavaScript', value: 'vanilla' },
147
+ { title: 'Other', value: 'vanilla' },
148
+ ],
149
+ });
150
+
151
+ if (!framework) {
152
+ console.log('\nSetup cancelled.');
153
+ process.exit(0);
154
+ }
155
+
156
+ const pkg = PACKAGES[distribution][framework];
157
+
158
+ // Step 3: Pro-specific registration flow
159
+ let license = null;
160
+
161
+ if (distribution === 'pro') {
162
+ console.log('');
163
+ const { support } = await prompts({
164
+ type: 'select',
165
+ name: 'support',
166
+ message: 'Get free dedicated technical support for 30 days?',
167
+ choices: [
168
+ {
169
+ title: 'Yes, register with my email',
170
+ description: 'Receive a license key and priority support from the Jspreadsheet team.',
171
+ value: 'register',
172
+ },
173
+ {
174
+ title: 'No thanks, start evaluation without registration',
175
+ description: 'You can register anytime later.',
176
+ value: 'skip',
177
+ },
178
+ ],
179
+ });
180
+
181
+ if (!support) {
182
+ console.log('\nSetup cancelled.');
183
+ process.exit(0);
184
+ }
185
+
186
+ if (support === 'register') {
187
+ const { email } = await prompts({
188
+ type: 'text',
189
+ name: 'email',
190
+ message: 'Your email',
191
+ validate: (value) => {
192
+ if (!value) {
193
+ return 'Email is required';
194
+ }
195
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
196
+ return 'Please enter a valid email address';
197
+ }
198
+ return true;
199
+ },
200
+ });
201
+
202
+ if (!email) {
203
+ console.log('\nSetup cancelled.');
204
+ process.exit(0);
205
+ }
206
+
207
+ console.log('\n Registering...');
208
+ license = await registerEmail(email);
209
+
210
+ if (license) {
211
+ console.log(' Done! Your license key has been generated.\n');
212
+ } else {
213
+ console.log(' Could not register at this time. You can register later at:');
214
+ console.log(' https://jspreadsheet.com/me\n');
215
+ console.log(' Continuing with evaluation mode.\n');
216
+ }
217
+ }
218
+ }
219
+
220
+ // Step 4: Install the package
221
+ const cmd = getInstallCommand(pkg);
222
+ console.log('');
223
+ console.log(` Installing ${pkg}...`);
224
+ console.log(` > ${cmd}`);
225
+ console.log('');
226
+
227
+ try {
228
+ execSync(cmd, { stdio: 'inherit' });
229
+ } catch (e) {
230
+ console.error(`\n Installation failed. Try running manually:`);
231
+ console.error(` ${cmd}\n`);
232
+ process.exit(1);
233
+ }
234
+
235
+ // Step 5: Show post-install instructions
236
+ console.log('');
237
+ console.log('');
238
+ console.log(' -----------------------------------------------');
239
+ console.log(' All set! Jspreadsheet has been installed.');
240
+ console.log(' -----------------------------------------------');
241
+ console.log('');
242
+ console.log('');
243
+
244
+ const isPro = distribution === 'pro';
245
+ const mainPkg = isPro ? 'jspreadsheet' : 'jspreadsheet-ce';
246
+
247
+ if (isPro) {
248
+ if (license) {
249
+ console.log(' Activate your license:');
250
+ console.log('');
251
+ console.log(` jspreadsheet.setLicense('${license}');`);
252
+ } else {
253
+ console.log(' Start in evaluation mode:');
254
+ console.log('');
255
+ console.log(" jspreadsheet.setLicense('evaluation');");
256
+ }
257
+ console.log('');
258
+ console.log('');
259
+ if (!license) {
260
+ console.log(' Want a license key? Register at:');
261
+ console.log(' https://jspreadsheet.com/me');
262
+ console.log('');
263
+ console.log('');
264
+ }
265
+ console.log(' Need a commercial license?');
266
+ console.log(' https://jspreadsheet.com/pricing');
267
+ } else {
268
+ console.log(' Jspreadsheet CE is ready to use.');
269
+ }
270
+
271
+ console.log('');
272
+ console.log('');
273
+
274
+ // Show framework-specific quick start
275
+ console.log(' Getting started:');
276
+ console.log('');
277
+
278
+ if (framework === 'react') {
279
+ const wrapper = isPro ? '@jspreadsheet/react' : '@jspreadsheet-ce/react';
280
+ console.log(` import { Spreadsheet, Worksheet } from '${wrapper}';`);
281
+ if (isPro) {
282
+ console.log(` import jspreadsheet from '${mainPkg}';`);
283
+ console.log('');
284
+ console.log(` jspreadsheet.setLicense('${license || 'evaluation'}');`);
285
+ }
286
+ } else if (framework === 'vue') {
287
+ const wrapper = isPro ? '@jspreadsheet/vue' : '@jspreadsheet-ce/vue';
288
+ console.log(` import { Spreadsheet, Worksheet } from '${wrapper}';`);
289
+ if (isPro) {
290
+ console.log(` import jspreadsheet from '${mainPkg}';`);
291
+ console.log('');
292
+ console.log(` jspreadsheet.setLicense('${license || 'evaluation'}');`);
293
+ }
294
+ } else {
295
+ console.log(` import jspreadsheet from '${mainPkg}';`);
296
+ if (isPro) {
297
+ console.log('');
298
+ console.log(` jspreadsheet.setLicense('${license || 'evaluation'}');`);
299
+ }
300
+ }
301
+
302
+ console.log('');
303
+ console.log('');
304
+
305
+ if (isPro) {
306
+ console.log(' Docs: https://jspreadsheet.com/docs');
307
+ } else {
308
+ console.log(' Docs: https://bossanova.uk/jspreadsheet/docs');
309
+ console.log('');
310
+ console.log('');
311
+ console.log(' Need file import/export, advanced formulas, or more features?');
312
+ console.log(' Try Jspreadsheet Pro: https://jspreadsheet.com');
313
+ }
314
+
315
+ console.log('');
316
+ console.log('');
317
+ }
318
+
319
+ main().catch((err) => {
320
+ console.error(err);
321
+ process.exit(1);
322
+ });
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@jspreadsheet/install",
3
+ "version": "1.0.0",
4
+ "description": "Interactive installer for Jspreadsheet",
5
+ "bin": {
6
+ "@jspreadsheet/install": "index.js",
7
+ "jspreadsheet-install": "index.js"
8
+ },
9
+ "main": "index.js",
10
+ "keywords": [
11
+ "jspreadsheet",
12
+ "spreadsheet",
13
+ "installer",
14
+ "cli"
15
+ ],
16
+ "author": "Jspreadsheet",
17
+ "license": "MIT",
18
+ "dependencies": {
19
+ "prompts": "^2.4.2"
20
+ }
21
+ }