extension-create 2.0.0-rc.25 → 2.0.0-rc.26
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/dist/module.d.ts +2 -4
- package/dist/module.js +593 -33
- package/dist/template/package.json +1 -0
- package/package.json +22 -14
package/dist/module.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
interface CreateOptions {
|
|
1
|
+
export interface CreateOptions {
|
|
2
2
|
template: string;
|
|
3
3
|
install?: boolean;
|
|
4
4
|
cliVersion?: string;
|
|
5
5
|
}
|
|
6
|
-
declare function extensionCreate(projectNameInput: string | undefined, { cliVersion, template, install }: CreateOptions): Promise<void>;
|
|
7
|
-
|
|
8
|
-
export { type CreateOptions, extensionCreate };
|
|
6
|
+
export declare function extensionCreate(projectNameInput: string | undefined, { cliVersion, template, install }: CreateOptions): Promise<void>;
|
package/dist/module.js
CHANGED
|
@@ -1,39 +1,599 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
|
|
3
|
+
return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
4
|
+
}();
|
|
5
|
+
var __webpack_require__ = {};
|
|
6
|
+
(()=>{
|
|
7
|
+
__webpack_require__.n = (module)=>{
|
|
8
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
9
|
+
__webpack_require__.d(getter, {
|
|
10
|
+
a: getter
|
|
11
|
+
});
|
|
12
|
+
return getter;
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
17
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: definition[key]
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
25
|
+
})();
|
|
26
|
+
(()=>{
|
|
27
|
+
__webpack_require__.r = (exports1)=>{
|
|
28
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
29
|
+
value: 'Module'
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
32
|
+
value: true
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
var __webpack_exports__ = {};
|
|
37
|
+
__webpack_require__.r(__webpack_exports__);
|
|
38
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
39
|
+
extensionCreate: ()=>extensionCreate
|
|
40
|
+
});
|
|
41
|
+
const external_path_namespaceObject = require("path");
|
|
42
|
+
const external_fs_namespaceObject = require("fs");
|
|
43
|
+
const external_chalk_namespaceObject = require("chalk");
|
|
44
|
+
var external_chalk_default = /*#__PURE__*/ __webpack_require__.n(external_chalk_namespaceObject);
|
|
45
|
+
const external_package_manager_detector_namespaceObject = require("package-manager-detector");
|
|
46
|
+
function destinationNotWriteable(workingDir) {
|
|
47
|
+
const workingDirFolder = external_path_namespaceObject.basename(workingDir);
|
|
48
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Failed to write in the destination directory\n\nPath is not writable. Ensure you have write permissions for this folder.\n${external_chalk_default().red('NOT WRITEABLE')}: ${external_chalk_default().underline(workingDirFolder)}`;
|
|
49
|
+
}
|
|
50
|
+
async function directoryHasConflicts(projectPath, conflictingFiles) {
|
|
51
|
+
const projectName = external_path_namespaceObject.basename(projectPath);
|
|
52
|
+
let message = `\nConflict! Path to ${external_chalk_default().cyan(projectName)} includes conflicting files:\n\n`;
|
|
53
|
+
for (const file of conflictingFiles){
|
|
54
|
+
const stats = await external_fs_namespaceObject.promises.lstat(external_path_namespaceObject.join(projectPath, file));
|
|
55
|
+
message += stats.isDirectory() ? `${external_chalk_default().gray('-')} ${external_chalk_default().yellow(file)}\n` : `${external_chalk_default().gray('-')} ${external_chalk_default().yellow(file)}\n`;
|
|
56
|
+
}
|
|
57
|
+
message += `\nYou need to either rename/remove the files listed above, or choose a new directory name for your extension.\n\nPath to conflicting directory: ${external_chalk_default().underline(projectPath)}`;
|
|
58
|
+
return message;
|
|
59
|
+
}
|
|
60
|
+
function noProjectName() {
|
|
61
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} You need to provide an extension name to create one. See ${external_chalk_default().yellow('--help')} for command info.`;
|
|
62
|
+
}
|
|
63
|
+
function noUrlAllowed() {
|
|
64
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} URLs are not allowed as a project path. Either write a name or a path to a local folder.`;
|
|
65
|
+
}
|
|
66
|
+
async function successfullInstall(projectPath, projectName) {
|
|
67
|
+
const relativePath = external_path_namespaceObject.relative(process.cwd(), projectPath);
|
|
68
|
+
const pm = await (0, external_package_manager_detector_namespaceObject.detect)();
|
|
69
|
+
let command = 'npm run';
|
|
70
|
+
switch(null == pm ? void 0 : pm.name){
|
|
71
|
+
case 'yarn':
|
|
72
|
+
command = 'yarn dev';
|
|
73
|
+
break;
|
|
74
|
+
case 'pnpm':
|
|
75
|
+
command = 'pnpm dev';
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
command = 'npm run dev';
|
|
79
|
+
}
|
|
80
|
+
if (process.env.npm_config_user_agent) {
|
|
81
|
+
if (process.env.npm_config_user_agent.includes('pnpm')) command = 'pnpm dev';
|
|
82
|
+
}
|
|
83
|
+
return `\u{1F9E9} - ${external_chalk_default().green('Success!')} Extension ${external_chalk_default().cyan(projectName)} created.\n\nNow ${external_chalk_default().magenta(`cd ${external_chalk_default().underline(relativePath)}`)} and ${external_chalk_default().magenta(`${command}`)} to open a new browser instance\nwith your extension installed, loaded, and enabled for development.\n\n${external_chalk_default().green('You are ready')}. Time to hack on your extension!`;
|
|
84
|
+
}
|
|
85
|
+
function startingNewExtension(projectName) {
|
|
86
|
+
return `\u{1F423} - Starting a new browser extension named ${external_chalk_default().cyan(projectName)}...`;
|
|
87
|
+
}
|
|
88
|
+
function checkingIfPathIsWriteable() {
|
|
89
|
+
return `\u{1F91E} - Checking if destination path is writeable...`;
|
|
90
|
+
}
|
|
91
|
+
function scanningPossiblyConflictingFiles() {
|
|
92
|
+
return "\uD83D\uDD0E - Scanning for potential conflicting files...";
|
|
93
|
+
}
|
|
94
|
+
function createDirectoryError(projectName, error) {
|
|
95
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't create directory ${external_chalk_default().cyan(projectName)}:\n${external_chalk_default().red(error)}`;
|
|
96
|
+
}
|
|
97
|
+
function writingTypeDefinitions(projectName) {
|
|
98
|
+
return `\u{1F537} - Writing type definitions for ${external_chalk_default().cyan(projectName)}...`;
|
|
99
|
+
}
|
|
100
|
+
function writingTypeDefinitionsError(error) {
|
|
101
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Failed to write the extension type definition.\n${external_chalk_default().red(error)}`;
|
|
102
|
+
}
|
|
103
|
+
function installingFromTemplate(projectName, templateName) {
|
|
104
|
+
if ('init' === templateName) return `\u{1F9F0} - Installing ${external_chalk_default().cyan(projectName)}...`;
|
|
105
|
+
return `\u{1F9F0} - Installing ${external_chalk_default().cyan(projectName)} from template ${external_chalk_default().magenta(templateName)}...`;
|
|
106
|
+
}
|
|
107
|
+
function installingFromTemplateError(projectName, template, error) {
|
|
108
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't find template ${external_chalk_default().magenta(template)} for ${external_chalk_default().cyan(projectName)}:\n${external_chalk_default().red(error)}`;
|
|
109
|
+
}
|
|
110
|
+
function initializingGitForRepository(projectName) {
|
|
111
|
+
return `\u{1F332} - Initializing git repository for ${external_chalk_default().cyan(projectName)}...`;
|
|
112
|
+
}
|
|
113
|
+
function initializingGitForRepositoryFailed(gitCommand, gitArgs, code) {
|
|
114
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Command ${external_chalk_default().yellow(gitCommand)} ${external_chalk_default().yellow(gitArgs.join(' '))} failed with exit code ${code}`;
|
|
115
|
+
}
|
|
116
|
+
function initializingGitForRepositoryProcessError(projectName, error) {
|
|
117
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Child process error: Can't initialize ${external_chalk_default().yellow('git')} for ${external_chalk_default().cyan(projectName)}:\n${external_chalk_default().red(error.message)}`;
|
|
118
|
+
}
|
|
119
|
+
function initializingGitForRepositoryError(projectName, error) {
|
|
120
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't initialize ${external_chalk_default().yellow('git')} for ${external_chalk_default().cyan(projectName)}:\n${external_chalk_default().red(error.message || error.toString())}`;
|
|
121
|
+
}
|
|
122
|
+
function installingDependencies() {
|
|
123
|
+
return "\uD83D\uDEE0 - Installing dependencies... (takes a moment)";
|
|
124
|
+
}
|
|
125
|
+
function installingDependenciesFailed(gitCommand, gitArgs, code) {
|
|
126
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Command ${gitCommand} ${gitArgs.join(' ')} failed with exit code ${code}`;
|
|
127
|
+
}
|
|
128
|
+
function installingDependenciesProcessError(projectName, error) {
|
|
129
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Child process error: Can't install dependencies for ${external_chalk_default().cyan(projectName)}:\n${external_chalk_default().red(error)}`;
|
|
130
|
+
}
|
|
131
|
+
function cantInstallDependencies(projectName, error) {
|
|
132
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't install dependencies for ${external_chalk_default().cyan(projectName)}:\n${external_chalk_default().red(error.message || error.toString())}`;
|
|
133
|
+
}
|
|
134
|
+
function writingPackageJsonMetadata() {
|
|
135
|
+
return `\u{1F4DD} - Writing ${external_chalk_default().yellow('package.json')} metadata...`;
|
|
136
|
+
}
|
|
137
|
+
function writingPackageJsonMetadataError(projectName, error) {
|
|
138
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't write ${external_chalk_default().yellow('package.json')} for ${external_chalk_default().cyan(projectName)}:\n${external_chalk_default().red(error)}`;
|
|
139
|
+
}
|
|
140
|
+
function writingManifestJsonMetadata() {
|
|
141
|
+
return `\u{1F4DC} - Writing ${external_chalk_default().yellow('manifest.json')} metadata...`;
|
|
142
|
+
}
|
|
143
|
+
function writingManifestJsonMetadataError(projectName, error) {
|
|
144
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't write ${external_chalk_default().yellow('manifest.json')} for ${external_chalk_default().cyan(projectName)}:\n${external_chalk_default().red(error)}`;
|
|
145
|
+
}
|
|
146
|
+
function writingReadmeMetaData() {
|
|
147
|
+
return `\u{1F4C4} - Writing ${external_chalk_default().yellow('README.md')} metadata...`;
|
|
148
|
+
}
|
|
149
|
+
function writingGitIgnore() {
|
|
150
|
+
return `\u{1F648} - Writing ${external_chalk_default().yellow('.gitignore')} lines...`;
|
|
151
|
+
}
|
|
152
|
+
function writingReadmeMetaDataEError(projectName, error) {
|
|
153
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't write the ${external_chalk_default().yellow('README.md')} file for ${external_chalk_default().cyan(projectName)}:\n${external_chalk_default().red(error)}`;
|
|
154
|
+
}
|
|
155
|
+
function folderExists(projectName) {
|
|
156
|
+
return `\u{1F91D} - Ensuring ${external_chalk_default().cyan(projectName)} folder exists...`;
|
|
157
|
+
}
|
|
158
|
+
function writingDirectoryError(error) {
|
|
159
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Error while checking directory writability:\n` + external_chalk_default().red(error);
|
|
160
|
+
}
|
|
161
|
+
function cantSetupBuiltInTests(projectName, error) {
|
|
162
|
+
return `${external_chalk_default().red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't setup built-in tests for ${external_chalk_default().cyan(projectName)}:\n${external_chalk_default().red(error)}`;
|
|
163
|
+
}
|
|
164
|
+
const promises_namespaceObject = require("fs/promises");
|
|
165
|
+
const external_url_namespaceObject = require("url");
|
|
166
|
+
const utils_filename = (0, external_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__);
|
|
167
|
+
const utils_dirname = external_path_namespaceObject.dirname(utils_filename);
|
|
168
|
+
async function copyDirectoryWithSymlinks(source, destination) {
|
|
169
|
+
const entries = await promises_namespaceObject.readdir(source, {
|
|
170
|
+
withFileTypes: true
|
|
171
|
+
});
|
|
172
|
+
await promises_namespaceObject.mkdir(destination, {
|
|
173
|
+
recursive: true
|
|
174
|
+
});
|
|
175
|
+
for (const entry of entries){
|
|
176
|
+
const sourcePath = external_path_namespaceObject.join(source, entry.name);
|
|
177
|
+
const destPath = external_path_namespaceObject.join(destination, entry.name);
|
|
178
|
+
if (entry.isDirectory()) await copyDirectoryWithSymlinks(sourcePath, destPath);
|
|
179
|
+
else if (entry.isSymbolicLink()) {
|
|
180
|
+
const target = await promises_namespaceObject.readlink(sourcePath);
|
|
181
|
+
await promises_namespaceObject.symlink(target, destPath);
|
|
182
|
+
} else await promises_namespaceObject.copyFile(sourcePath, destPath);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async function moveDirectoryContents(source, destination) {
|
|
186
|
+
await promises_namespaceObject.mkdir(destination, {
|
|
187
|
+
recursive: true
|
|
188
|
+
});
|
|
189
|
+
const entries = await promises_namespaceObject.readdir(source, {
|
|
190
|
+
withFileTypes: true
|
|
191
|
+
});
|
|
192
|
+
for (const entry of entries){
|
|
193
|
+
const sourcePath = external_path_namespaceObject.join(source, entry.name);
|
|
194
|
+
const destPath = external_path_namespaceObject.join(destination, entry.name);
|
|
195
|
+
if (entry.isDirectory()) await moveDirectoryContents(sourcePath, destPath);
|
|
196
|
+
else if (entry.isSymbolicLink()) {
|
|
197
|
+
const target = await promises_namespaceObject.readlink(sourcePath);
|
|
198
|
+
await promises_namespaceObject.symlink(target, destPath);
|
|
199
|
+
} else await promises_namespaceObject.rename(sourcePath, destPath);
|
|
200
|
+
}
|
|
201
|
+
await promises_namespaceObject.rm(source, {
|
|
202
|
+
recursive: true,
|
|
203
|
+
force: true
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
async function getInstallCommand() {
|
|
207
|
+
const pm = await (0, external_package_manager_detector_namespaceObject.detect)();
|
|
208
|
+
let command = 'npm';
|
|
209
|
+
if (process.env.npm_config_user_agent) {
|
|
210
|
+
if (process.env.npm_config_user_agent.includes('pnpm')) return 'pnpm';
|
|
211
|
+
}
|
|
212
|
+
switch(null == pm ? void 0 : pm.name){
|
|
213
|
+
case 'yarn':
|
|
214
|
+
command = 'yarn';
|
|
215
|
+
break;
|
|
216
|
+
case 'pnpm':
|
|
217
|
+
command = 'pnpm';
|
|
218
|
+
break;
|
|
219
|
+
default:
|
|
220
|
+
command = 'npm';
|
|
221
|
+
}
|
|
222
|
+
return command;
|
|
223
|
+
}
|
|
224
|
+
function getTemplatePath(workingDir) {
|
|
225
|
+
const templatesDir = external_path_namespaceObject.resolve(utils_dirname, '..', 'template');
|
|
226
|
+
return external_path_namespaceObject.resolve(workingDir, templatesDir);
|
|
227
|
+
}
|
|
228
|
+
async function isDirectoryWriteable(directory, projectName) {
|
|
229
|
+
try {
|
|
230
|
+
console.log(folderExists(projectName));
|
|
231
|
+
await promises_namespaceObject.mkdir(directory, {
|
|
232
|
+
recursive: true
|
|
233
|
+
});
|
|
234
|
+
return true;
|
|
235
|
+
} catch (err) {
|
|
236
|
+
console.log(writingDirectoryError(err));
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function isExternalTemplate(templateName) {
|
|
241
|
+
return 'init' !== templateName;
|
|
242
|
+
}
|
|
243
|
+
function isTypeScriptTemplate(templateName) {
|
|
244
|
+
return templateName.includes("typescript") || templateName.includes('react') || templateName.includes('preact') || templateName.includes('svelte') || templateName.includes('solid');
|
|
245
|
+
}
|
|
246
|
+
const allowlist = [
|
|
247
|
+
'LICENSE',
|
|
248
|
+
'node_modules'
|
|
249
|
+
];
|
|
250
|
+
async function createDirectory(projectPath, projectName) {
|
|
251
|
+
console.log(startingNewExtension(projectName));
|
|
252
|
+
try {
|
|
253
|
+
const isCurrentDirWriteable = await isDirectoryWriteable(projectPath, projectName);
|
|
254
|
+
console.log(checkingIfPathIsWriteable());
|
|
255
|
+
if (!isCurrentDirWriteable) {
|
|
256
|
+
console.error(destinationNotWriteable(projectPath));
|
|
257
|
+
process.exit(1);
|
|
258
|
+
}
|
|
259
|
+
const currentDir = await promises_namespaceObject.readdir(projectPath);
|
|
260
|
+
console.log(scanningPossiblyConflictingFiles());
|
|
261
|
+
const conflictingFiles = await Promise.all(currentDir.filter((file)=>!file.startsWith('.')).filter((file)=>!file.endsWith('.log')).filter((file)=>!allowlist.includes(file)).map(async (file)=>{
|
|
262
|
+
const stats = await promises_namespaceObject.lstat(external_path_namespaceObject.join(projectPath, file));
|
|
263
|
+
return stats.isDirectory() ? `${file}/` : `${file}`;
|
|
264
|
+
}));
|
|
265
|
+
if (conflictingFiles.length > 0) {
|
|
266
|
+
const conflictMessage = await directoryHasConflicts(projectPath, conflictingFiles);
|
|
267
|
+
throw new Error(conflictMessage);
|
|
268
|
+
}
|
|
269
|
+
} catch (error) {
|
|
270
|
+
console.error(createDirectoryError(projectName, error));
|
|
271
|
+
process.exit(1);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const import_local_template_filename = (0, external_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__);
|
|
275
|
+
const import_local_template_dirname = external_path_namespaceObject.dirname(import_local_template_filename);
|
|
276
|
+
async function importLocalTemplate(projectPath, projectName, template) {
|
|
277
|
+
const localTemplatePath = external_path_namespaceObject.resolve(import_local_template_dirname, 'template');
|
|
278
|
+
try {
|
|
279
|
+
console.log(installingFromTemplate(projectName, template));
|
|
280
|
+
await copyDirectoryWithSymlinks(localTemplatePath, projectPath);
|
|
281
|
+
} catch (error) {
|
|
282
|
+
console.error(installingFromTemplateError(projectName, template, error));
|
|
283
|
+
process.exit(1);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const external_go_git_it_namespaceObject = require("go-git-it");
|
|
287
|
+
var external_go_git_it_default = /*#__PURE__*/ __webpack_require__.n(external_go_git_it_namespaceObject);
|
|
288
|
+
const import_external_template_filename = (0, external_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__);
|
|
289
|
+
const import_external_template_dirname = external_path_namespaceObject.dirname(import_external_template_filename);
|
|
290
|
+
async function importExternalTemplate(projectPath, projectName, template) {
|
|
291
|
+
const installationPath = external_path_namespaceObject.dirname(projectPath);
|
|
292
|
+
const templateName = external_path_namespaceObject.basename(template);
|
|
293
|
+
const examplesUrl = 'https://github.com/extension-js/extension.js/tree/main/examples';
|
|
294
|
+
const templateUrl = `${examplesUrl}/${template}`;
|
|
295
|
+
try {
|
|
296
|
+
await promises_namespaceObject.mkdir(projectPath, {
|
|
297
|
+
recursive: true
|
|
298
|
+
});
|
|
299
|
+
if ('development' === process.env.EXTENSION_ENV) {
|
|
300
|
+
console.log(installingFromTemplate(projectName, template));
|
|
301
|
+
const localTemplatePath = external_path_namespaceObject.join(import_external_template_dirname, '..', '..', '..', 'examples', templateName);
|
|
302
|
+
await copyDirectoryWithSymlinks(localTemplatePath, projectPath);
|
|
303
|
+
} else {
|
|
304
|
+
const tempPath = external_path_namespaceObject.join(installationPath, projectName + '-temp');
|
|
305
|
+
await promises_namespaceObject.mkdir(tempPath, {
|
|
306
|
+
recursive: true
|
|
307
|
+
});
|
|
308
|
+
await external_go_git_it_default()(templateUrl, tempPath, installingFromTemplate(projectName, templateName));
|
|
309
|
+
const srcPath = external_path_namespaceObject.join(tempPath, templateName);
|
|
310
|
+
await moveDirectoryContents(srcPath, projectPath);
|
|
311
|
+
await promises_namespaceObject.rm(tempPath, {
|
|
312
|
+
recursive: true,
|
|
313
|
+
force: true
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
} catch (error) {
|
|
317
|
+
console.error(installingFromTemplateError(projectName, templateName, error));
|
|
318
|
+
process.exit(1);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
const extensionJsPackageJsonScripts = {
|
|
322
|
+
dev: 'development' === process.env.EXTENSION_ENV ? 'node node_modules/extension dev' : 'extension dev',
|
|
323
|
+
start: 'development' === process.env.EXTENSION_ENV ? 'node node_modules/extension start' : 'extension start',
|
|
324
|
+
build: 'development' === process.env.EXTENSION_ENV ? 'node node_modules/extension build' : 'extension build'
|
|
325
|
+
};
|
|
326
|
+
async function overridePackageJson(projectPath, projectName, { template, cliVersion }) {
|
|
327
|
+
const templatePath = getTemplatePath(process.cwd());
|
|
328
|
+
const packageJsonPath = isExternalTemplate(template) ? external_path_namespaceObject.join(projectPath, 'package.json') : external_path_namespaceObject.join(templatePath, 'package.json');
|
|
329
|
+
const packageJsonContent = await promises_namespaceObject.readFile(packageJsonPath);
|
|
330
|
+
const packageJson = JSON.parse(packageJsonContent.toString());
|
|
331
|
+
packageJson.scripts = packageJson.scripts || {};
|
|
332
|
+
packageJson.dependencies = packageJson.dependencies || {};
|
|
333
|
+
packageJson.devDependencies = {
|
|
334
|
+
...packageJson.devDependencies || {},
|
|
335
|
+
extension: 'development' === process.env.EXTENSION_ENV ? '*' : `^${cliVersion}`
|
|
336
|
+
};
|
|
337
|
+
const packageMetadata = {
|
|
338
|
+
...packageJson,
|
|
339
|
+
name: external_path_namespaceObject.basename(projectPath),
|
|
340
|
+
private: true,
|
|
341
|
+
scripts: {
|
|
342
|
+
...packageJson.scripts,
|
|
343
|
+
...extensionJsPackageJsonScripts
|
|
344
|
+
},
|
|
345
|
+
dependencies: packageJson.dependencies,
|
|
346
|
+
devDependencies: packageJson.devDependencies,
|
|
347
|
+
author: {
|
|
348
|
+
name: 'Your Name',
|
|
349
|
+
email: 'your@email.com',
|
|
350
|
+
url: 'https://yourwebsite.com'
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
try {
|
|
354
|
+
console.log(writingPackageJsonMetadata());
|
|
355
|
+
await promises_namespaceObject.writeFile(external_path_namespaceObject.join(projectPath, 'package.json'), JSON.stringify(packageMetadata, null, 2));
|
|
356
|
+
} catch (error) {
|
|
357
|
+
console.error(writingPackageJsonMetadataError(projectName, error));
|
|
358
|
+
process.exit(1);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
const external_cross_spawn_namespaceObject = require("cross-spawn");
|
|
362
|
+
function getInstallArgs() {
|
|
363
|
+
return [
|
|
364
|
+
'install',
|
|
365
|
+
'--silent'
|
|
366
|
+
];
|
|
367
|
+
}
|
|
368
|
+
async function installDependencies(projectPath, projectName) {
|
|
369
|
+
const nodeModulesPath = external_path_namespaceObject.join(projectPath, 'node_modules');
|
|
370
|
+
const command = await getInstallCommand();
|
|
371
|
+
const dependenciesArgs = getInstallArgs();
|
|
372
|
+
console.log(installingDependencies());
|
|
373
|
+
try {
|
|
374
|
+
await external_fs_namespaceObject.promises.mkdir(nodeModulesPath, {
|
|
375
|
+
recursive: true
|
|
376
|
+
});
|
|
377
|
+
const stdio = 'development' === process.env.EXTENSION_ENV ? 'inherit' : 'ignore';
|
|
378
|
+
const child = (0, external_cross_spawn_namespaceObject.spawn)(command, dependenciesArgs, {
|
|
379
|
+
stdio,
|
|
380
|
+
cwd: projectPath
|
|
381
|
+
});
|
|
382
|
+
await new Promise((resolve, reject)=>{
|
|
383
|
+
child.on('close', (code)=>{
|
|
384
|
+
if (0 !== code) reject(new Error(installingDependenciesFailed(command, dependenciesArgs, code)));
|
|
385
|
+
else resolve();
|
|
386
|
+
});
|
|
387
|
+
child.on('error', (error)=>{
|
|
388
|
+
console.error(installingDependenciesProcessError(projectName, error));
|
|
389
|
+
reject(error);
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
} catch (error) {
|
|
393
|
+
console.error(cantInstallDependencies(projectName, error));
|
|
394
|
+
process.exit(1);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
const write_readme_file_filename = (0, external_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__);
|
|
398
|
+
const write_readme_file_dirname = external_path_namespaceObject.dirname(write_readme_file_filename);
|
|
399
|
+
async function writeReadmeFile(projectPath, projectName) {
|
|
400
|
+
const initTemplateReadme = await promises_namespaceObject.readFile(external_path_namespaceObject.join(write_readme_file_dirname, 'template', 'README.md'), 'utf-8');
|
|
401
|
+
const installCommand = await getInstallCommand();
|
|
402
|
+
const manifestJsonPath = external_path_namespaceObject.join(projectPath, 'manifest.json');
|
|
403
|
+
const manifestJson = JSON.parse(await promises_namespaceObject.readFile(manifestJsonPath, 'utf-8'));
|
|
404
|
+
const readmeFileEdited = initTemplateReadme.replaceAll('[projectName]', projectName).replaceAll("[templateDescription]", manifestJson.description).replaceAll('[runCommand]', installCommand);
|
|
405
|
+
try {
|
|
406
|
+
console.log(writingReadmeMetaData());
|
|
407
|
+
await promises_namespaceObject.mkdir(projectPath, {
|
|
408
|
+
recursive: true
|
|
409
|
+
});
|
|
410
|
+
await promises_namespaceObject.writeFile(external_path_namespaceObject.join(projectPath, 'README.md'), readmeFileEdited);
|
|
411
|
+
} catch (error) {
|
|
412
|
+
console.error(writingReadmeMetaDataEError(projectName, error));
|
|
413
|
+
process.exit(1);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
async function writeManifestJson(projectPath, projectName) {
|
|
417
|
+
const manifestJsonPath = external_path_namespaceObject.join(projectPath, 'manifest.json');
|
|
418
|
+
const manifestJsonContent = await promises_namespaceObject.readFile(manifestJsonPath);
|
|
419
|
+
const manifestJson = JSON.parse(manifestJsonContent.toString());
|
|
420
|
+
const manifestMetadata = {
|
|
421
|
+
...manifestJson,
|
|
422
|
+
name: external_path_namespaceObject.basename(projectPath),
|
|
423
|
+
author: 'Your Name'
|
|
424
|
+
};
|
|
425
|
+
try {
|
|
426
|
+
console.log(writingManifestJsonMetadata());
|
|
427
|
+
await promises_namespaceObject.writeFile(external_path_namespaceObject.join(projectPath, 'manifest.json'), JSON.stringify(manifestMetadata, null, 2));
|
|
428
|
+
} catch (error) {
|
|
429
|
+
console.error(writingManifestJsonMetadataError(projectName, error));
|
|
430
|
+
process.exit(1);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
async function generateExtensionTypes(projectPath, projectName) {
|
|
434
|
+
const extensionEnvFile = external_path_namespaceObject.join(projectPath, 'extension-env.d.ts');
|
|
435
|
+
const typePath = 'development' === process.env.EXTENSION_ENV ? external_path_namespaceObject.resolve(process.cwd(), 'programs/cli/types') : 'extension/dist/types';
|
|
436
|
+
const fileContent = `\
|
|
437
|
+
// Required Extension.js types for TypeScript projects.
|
|
30
438
|
// This file is auto-generated and should not be excluded.
|
|
31
439
|
// If you need additional types, consider creating a new *.d.ts file and
|
|
32
440
|
// referencing it in the "include" array of your tsconfig.json file.
|
|
33
441
|
// See https://www.typescriptlang.org/tsconfig#include for more information.
|
|
34
|
-
/// <reference types="${
|
|
442
|
+
/// <reference types="${typePath}/index.d.ts" />
|
|
35
443
|
|
|
36
444
|
// Polyfill types for browser.* APIs.
|
|
37
|
-
/// <reference types="${
|
|
38
|
-
`;
|
|
39
|
-
|
|
445
|
+
/// <reference types="${typePath}/polyfill.d.ts" />
|
|
446
|
+
`;
|
|
447
|
+
try {
|
|
448
|
+
await promises_namespaceObject.mkdir(projectPath, {
|
|
449
|
+
recursive: true
|
|
450
|
+
});
|
|
451
|
+
console.log(writingTypeDefinitions(projectName));
|
|
452
|
+
await promises_namespaceObject.writeFile(extensionEnvFile, fileContent);
|
|
453
|
+
} catch (error) {
|
|
454
|
+
console.error(writingTypeDefinitionsError(error));
|
|
455
|
+
process.exit(1);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
const globalDependencies = [
|
|
459
|
+
'',
|
|
460
|
+
'# dependencies',
|
|
461
|
+
'node_modules'
|
|
462
|
+
];
|
|
463
|
+
const globalTesting = [
|
|
464
|
+
'',
|
|
465
|
+
'# testing',
|
|
466
|
+
'coverage'
|
|
467
|
+
];
|
|
468
|
+
const globalProduction = [
|
|
469
|
+
'',
|
|
470
|
+
'# production',
|
|
471
|
+
'dist'
|
|
472
|
+
];
|
|
473
|
+
const globalMisc = [
|
|
474
|
+
'',
|
|
475
|
+
'# misc',
|
|
476
|
+
'.DS_Store'
|
|
477
|
+
];
|
|
478
|
+
const envFiles = [
|
|
479
|
+
'',
|
|
480
|
+
'# local env files',
|
|
481
|
+
'.env.local',
|
|
482
|
+
'.env.development.local',
|
|
483
|
+
'.env.test.local',
|
|
484
|
+
'.env.production.local'
|
|
485
|
+
];
|
|
486
|
+
const debugFiles = [
|
|
487
|
+
'',
|
|
488
|
+
'# debug files',
|
|
489
|
+
'npm-debug.log*',
|
|
490
|
+
'yarn-debug.log*',
|
|
491
|
+
'yarn-error.log*'
|
|
492
|
+
];
|
|
493
|
+
const extensionJsFiles = [
|
|
494
|
+
'',
|
|
495
|
+
'# extension.js',
|
|
496
|
+
'extension-env.d.ts'
|
|
497
|
+
];
|
|
498
|
+
const globalLines = [
|
|
499
|
+
'# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.',
|
|
500
|
+
...globalDependencies,
|
|
501
|
+
...globalTesting,
|
|
502
|
+
...globalProduction,
|
|
503
|
+
...globalMisc,
|
|
504
|
+
...envFiles,
|
|
505
|
+
...debugFiles,
|
|
506
|
+
...extensionJsFiles
|
|
507
|
+
];
|
|
508
|
+
async function writeGitignore(projectPath) {
|
|
509
|
+
const gitIgnorePath = external_path_namespaceObject.join(projectPath, '.gitignore');
|
|
510
|
+
const fileHandle = await promises_namespaceObject.open(gitIgnorePath, 'a+').catch((err)=>{
|
|
511
|
+
console.error(err);
|
|
512
|
+
process.exit(1);
|
|
513
|
+
});
|
|
514
|
+
const paths = new Set();
|
|
515
|
+
for await (let line of fileHandle.readLines({
|
|
516
|
+
autoClose: false
|
|
517
|
+
})){
|
|
518
|
+
line = line.trim();
|
|
519
|
+
if (0 !== line.length) paths.add(line);
|
|
520
|
+
}
|
|
521
|
+
const linesToAdd = globalLines.filter((line)=>!paths.has(line));
|
|
522
|
+
while('' === linesToAdd[linesToAdd.length - 1])linesToAdd.pop();
|
|
523
|
+
console.log(writingGitIgnore());
|
|
524
|
+
await fileHandle.appendFile(linesToAdd.join('\n')).catch((err)=>{
|
|
525
|
+
console.error(err);
|
|
526
|
+
process.exit(1);
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
async function initializeGitRepository(projectPath, projectName) {
|
|
530
|
+
const gitCommand = 'git';
|
|
531
|
+
const gitArgs = [
|
|
532
|
+
'init',
|
|
533
|
+
'--quiet'
|
|
534
|
+
];
|
|
535
|
+
console.log(initializingGitForRepository(projectName));
|
|
536
|
+
try {
|
|
537
|
+
const stdio = 'development' === process.env.EXTENSION_ENV ? 'inherit' : 'ignore';
|
|
538
|
+
const child = (0, external_cross_spawn_namespaceObject.spawn)(gitCommand, gitArgs, {
|
|
539
|
+
stdio,
|
|
540
|
+
cwd: projectPath
|
|
541
|
+
});
|
|
542
|
+
await new Promise((resolve, reject)=>{
|
|
543
|
+
child.on('close', (code)=>{
|
|
544
|
+
if (0 !== code) reject(new Error(initializingGitForRepositoryFailed(gitCommand, gitArgs, code)));
|
|
545
|
+
else resolve();
|
|
546
|
+
});
|
|
547
|
+
child.on('error', (error)=>{
|
|
548
|
+
console.error(initializingGitForRepositoryProcessError(projectName, error));
|
|
549
|
+
reject(error);
|
|
550
|
+
});
|
|
551
|
+
});
|
|
552
|
+
} catch (error) {
|
|
553
|
+
console.error(initializingGitForRepositoryError(projectName, error));
|
|
554
|
+
process.exit(1);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
async function setupBuiltInTests(projectPath, projectName) {
|
|
558
|
+
try {
|
|
559
|
+
const testSpecPath = external_path_namespaceObject.join(projectPath, 'tests', 'templates.spec.ts');
|
|
560
|
+
if (external_fs_namespaceObject.existsSync(testSpecPath)) external_fs_namespaceObject.unlinkSync(testSpecPath);
|
|
561
|
+
} catch (error) {
|
|
562
|
+
console.error(cantSetupBuiltInTests(projectName, error));
|
|
563
|
+
process.exit(1);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
async function extensionCreate(projectNameInput, { cliVersion, template = 'init', install = true }) {
|
|
567
|
+
if (!projectNameInput) throw new Error(noProjectName());
|
|
568
|
+
if (projectNameInput.startsWith('http')) throw new Error(noUrlAllowed());
|
|
569
|
+
const projectPath = external_path_namespaceObject.isAbsolute(projectNameInput) ? projectNameInput : external_path_namespaceObject.join(process.cwd(), projectNameInput);
|
|
570
|
+
const projectName = external_path_namespaceObject.basename(projectPath);
|
|
571
|
+
try {
|
|
572
|
+
await createDirectory(projectPath, projectName);
|
|
573
|
+
if ('init' === template) await importLocalTemplate(projectPath, projectName, template);
|
|
574
|
+
else await importExternalTemplate(projectPath, projectName, template);
|
|
575
|
+
await overridePackageJson(projectPath, projectName, {
|
|
576
|
+
template,
|
|
577
|
+
cliVersion
|
|
578
|
+
});
|
|
579
|
+
if (install) await installDependencies(projectPath, projectName);
|
|
580
|
+
await writeReadmeFile(projectPath, projectName);
|
|
581
|
+
await writeManifestJson(projectPath, projectName);
|
|
582
|
+
await initializeGitRepository(projectPath, projectName);
|
|
583
|
+
await writeGitignore(projectPath);
|
|
584
|
+
await setupBuiltInTests(projectPath, projectName);
|
|
585
|
+
if (isTypeScriptTemplate(template)) await generateExtensionTypes(projectPath, projectName);
|
|
586
|
+
const successfulInstall = await successfullInstall(projectPath, projectName);
|
|
587
|
+
console.log(successfulInstall);
|
|
588
|
+
} catch (error) {
|
|
589
|
+
console.error(error);
|
|
590
|
+
throw error;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
exports.extensionCreate = __webpack_exports__.extensionCreate;
|
|
594
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
595
|
+
"extensionCreate"
|
|
596
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
597
|
+
Object.defineProperty(exports, '__esModule', {
|
|
598
|
+
value: true
|
|
599
|
+
});
|
package/package.json
CHANGED
|
@@ -8,42 +8,50 @@
|
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">=18"
|
|
10
10
|
},
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/module.d.ts",
|
|
14
|
+
"import": "./dist/module.js",
|
|
15
|
+
"require": "./dist/module.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
14
18
|
"main": "./dist/module.js",
|
|
15
19
|
"types": "./dist/module.d.ts",
|
|
16
20
|
"files": [
|
|
17
21
|
"dist"
|
|
18
22
|
],
|
|
23
|
+
"name": "extension-create",
|
|
24
|
+
"version": "2.0.0-rc.26",
|
|
25
|
+
"description": "The create step of Extension.js",
|
|
19
26
|
"author": {
|
|
20
27
|
"name": "Cezar Augusto",
|
|
21
28
|
"email": "boss@cezaraugusto.net",
|
|
22
29
|
"url": "https://cezaraugusto.com"
|
|
23
30
|
},
|
|
24
31
|
"dependencies": {
|
|
25
|
-
"@colors/colors": "^1.6.0",
|
|
26
32
|
"@types/firefox-webext-browser": "^120.0.4",
|
|
33
|
+
"chalk": "^5.3.0",
|
|
27
34
|
"cross-spawn": "^7.0.6",
|
|
28
|
-
"go-git-it": "
|
|
29
|
-
"package-manager-detector": "^0.2.7"
|
|
35
|
+
"go-git-it": "4.0.0-1",
|
|
36
|
+
"package-manager-detector": "^0.2.7",
|
|
37
|
+
"tiny-glob": "^0.2.9"
|
|
30
38
|
},
|
|
31
39
|
"devDependencies": {
|
|
40
|
+
"@rslib/core": "^0.6.9",
|
|
32
41
|
"@types/cross-spawn": "^6.0.6",
|
|
33
42
|
"@types/node": "^22.10.1",
|
|
34
43
|
"@types/react-dom": "^19.0.1",
|
|
44
|
+
"@vitest/coverage-v8": "^1.3.1",
|
|
35
45
|
"globals": "^15.13.0",
|
|
36
|
-
"jest": "^29.7.0",
|
|
37
|
-
"ts-jest": "^29.3.1",
|
|
38
46
|
"tsconfig": "*",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
47
|
+
"typescript": "5.7.2",
|
|
48
|
+
"vitest": "^1.3.1"
|
|
41
49
|
},
|
|
42
50
|
"scripts": {
|
|
43
51
|
"clean": "rm -rf dist",
|
|
44
|
-
"watch": "
|
|
45
|
-
"compile": "
|
|
46
|
-
"test
|
|
47
|
-
"test:
|
|
52
|
+
"watch": "rslib build --watch",
|
|
53
|
+
"compile": "rslib build && bash install_scripts.sh",
|
|
54
|
+
"test:create": "vitest run",
|
|
55
|
+
"test:coverage": "vitest run --coverage"
|
|
48
56
|
}
|
|
49
57
|
}
|