extension-create 4.1.39 → 4.1.40-canary.458.001a6a0
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 +3 -3
- package/dist/lib/messages.d.ts +2 -0
- package/dist/lib/utils.d.ts +2 -2
- package/dist/module.cjs +123 -54
- package/dist/steps/import-external-template.d.ts +6 -1
- package/dist/test-template-javascript/.extension-create.json +2 -2
- package/dist/test-template-javascript/README.md +1 -1
- package/dist/test-template-javascript/package.json +1 -1
- package/package.json +5 -5
- package/templates/README.md +1 -1
- package/templates/javascript/.mcp.json +14 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
[npm-version-image]: https://img.shields.io/npm/v/extension-create.svg?color=
|
|
1
|
+
[npm-version-image]: https://img.shields.io/npm/v/extension-create.svg?color=0065e6
|
|
2
2
|
[npm-version-url]: https://www.npmjs.com/package/extension-create
|
|
3
|
-
[npm-downloads-image]: https://img.shields.io/npm/dm/extension-create.svg?color=
|
|
3
|
+
[npm-downloads-image]: https://img.shields.io/npm/dm/extension-create.svg?color=0065e6
|
|
4
4
|
[npm-downloads-url]: https://www.npmjs.com/package/extension-create
|
|
5
5
|
[action-image]: https://github.com/extension-js/extension.js/actions/workflows/ci.yml/badge.svg?branch=main
|
|
6
6
|
[action-url]: https://github.com/extension-js/extension.js/actions/workflows/ci.yml
|
|
@@ -53,7 +53,7 @@ Creates a new extension project with the specified configuration.
|
|
|
53
53
|
|
|
54
54
|
## Templates
|
|
55
55
|
|
|
56
|
-
Templates are sourced from the public
|
|
56
|
+
Templates are sourced from the public templates repository. Browse the catalog in the [Extension.js templates](https://github.com/extension-js/templates) and reference templates by name (for example, `content`, `content-react`, `content-vue`).
|
|
57
57
|
|
|
58
58
|
## License
|
|
59
59
|
|
package/dist/lib/messages.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare function templateOverrideFetchFailed(url: string, error: unknown)
|
|
|
24
24
|
export declare function templateDownloadFailed(templateName: string, error: unknown): string;
|
|
25
25
|
export declare function templateOfflineFallback(requestedTemplate: string, fallbackTemplate: string, error: unknown): string;
|
|
26
26
|
export declare function removedStaleTemplateLockfiles(fileNames: string[]): string;
|
|
27
|
+
export declare function droppedTemplateLinks(linkPaths: string[]): string;
|
|
27
28
|
export declare function initializingGitForRepository(projectName: string): string;
|
|
28
29
|
export declare function initializingGitSkipped(projectName: string, reason: string): string;
|
|
29
30
|
export declare function firstCommitSkipped(projectName: string, reason: string): string;
|
|
@@ -55,4 +56,5 @@ export declare function writingGitIgnore(): string;
|
|
|
55
56
|
export declare function writingReadmeMetaDataError(error: unknown): string;
|
|
56
57
|
export declare function cantSetupBuiltInTests(error: unknown): string;
|
|
57
58
|
export declare function keepingExistingGitignore(projectName: string): string;
|
|
59
|
+
export declare function keepingExistingMcpConfig(projectName: string): string;
|
|
58
60
|
export declare function existingRepositoryKept(projectName: string): string;
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const NEVER_SCAFFOLDED_DIRS: string[];
|
|
2
|
-
export declare function copyDirectoryWithSymlinks(source: string, destination: string): Promise<
|
|
3
|
-
export declare function moveDirectoryContents(source: string, destination: string): Promise<
|
|
2
|
+
export declare function copyDirectoryWithSymlinks(source: string, destination: string, root?: string): Promise<string[]>;
|
|
3
|
+
export declare function moveDirectoryContents(source: string, destination: string, root?: string): Promise<string[]>;
|
|
4
4
|
export declare function shellQuote(value: string): string;
|
|
5
5
|
export declare function directoryWriteFailure(directory: string): Promise<NodeJS.ErrnoException | null>;
|
|
6
6
|
export declare function isTypeScriptTemplate(templateName: string): boolean;
|
package/dist/module.cjs
CHANGED
|
@@ -244,7 +244,36 @@ const NEVER_SCAFFOLDED_DIRS = [
|
|
|
244
244
|
'.extension-js',
|
|
245
245
|
'.git'
|
|
246
246
|
];
|
|
247
|
-
async function
|
|
247
|
+
async function linkTargetInside(linkPath, root) {
|
|
248
|
+
let real;
|
|
249
|
+
try {
|
|
250
|
+
real = await promises_namespaceObject.realpath(linkPath);
|
|
251
|
+
} catch {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
const relative = external_node_path_namespaceObject.relative(root, real);
|
|
255
|
+
if (!relative || relative.startsWith('..') || external_node_path_namespaceObject.isAbsolute(relative)) return null;
|
|
256
|
+
return real;
|
|
257
|
+
}
|
|
258
|
+
function templateRelative(root, file) {
|
|
259
|
+
return external_node_path_namespaceObject.relative(root, file).split(external_node_path_namespaceObject.sep).join('/');
|
|
260
|
+
}
|
|
261
|
+
async function recreateLink(sourcePath, destPath, real) {
|
|
262
|
+
const target = external_node_path_namespaceObject.relative(external_node_path_namespaceObject.dirname(sourcePath), real) || '.';
|
|
263
|
+
const kind = (await promises_namespaceObject.stat(real)).isDirectory() ? 'dir' : 'file';
|
|
264
|
+
try {
|
|
265
|
+
await promises_namespaceObject.symlink(target, destPath, kind);
|
|
266
|
+
} catch (caught) {
|
|
267
|
+
const err = caught;
|
|
268
|
+
if (err?.code === 'EPERM' || err?.code === 'ENOTSUP') await promises_namespaceObject.cp(real, destPath, {
|
|
269
|
+
recursive: true
|
|
270
|
+
});
|
|
271
|
+
else throw err;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
async function copyDirectoryWithSymlinks(source, destination, root) {
|
|
275
|
+
const templateRoot = root ?? await promises_namespaceObject.realpath(source);
|
|
276
|
+
const dropped = [];
|
|
248
277
|
const entries = await promises_namespaceObject.readdir(source, {
|
|
249
278
|
withFileTypes: true
|
|
250
279
|
});
|
|
@@ -256,23 +285,21 @@ async function copyDirectoryWithSymlinks(source, destination) {
|
|
|
256
285
|
const destPath = external_node_path_namespaceObject.join(destination, entry.name);
|
|
257
286
|
if (entry.isDirectory()) {
|
|
258
287
|
if (NEVER_SCAFFOLDED_DIRS.includes(entry.name)) continue;
|
|
259
|
-
await copyDirectoryWithSymlinks(sourcePath, destPath);
|
|
260
|
-
} else if (entry.isSymbolicLink())
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
recursive: true
|
|
269
|
-
});
|
|
270
|
-
} else throw err;
|
|
271
|
-
}
|
|
272
|
-
else await promises_namespaceObject.copyFile(sourcePath, destPath);
|
|
288
|
+
dropped.push(...await copyDirectoryWithSymlinks(sourcePath, destPath, templateRoot));
|
|
289
|
+
} else if (entry.isSymbolicLink()) {
|
|
290
|
+
const real = await linkTargetInside(sourcePath, templateRoot);
|
|
291
|
+
if (!real) {
|
|
292
|
+
dropped.push(templateRelative(templateRoot, sourcePath));
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
await recreateLink(sourcePath, destPath, real);
|
|
296
|
+
} else await promises_namespaceObject.copyFile(sourcePath, destPath);
|
|
273
297
|
}
|
|
298
|
+
return dropped;
|
|
274
299
|
}
|
|
275
|
-
async function moveDirectoryContents(source, destination) {
|
|
300
|
+
async function moveDirectoryContents(source, destination, root) {
|
|
301
|
+
const templateRoot = root ?? await promises_namespaceObject.realpath(source);
|
|
302
|
+
const dropped = [];
|
|
276
303
|
await promises_namespaceObject.mkdir(destination, {
|
|
277
304
|
recursive: true
|
|
278
305
|
});
|
|
@@ -282,20 +309,15 @@ async function moveDirectoryContents(source, destination) {
|
|
|
282
309
|
for (const entry of entries){
|
|
283
310
|
const sourcePath = external_node_path_namespaceObject.join(source, entry.name);
|
|
284
311
|
const destPath = external_node_path_namespaceObject.join(destination, entry.name);
|
|
285
|
-
if (entry.isDirectory()) await moveDirectoryContents(sourcePath, destPath);
|
|
286
|
-
else if (entry.isSymbolicLink())
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
recursive: true
|
|
295
|
-
});
|
|
296
|
-
} else throw err;
|
|
297
|
-
}
|
|
298
|
-
else try {
|
|
312
|
+
if (entry.isDirectory()) dropped.push(...await moveDirectoryContents(sourcePath, destPath, templateRoot));
|
|
313
|
+
else if (entry.isSymbolicLink()) {
|
|
314
|
+
const real = await linkTargetInside(sourcePath, templateRoot);
|
|
315
|
+
if (!real) {
|
|
316
|
+
dropped.push(templateRelative(templateRoot, sourcePath));
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
await recreateLink(sourcePath, destPath, real);
|
|
320
|
+
} else try {
|
|
299
321
|
await promises_namespaceObject.rename(sourcePath, destPath);
|
|
300
322
|
} catch (caught) {
|
|
301
323
|
const err = caught;
|
|
@@ -311,6 +333,7 @@ async function moveDirectoryContents(source, destination) {
|
|
|
311
333
|
recursive: true,
|
|
312
334
|
force: true
|
|
313
335
|
});
|
|
336
|
+
return dropped;
|
|
314
337
|
}
|
|
315
338
|
const SHELL_SAFE_PATH = /^[A-Za-z0-9_@%+=:,./-]+$/;
|
|
316
339
|
const SINGLE_QUOTE = String.fromCharCode(39);
|
|
@@ -434,14 +457,14 @@ function templateFetchTimedOut(templateName, ms) {
|
|
|
434
457
|
return `${prefix('error')} Couldn't fetch the template ${external_pintor_default().blue(templateName)} within ${Math.round(ms / 1000)}s.\n${external_pintor_default().red('- Check your network connection.')}\n${external_pintor_default().red('- Set')} ${external_pintor_default().blue('EXTENSION_CREATE_TIMEOUT_MS')} ${external_pintor_default().red('to allow more time.')}`;
|
|
435
458
|
}
|
|
436
459
|
function templateNotFoundInCatalog(templateName, error) {
|
|
437
|
-
return `${prefix('error')} The template ${external_pintor_default().blue(templateName)} is not in the extension-js/
|
|
460
|
+
return `${prefix('error')} The template ${external_pintor_default().blue(templateName)} is not in the extension-js/templates catalog.\n` + (error ? `${fmt.label('REASON')} ${fmt.val(fmt.truncate(String(error)))}\n` : '') + `${external_pintor_default().red('- Run')} ${external_pintor_default().blue('extension create --help')} ${external_pintor_default().red('to list the valid template names.')}\n` + `${external_pintor_default().red('- Pass a GitHub URL to use a template from anywhere.')}`;
|
|
438
461
|
}
|
|
439
462
|
const CAUSE_STACK_LINE = /^\s*at\s/;
|
|
440
463
|
function causeDigest(error) {
|
|
441
464
|
return String(error?.message || error).split(/\r?\n/).map((line)=>line.trim()).filter((line)=>'' !== line && !CAUSE_STACK_LINE.test(line)).join(' ');
|
|
442
465
|
}
|
|
443
466
|
function templatePathNotFound(requested) {
|
|
444
|
-
return `${prefix('error')} Couldn't find the template ${external_pintor_default().blue(requested)}.\n${fmt.label('SEARCHED')} ${fmt.val(`that path on this machine, then the extension-js/
|
|
467
|
+
return `${prefix('error')} Couldn't find the template ${external_pintor_default().blue(requested)}.\n${fmt.label('SEARCHED')} ${fmt.val(`that path on this machine, then the extension-js/templates catalog for ${external_node_path_namespaceObject.basename(requested)}`)}\n${external_pintor_default().red('- Pass the path of a template directory that exists.')}\n${external_pintor_default().red('- Run')} ${external_pintor_default().blue('extension create --help')} ${external_pintor_default().red('to list the valid template names.')}`;
|
|
445
468
|
}
|
|
446
469
|
function templateDirectoryIsDestination(templateDir, projectPath) {
|
|
447
470
|
return `${prefix('error')} Can't scaffold a project inside the template it copies.\n${fmt.label('TEMPLATE')} ${fmt.val(templateDir)}\n${fmt.label('OUTPUT')} ${fmt.val(projectPath)}\n${external_pintor_default().red('Choose an output path outside the template directory.')}`;
|
|
@@ -459,20 +482,24 @@ function templateArchiveEntryOutside(url, entry, override) {
|
|
|
459
482
|
return `${prefix('error')} The ZIP archive at the remote URL contains a path outside its folder, so it was refused. Nothing was written.\n${fmt.label('URL')} ${fmt.val(fmt.truncate(url, 160))}\n${fmt.label('ENTRY')} ${fmt.val(fmt.truncate(entry, 160))}\n` + (override ? `${fmt.label('SET BY')} ${fmt.val('EXTENSION_CREATE_TEMPLATE_URL')}\n${overrideRemedy()}` : `${external_pintor_default().red('Use an archive whose entries all stay inside its folder.')}`);
|
|
460
483
|
}
|
|
461
484
|
function overrideRemedy() {
|
|
462
|
-
return `${external_pintor_default().red('Point')} ${external_pintor_default().blue('EXTENSION_CREATE_TEMPLATE_URL')} ${external_pintor_default().red('at a ZIP of the
|
|
485
|
+
return `${external_pintor_default().red('Point')} ${external_pintor_default().blue('EXTENSION_CREATE_TEMPLATE_URL')} ${external_pintor_default().red('at a ZIP of the templates catalog, or unset it to use the default catalog.')}`;
|
|
463
486
|
}
|
|
464
487
|
function templateOverrideFetchFailed(url, error) {
|
|
465
488
|
return `${prefix('error')} Couldn't fetch the template catalog from ${external_pintor_default().blue('EXTENSION_CREATE_TEMPLATE_URL')}.\n${fmt.label('URL')} ${fmt.val(fmt.truncate(url, 160))}\n${fmt.label('REASON')} ${fmt.val(fmt.truncate(causeDigest(error), 600))}\n` + overrideRemedy();
|
|
466
489
|
}
|
|
467
490
|
function templateDownloadFailed(templateName, error) {
|
|
468
|
-
return `${prefix('error')} Couldn't download the template ${external_pintor_default().blue(templateName)} from ${fmt.val('github.com/extension-js/
|
|
491
|
+
return `${prefix('error')} Couldn't download the template ${external_pintor_default().blue(templateName)} from ${fmt.val('github.com/extension-js/templates')}.\n${fmt.label('REASON')} ${fmt.val(fmt.truncate(String(error?.message || error)))}\n${external_pintor_default().red('- Check your network connection and any GitHub rate limit, then try again.')}\n${external_pintor_default().red('- Set')} ${external_pintor_default().blue('EXTENSION_CREATE_TIMEOUT_MS')} ${external_pintor_default().red('to allow more time.')}`;
|
|
469
492
|
}
|
|
470
493
|
function templateOfflineFallback(requestedTemplate, fallbackTemplate, error) {
|
|
471
|
-
return `${prefix('info')} Couldn't download the template ${external_pintor_default().blue(requestedTemplate)} from ${fmt.val('github.com/extension-js/
|
|
494
|
+
return `${prefix('info')} Couldn't download the template ${external_pintor_default().blue(requestedTemplate)} from ${fmt.val('github.com/extension-js/templates')}, so this scaffold uses the offline ${external_pintor_default().blue(fallbackTemplate)} template instead.\n${fmt.label('REASON')} ${fmt.val(fmt.truncate(String(error?.message || error)))}\n${external_pintor_default().gray('- Reconnect and run')} ${external_pintor_default().blue(`extension create --template ${requestedTemplate}`)} ${external_pintor_default().gray('to scaffold it.')}`;
|
|
472
495
|
}
|
|
473
496
|
function removedStaleTemplateLockfiles(fileNames) {
|
|
474
497
|
return `${prefix('info')} Removed the template ${fileNames.map((name)=>fmt.val(name)).join(', ')}. The first install writes a fresh one.`;
|
|
475
498
|
}
|
|
499
|
+
function droppedTemplateLinks(linkPaths) {
|
|
500
|
+
const noun = 1 === linkPaths.length ? 'link' : 'links';
|
|
501
|
+
return `${prefix('info')} Left out the template ${noun} ${linkPaths.map((name)=>fmt.val(name)).join(', ')}: ${1 === linkPaths.length ? 'it points' : 'they point'} outside the template.`;
|
|
502
|
+
}
|
|
476
503
|
function initializingGitForRepository(projectName) {
|
|
477
504
|
return `${prefix('debug')} create git init name=${projectName}`;
|
|
478
505
|
}
|
|
@@ -587,6 +614,9 @@ function cantSetupBuiltInTests(error) {
|
|
|
587
614
|
function keepingExistingGitignore(projectName) {
|
|
588
615
|
return `${prefix('info')} ${external_pintor_default().blue(projectName)} already has a ${external_pintor_default().blue('.gitignore')}.\nKeeping its rules and adding the template rules it lacks.`;
|
|
589
616
|
}
|
|
617
|
+
function keepingExistingMcpConfig(projectName) {
|
|
618
|
+
return `${prefix('info')} ${external_pintor_default().blue(projectName)} already has a ${external_pintor_default().blue('.mcp.json')}.\nKeeping it as it is. The template file was not written over it.`;
|
|
619
|
+
}
|
|
590
620
|
function existingRepositoryKept(projectName) {
|
|
591
621
|
return `${prefix('info')} ${external_pintor_default().blue(projectName)} is already a git repository with history.\nLeft it uncommitted. Review the scaffold and run ${external_pintor_default().blue('git add -A && git commit')} yourself.`;
|
|
592
622
|
}
|
|
@@ -597,9 +627,10 @@ const allowlist = [
|
|
|
597
627
|
'LICENSE',
|
|
598
628
|
'node_modules'
|
|
599
629
|
];
|
|
600
|
-
const HIDDEN_FILES_TEMPLATES_SHIP =
|
|
601
|
-
'.gitignore'
|
|
602
|
-
|
|
630
|
+
const HIDDEN_FILES_TEMPLATES_SHIP = {
|
|
631
|
+
'.gitignore': keepingExistingGitignore,
|
|
632
|
+
'.mcp.json': keepingExistingMcpConfig
|
|
633
|
+
};
|
|
603
634
|
async function createDirectory(projectPath, projectName, logger) {
|
|
604
635
|
logger.log(startingNewExtension(projectName));
|
|
605
636
|
const directoryPreExisted = (0, external_node_fs_namespaceObject.existsSync)(projectPath);
|
|
@@ -615,7 +646,7 @@ async function createDirectory(projectPath, projectName, logger) {
|
|
|
615
646
|
const conflictMessage = await directoryHasConflicts(projectPath, conflictingFiles);
|
|
616
647
|
throw new Error(conflictMessage);
|
|
617
648
|
}
|
|
618
|
-
for (const hidden of HIDDEN_FILES_TEMPLATES_SHIP)if (currentDir.includes(hidden)) logger.log(
|
|
649
|
+
for (const [hidden, keeping] of Object.entries(HIDDEN_FILES_TEMPLATES_SHIP))if (currentDir.includes(hidden)) logger.log(keeping(projectName));
|
|
619
650
|
} catch (error) {
|
|
620
651
|
if (hasChannelPrefix(String(error?.message ?? error))) throw error;
|
|
621
652
|
throw new Error(createDirectoryError(projectName, error));
|
|
@@ -788,8 +819,8 @@ const NETWORK_TIMEOUT_MS = (()=>{
|
|
|
788
819
|
const raw = parseInt(String(process.env.EXTENSION_CREATE_TIMEOUT_MS || ''), 10);
|
|
789
820
|
return Number.isFinite(raw) && raw > 0 ? raw : 60000;
|
|
790
821
|
})();
|
|
791
|
-
const CODELOAD_BASE = 'https://codeload.github.com/extension-js/
|
|
792
|
-
const DEFAULT_TEMPLATES_REF = '
|
|
822
|
+
const CODELOAD_BASE = 'https://codeload.github.com/extension-js/templates/zip';
|
|
823
|
+
const DEFAULT_TEMPLATES_REF = '55291446965c7289ce77cf887ab7f69424d7d31e';
|
|
793
824
|
const BUNDLED_TEMPLATES = [
|
|
794
825
|
"javascript"
|
|
795
826
|
];
|
|
@@ -1050,17 +1081,18 @@ async function withSuppressedOutput(task) {
|
|
|
1050
1081
|
function bundledTemplateDir(templateName) {
|
|
1051
1082
|
return external_node_path_namespaceObject.join(__dirname, '..', 'templates', templateName);
|
|
1052
1083
|
}
|
|
1053
|
-
async function copyTemplateDirectory(sourceDir, projectPath, logger,
|
|
1054
|
-
await copyDirectoryWithSymlinks(sourceDir, projectPath);
|
|
1055
|
-
|
|
1084
|
+
async function copyTemplateDirectory(sourceDir, projectPath, logger, ownerFiles) {
|
|
1085
|
+
const droppedLinks = await copyDirectoryWithSymlinks(sourceDir, projectPath);
|
|
1086
|
+
if (droppedLinks.length) logger.log(droppedTemplateLinks(droppedLinks));
|
|
1087
|
+
await restoreOwnerHiddenFiles(projectPath, ownerFiles);
|
|
1056
1088
|
await removeTemplateScaffoldingFiles(projectPath);
|
|
1057
1089
|
const dropped = await removeStaleTemplateLockfiles(projectPath);
|
|
1058
1090
|
if (dropped.length) logger.log(removedStaleTemplateLockfiles(dropped));
|
|
1059
1091
|
}
|
|
1060
|
-
async function copyBundledTemplate(templateName, projectPath, logger,
|
|
1092
|
+
async function copyBundledTemplate(templateName, projectPath, logger, ownerFiles = NO_OWNER_FILES) {
|
|
1061
1093
|
const localTemplate = bundledTemplateDir(templateName);
|
|
1062
1094
|
if (!(0, external_node_fs_namespaceObject.existsSync)(localTemplate)) return;
|
|
1063
|
-
await copyTemplateDirectory(localTemplate, projectPath, logger,
|
|
1095
|
+
await copyTemplateDirectory(localTemplate, projectPath, logger, ownerFiles);
|
|
1064
1096
|
return {
|
|
1065
1097
|
template: templateName,
|
|
1066
1098
|
source: 'bundled'
|
|
@@ -1185,6 +1217,40 @@ async function restoreOwnerGitignore(projectPath, ownerContents) {
|
|
|
1185
1217
|
const merged = 0 === added.length ? ownerContents : `${ownerContents.replace(/\n?$/, '\n')}\n# Extension.js template rules\n${added.join('\n')}\n`;
|
|
1186
1218
|
await promises_namespaceObject.writeFile(target, merged);
|
|
1187
1219
|
}
|
|
1220
|
+
async function readOwnerMcpConfig(projectPath) {
|
|
1221
|
+
try {
|
|
1222
|
+
return await promises_namespaceObject.readFile(external_node_path_namespaceObject.join(projectPath, '.mcp.json'));
|
|
1223
|
+
} catch {
|
|
1224
|
+
return null;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
const NO_OWNER_FILES = {
|
|
1228
|
+
gitignore: null,
|
|
1229
|
+
mcpConfig: null
|
|
1230
|
+
};
|
|
1231
|
+
async function readOwnerHiddenFiles(projectPath) {
|
|
1232
|
+
return {
|
|
1233
|
+
gitignore: await readOwnerGitignore(projectPath),
|
|
1234
|
+
mcpConfig: await readOwnerMcpConfig(projectPath)
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
async function restoreOwnerHiddenFiles(projectPath, ownerFiles) {
|
|
1238
|
+
await restoreOwnerGitignore(projectPath, ownerFiles.gitignore);
|
|
1239
|
+
if (null !== ownerFiles.mcpConfig) await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(projectPath, '.mcp.json'), ownerFiles.mcpConfig);
|
|
1240
|
+
}
|
|
1241
|
+
async function putBackOwnerHiddenFiles(projectPath, ownerFiles) {
|
|
1242
|
+
const files = [
|
|
1243
|
+
[
|
|
1244
|
+
'.gitignore',
|
|
1245
|
+
ownerFiles.gitignore
|
|
1246
|
+
],
|
|
1247
|
+
[
|
|
1248
|
+
'.mcp.json',
|
|
1249
|
+
ownerFiles.mcpConfig
|
|
1250
|
+
]
|
|
1251
|
+
];
|
|
1252
|
+
for (const [name, contents] of files)if (null !== contents) await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(projectPath, name), contents).catch(()=>{});
|
|
1253
|
+
}
|
|
1188
1254
|
async function importExternalTemplate(projectPath, projectName, template, logger, options) {
|
|
1189
1255
|
const templateName = external_node_path_namespaceObject.basename(template);
|
|
1190
1256
|
const resolvedTemplate = template;
|
|
@@ -1199,7 +1265,7 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1199
1265
|
if (dirExistedBeforeImport) try {
|
|
1200
1266
|
preExistingEntries = await promises_namespaceObject.readdir(projectPath);
|
|
1201
1267
|
} catch {}
|
|
1202
|
-
const
|
|
1268
|
+
const ownerFiles = dirExistedBeforeImport ? await readOwnerHiddenFiles(projectPath) : NO_OWNER_FILES;
|
|
1203
1269
|
let tempRoot;
|
|
1204
1270
|
try {
|
|
1205
1271
|
if (isRefusedHttpTemplateUrl(template)) throw new InsecureTemplateUrlError(template);
|
|
@@ -1211,14 +1277,14 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1211
1277
|
recursive: true
|
|
1212
1278
|
});
|
|
1213
1279
|
if (localTemplateDir) {
|
|
1214
|
-
await copyTemplateDirectory(localTemplateDir, projectPath, logger,
|
|
1280
|
+
await copyTemplateDirectory(localTemplateDir, projectPath, logger, ownerFiles);
|
|
1215
1281
|
return {
|
|
1216
1282
|
template: external_node_path_namespaceObject.basename(localTemplateDir),
|
|
1217
1283
|
source: 'local'
|
|
1218
1284
|
};
|
|
1219
1285
|
}
|
|
1220
1286
|
if (!isHttp && !isGithub && BUNDLED_TEMPLATES.includes(resolvedTemplate)) {
|
|
1221
|
-
const provenance = await copyBundledTemplate(resolvedTemplate, projectPath, logger,
|
|
1287
|
+
const provenance = await copyBundledTemplate(resolvedTemplate, projectPath, logger, ownerFiles);
|
|
1222
1288
|
if (provenance) return provenance;
|
|
1223
1289
|
}
|
|
1224
1290
|
tempRoot = await promises_namespaceObject.mkdtemp(external_node_path_namespaceObject.join(external_node_os_namespaceObject.tmpdir(), 'extension-js-create-'));
|
|
@@ -1258,6 +1324,7 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1258
1324
|
return body;
|
|
1259
1325
|
};
|
|
1260
1326
|
let provenance;
|
|
1327
|
+
let droppedLinks = [];
|
|
1261
1328
|
if (isGithub) {
|
|
1262
1329
|
try {
|
|
1263
1330
|
await runGoGitIt(template, tempPath);
|
|
@@ -1269,7 +1336,7 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1269
1336
|
});
|
|
1270
1337
|
const preferred = candidates.find((d)=>d.isDirectory() && d.name === templateName);
|
|
1271
1338
|
const srcPath = preferred ? external_node_path_namespaceObject.join(tempPath, templateName) : tempPath;
|
|
1272
|
-
await moveDirectoryContents(srcPath, projectPath);
|
|
1339
|
+
droppedLinks = await moveDirectoryContents(srcPath, projectPath);
|
|
1273
1340
|
provenance = {
|
|
1274
1341
|
template: resolvedTemplateName,
|
|
1275
1342
|
source: template
|
|
@@ -1281,7 +1348,7 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1281
1348
|
});
|
|
1282
1349
|
await extractZipBufferTo(data, tempPath, template);
|
|
1283
1350
|
const sourcePath = await getZipSourcePath(tempPath, template);
|
|
1284
|
-
await moveDirectoryContents(sourcePath, projectPath);
|
|
1351
|
+
droppedLinks = await moveDirectoryContents(sourcePath, projectPath);
|
|
1285
1352
|
provenance = {
|
|
1286
1353
|
template: resolvedTemplateName,
|
|
1287
1354
|
source: template
|
|
@@ -1296,7 +1363,8 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1296
1363
|
} : {}
|
|
1297
1364
|
};
|
|
1298
1365
|
}
|
|
1299
|
-
|
|
1366
|
+
if (droppedLinks.length) logger.log(droppedTemplateLinks(droppedLinks));
|
|
1367
|
+
await restoreOwnerHiddenFiles(projectPath, ownerFiles);
|
|
1300
1368
|
await removeTemplateScaffoldingFiles(projectPath);
|
|
1301
1369
|
const droppedLockfiles = await removeStaleTemplateLockfiles(projectPath);
|
|
1302
1370
|
if (droppedLockfiles.length) logger.log(removedStaleTemplateLockfiles(droppedLockfiles));
|
|
@@ -1308,7 +1376,7 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1308
1376
|
await promises_namespaceObject.mkdir(projectPath, {
|
|
1309
1377
|
recursive: true
|
|
1310
1378
|
});
|
|
1311
|
-
const fallback = await copyBundledTemplate(OFFLINE_FALLBACK_TEMPLATE, projectPath, logger,
|
|
1379
|
+
const fallback = await copyBundledTemplate(OFFLINE_FALLBACK_TEMPLATE, projectPath, logger, ownerFiles);
|
|
1312
1380
|
if (fallback) {
|
|
1313
1381
|
logger.log(templateOfflineFallback(resolvedTemplateName, OFFLINE_FALLBACK_TEMPLATE, error));
|
|
1314
1382
|
return fallback;
|
|
@@ -1318,6 +1386,7 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1318
1386
|
const frame = insecureUrl ? templateUrlNotHttps(insecureUrl.url) : error instanceof TemplateNotFoundError ? looksLikeTemplatePath(template) ? templatePathNotFound(template) : templateNotFoundInCatalog(templateName, error.cause) : error instanceof TemplateNotZipError ? templateUrlNotZip(error.url, error.got, catalogOverride) : error instanceof TemplateArchiveEntryOutsideError ? templateArchiveEntryOutside(error.url, error.entry, catalogOverride) : error instanceof TemplateArchiveDamagedError ? templateArchiveDamaged(error.url, error.reason, catalogOverride) : error instanceof TemplateDownloadError ? isHttp ? templateUrlFetchFailed(template, error) : catalogOverride ? templateOverrideFetchFailed(catalogOverride, error) : templateDownloadFailed(templateName, error) : null;
|
|
1319
1387
|
if (null === frame && !hasChannelPrefix(String(error?.message))) logger.error(installingFromTemplateError(templateName, error));
|
|
1320
1388
|
await cleanupFailedImport(projectPath, ownsProjectDir, preExistingEntries);
|
|
1389
|
+
if (!ownsProjectDir) await putBackOwnerHiddenFiles(projectPath, ownerFiles);
|
|
1321
1390
|
if (null !== frame && error instanceof Error) error.message = frame;
|
|
1322
1391
|
throw error;
|
|
1323
1392
|
} finally{
|
|
@@ -2473,7 +2542,7 @@ async function writeReadmeFile(projectPath, projectName, logger, packageManager)
|
|
|
2473
2542
|
const screenshotHref = hasPublicScreenshot ? './public/screenshot.png' : hasRootScreenshot ? './screenshot.png' : null;
|
|
2474
2543
|
const screenshotEmbed = screenshotHref ? `\n\n` : '';
|
|
2475
2544
|
const blockquote = description ? `> ${description}\n\n` : '';
|
|
2476
|
-
const readme = `<a href="https://extension.js.org" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/Powered%20by%20%7C%20Extension.js-
|
|
2545
|
+
const readme = `<a href="https://extension.js.org" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/Powered%20by%20%7C%20Extension.js-0065e6" alt="Powered by Extension.js" align="right" /></a>\n\n# ${projectName}\n\n` + blockquote + `${screenshotEmbed}` + `## Commands\n` + `\n` + `### dev\n` + `\n` + "Run the extension in development mode. Target a browser with `--browser`:\n" + `\n` + "```bash\n" + `${runPrefix} dev\n` + `${runPrefix} dev${argSeparator} --browser=firefox\n` + `${runPrefix} dev${argSeparator} --browser=edge\n` + "```\n" + `\n` + `### build\n` + `\n` + `Build for production. Convenience scripts target each browser:\n` + `\n` + "```bash\n" + `${runPrefix} build # Chromium (default)\n` + `${runPrefix} build:firefox\n` + `${runPrefix} build:edge\n` + "```\n" + `\n` + `### preview\n` + `\n` + `Preview the production build in the browser:\n` + `\n` + "```bash\n" + `${runPrefix} preview\n` + "```\n" + `\n` + `## Learn more\n` + `\n` + `[Extension.js docs](https://extension.js.org).\n`;
|
|
2477
2546
|
try {
|
|
2478
2547
|
if (isDebug()) logger.log(writingReadmeMetaData());
|
|
2479
2548
|
await promises_namespaceObject.mkdir(projectPath, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const DEFAULT_TEMPLATES_REF = "
|
|
1
|
+
export declare const DEFAULT_TEMPLATES_REF = "55291446965c7289ce77cf887ab7f69424d7d31e";
|
|
2
2
|
export declare const BUNDLED_TEMPLATES: readonly string[];
|
|
3
3
|
export declare const DEFAULT_TEMPLATE_NAME = "typescript";
|
|
4
4
|
export declare const OFFLINE_FALLBACK_TEMPLATE = "javascript";
|
|
@@ -52,6 +52,11 @@ export interface ImportExternalTemplateOptions {
|
|
|
52
52
|
allowOfflineFallback?: boolean;
|
|
53
53
|
}
|
|
54
54
|
export declare function cleanupFailedImport(projectPath: string, ownsProjectDir: boolean, preExistingEntries: string[]): Promise<void>;
|
|
55
|
+
export interface OwnerHiddenFiles {
|
|
56
|
+
gitignore: string | null;
|
|
57
|
+
mcpConfig: Buffer | null;
|
|
58
|
+
}
|
|
59
|
+
export declare function putBackOwnerHiddenFiles(projectPath: string, ownerFiles: OwnerHiddenFiles): Promise<void>;
|
|
55
60
|
export declare function importExternalTemplate(projectPath: string, projectName: string, template: string, logger: {
|
|
56
61
|
log(...args: unknown[]): void;
|
|
57
62
|
error(...args: unknown[]): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<a href="https://extension.js.org" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/Powered%20by%20%7C%20Extension.js-
|
|
1
|
+
<a href="https://extension.js.org" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/Powered%20by%20%7C%20Extension.js-0065e6" alt="Powered by Extension.js" align="right" /></a>
|
|
2
2
|
|
|
3
3
|
# test-template-javascript
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
-
"development": "./
|
|
14
|
+
"development": "./module.ts",
|
|
15
15
|
"types": "./dist/module.d.ts",
|
|
16
16
|
"import": "./dist/module.cjs",
|
|
17
17
|
"require": "./dist/module.cjs",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"templates"
|
|
26
26
|
],
|
|
27
27
|
"name": "extension-create",
|
|
28
|
-
"version": "4.1.
|
|
28
|
+
"version": "4.1.40-canary.458.001a6a0",
|
|
29
29
|
"description": "The standalone extension creation engine for Extension.js",
|
|
30
30
|
"author": {
|
|
31
31
|
"name": "Cezar Augusto",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"clean": "rm -rf dist",
|
|
46
|
-
"watch": "rslib build --watch",
|
|
47
|
-
"compile": "rslib build",
|
|
46
|
+
"watch": "node ../../scripts/run-locked.mjs watch \"rslib build --watch\"",
|
|
47
|
+
"compile": "node ../../scripts/run-locked.mjs compile \"rslib build\"",
|
|
48
48
|
"format": "biome format --write .",
|
|
49
49
|
"lint": "biome lint . && eslint .",
|
|
50
50
|
"pretest:create": "pnpm compile",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@biomejs/biome": "^2.2.4",
|
|
88
88
|
"@changesets/cli": "^3.0.2",
|
|
89
|
-
"@rslib/core": "^1.0.
|
|
89
|
+
"@rslib/core": "^1.0.6",
|
|
90
90
|
"@types/chrome": "^0.1.33",
|
|
91
91
|
"@types/cross-spawn": "^6.0.6",
|
|
92
92
|
"@types/node": "^26",
|
package/templates/README.md
CHANGED