extension-create 3.8.6 → 3.8.7-canary.200.6494abb
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.cjs +52 -17
- package/dist/steps/write-package-json.d.ts +1 -1
- package/package.json +1 -1
package/dist/module.cjs
CHANGED
|
@@ -380,14 +380,46 @@ async function importExternalTemplate(projectPath, projectName, template) {
|
|
|
380
380
|
throw error;
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
|
|
383
|
+
async function resolveExtensionBinary() {
|
|
384
|
+
const developRoot = process.env.EXTENSION_CREATE_DEVELOP_ROOT;
|
|
385
|
+
if (developRoot) {
|
|
386
|
+
const localCliPath = external_path_namespaceObject.resolve(developRoot, '..', 'cli', 'dist', 'cli.cjs');
|
|
387
|
+
try {
|
|
388
|
+
await promises_namespaceObject.access(localCliPath);
|
|
389
|
+
return `node "${localCliPath}"`;
|
|
390
|
+
} catch {}
|
|
391
|
+
}
|
|
392
|
+
if ('development' === process.env.EXTENSION_ENV) return 'node node_modules/extension';
|
|
393
|
+
return 'extension';
|
|
394
|
+
}
|
|
395
|
+
function extensionJsPackageJsonScripts(extensionBinary) {
|
|
396
|
+
return {
|
|
397
|
+
dev: `${extensionBinary} dev`,
|
|
398
|
+
start: `${extensionBinary} start`,
|
|
399
|
+
build: `${extensionBinary} build`,
|
|
400
|
+
preview: `${extensionBinary} preview`,
|
|
401
|
+
'build:chrome': `${extensionBinary} build --browser chrome`,
|
|
402
|
+
'build:firefox': `${extensionBinary} build --browser firefox`,
|
|
403
|
+
'build:edge': `${extensionBinary} build --browser edge`
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
function getTemplateAwareScripts(template, extensionBinary) {
|
|
407
|
+
if (String(template).toLowerCase().includes('monorepo')) {
|
|
408
|
+
const target = 'packages/extension';
|
|
409
|
+
return {
|
|
410
|
+
dev: `${extensionBinary} dev ${target}`,
|
|
411
|
+
start: `${extensionBinary} start ${target}`,
|
|
412
|
+
build: `${extensionBinary} build ${target}`,
|
|
413
|
+
preview: `${extensionBinary} preview ${target}`,
|
|
414
|
+
'build:chrome': `${extensionBinary} build ${target} --browser chrome`,
|
|
415
|
+
'build:firefox': `${extensionBinary} build ${target} --browser firefox`,
|
|
416
|
+
'build:edge': `${extensionBinary} build ${target} --browser edge`
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
return extensionJsPackageJsonScripts(extensionBinary);
|
|
420
|
+
}
|
|
421
|
+
async function overridePackageJson(projectPath, projectName, { template, cliVersion }) {
|
|
422
|
+
const extensionBinary = await resolveExtensionBinary();
|
|
391
423
|
const candidatePath = external_path_namespaceObject.join(projectPath, 'package.json');
|
|
392
424
|
let packageJson = {};
|
|
393
425
|
try {
|
|
@@ -417,8 +449,8 @@ async function overridePackageJson(projectPath, projectName, { template: _templa
|
|
|
417
449
|
packageManager: packageManagerSpec
|
|
418
450
|
} : {},
|
|
419
451
|
scripts: {
|
|
420
|
-
...
|
|
421
|
-
...
|
|
452
|
+
...getTemplateAwareScripts(template, extensionBinary),
|
|
453
|
+
...packageJson.scripts
|
|
422
454
|
},
|
|
423
455
|
dependencies: packageJson.dependencies,
|
|
424
456
|
devDependencies: packageJson.devDependencies,
|
|
@@ -765,21 +797,24 @@ const globalLines = [
|
|
|
765
797
|
];
|
|
766
798
|
async function writeGitignore(projectPath) {
|
|
767
799
|
const gitIgnorePath = external_path_namespaceObject.join(projectPath, '.gitignore');
|
|
768
|
-
const
|
|
800
|
+
const paths = new Set();
|
|
801
|
+
let currentContents = '';
|
|
802
|
+
currentContents = await promises_namespaceObject.readFile(gitIgnorePath, 'utf8').catch((err)=>{
|
|
803
|
+
if ('ENOENT' === err.code) return '';
|
|
769
804
|
console.error(err);
|
|
770
805
|
throw err;
|
|
771
806
|
});
|
|
772
|
-
const
|
|
773
|
-
|
|
774
|
-
autoClose: false
|
|
775
|
-
})){
|
|
776
|
-
line = line.trim();
|
|
807
|
+
for (const rawLine of currentContents.split(/\r?\n/)){
|
|
808
|
+
const line = rawLine.trim();
|
|
777
809
|
if (0 !== line.length) paths.add(line);
|
|
778
810
|
}
|
|
779
811
|
const linesToAdd = globalLines.filter((line)=>!paths.has(line));
|
|
780
812
|
while('' === linesToAdd[linesToAdd.length - 1])linesToAdd.pop();
|
|
813
|
+
if (0 === linesToAdd.length) return;
|
|
781
814
|
console.log(writingGitIgnore());
|
|
782
|
-
|
|
815
|
+
const shouldPrefixWithNewline = currentContents.length > 0 && !currentContents.endsWith('\n');
|
|
816
|
+
const contentToAppend = `${shouldPrefixWithNewline ? '\n' : ''}${linesToAdd.join('\n')}`;
|
|
817
|
+
await promises_namespaceObject.appendFile(gitIgnorePath, contentToAppend).catch((err)=>{
|
|
783
818
|
console.error(err);
|
|
784
819
|
throw err;
|
|
785
820
|
});
|
|
@@ -2,5 +2,5 @@ interface OverridePackageJsonOptions {
|
|
|
2
2
|
template: string;
|
|
3
3
|
cliVersion?: string;
|
|
4
4
|
}
|
|
5
|
-
export declare function overridePackageJson(projectPath: string, projectName: string, { template
|
|
5
|
+
export declare function overridePackageJson(projectPath: string, projectName: string, { template, cliVersion }: OverridePackageJsonOptions): Promise<void>;
|
|
6
6
|
export {};
|
package/package.json
CHANGED