@create-node-app/core 0.2.4 → 0.2.5
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/index.d.ts +4 -6
- package/dist/index.js +105 -47
- package/dist/index.mjs +105 -47
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,14 +8,14 @@ declare const printEnvInfo: () => Promise<never>;
|
|
|
8
8
|
type CnaOptions = {
|
|
9
9
|
projectName: string;
|
|
10
10
|
info?: boolean;
|
|
11
|
-
alias?: string;
|
|
12
|
-
srcDir?: string;
|
|
13
11
|
interactive?: boolean;
|
|
14
12
|
verbose?: boolean;
|
|
15
|
-
|
|
13
|
+
packageManager?: string;
|
|
16
14
|
nodeps?: boolean;
|
|
17
15
|
template?: string;
|
|
18
16
|
templatesOrExtensions?: TemplateOrExtension[];
|
|
17
|
+
} & {
|
|
18
|
+
[key: string]: unknown;
|
|
19
19
|
};
|
|
20
20
|
type CnaOptionsTransform = (options: CnaOptions) => Promise<CnaOptions>;
|
|
21
21
|
/**
|
|
@@ -23,12 +23,10 @@ type CnaOptionsTransform = (options: CnaOptions) => Promise<CnaOptions>;
|
|
|
23
23
|
* @param programName - Name of the program to bootstrap the Node application
|
|
24
24
|
* @param options - CnaOptions to bootstrap the Node application
|
|
25
25
|
* @param options.info - Print environment debug info
|
|
26
|
-
* @param options.alias - Metadata to specify alias, usefull for backends using webpack
|
|
27
|
-
* @param options.srcDir - Metadata to specify where to put the source code
|
|
28
26
|
* @param options.interactive - Specify if it is needed to use interactive mode or not
|
|
29
27
|
* @param options.verbose - Specify if it is needed to use verbose mode or not
|
|
30
28
|
* @param options.projectName - Project's name
|
|
31
|
-
* @param options.
|
|
29
|
+
* @param options.packageManager - Package manager to use
|
|
32
30
|
* @param options.nodeps - Generate package.json file without installing dependencies
|
|
33
31
|
* @param options.template - Template to bootstrap the aplication
|
|
34
32
|
* @param options.extend - Extensions to apply for the boilerplate generation
|
package/dist/index.js
CHANGED
|
@@ -78,6 +78,20 @@ var shouldUseYarn = () => {
|
|
|
78
78
|
}
|
|
79
79
|
return true;
|
|
80
80
|
};
|
|
81
|
+
var shouldUsePnpm = () => {
|
|
82
|
+
const { hasMinPnpm, pnpmVersion } = checkPnpmVersion();
|
|
83
|
+
if (!hasMinPnpm) {
|
|
84
|
+
console.log(
|
|
85
|
+
import_chalk.default.yellow(
|
|
86
|
+
`You are using pnpm version ${import_chalk.default.bold(
|
|
87
|
+
pnpmVersion
|
|
88
|
+
)} which is not supported yet. To use pnpm, install v5.0.0 or higher. See https://pnpm.js.org for instructions on how to update.`
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
};
|
|
81
95
|
var checkThatNpmCanReadCwd = () => {
|
|
82
96
|
const cwd = process.cwd();
|
|
83
97
|
let childOutput = null;
|
|
@@ -130,6 +144,24 @@ This is probably caused by a misconfigured system terminal shell.`
|
|
|
130
144
|
}
|
|
131
145
|
return false;
|
|
132
146
|
};
|
|
147
|
+
var checkPnpmVersion = () => {
|
|
148
|
+
const minPnpm = "5.0.0";
|
|
149
|
+
let hasMinPnpm = false;
|
|
150
|
+
let pnpmVersion = null;
|
|
151
|
+
try {
|
|
152
|
+
pnpmVersion = (0, import_child_process.execSync)("pnpm --version").toString().trim();
|
|
153
|
+
if (import_semver.default.valid(pnpmVersion)) {
|
|
154
|
+
hasMinPnpm = import_semver.default.gte(pnpmVersion, minPnpm);
|
|
155
|
+
} else {
|
|
156
|
+
const trimmedPnpmVersionMatch = /^(.+?)[-+].+$/.exec(pnpmVersion);
|
|
157
|
+
if (trimmedPnpmVersionMatch) {
|
|
158
|
+
hasMinPnpm = import_semver.default.gte(trimmedPnpmVersionMatch[1], minPnpm);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
} catch (e) {
|
|
162
|
+
}
|
|
163
|
+
return { hasMinPnpm, pnpmVersion };
|
|
164
|
+
};
|
|
133
165
|
var checkYarnVersion = () => {
|
|
134
166
|
const minYarnPnp = "1.12.0";
|
|
135
167
|
const maxYarnPnp = "2.0.0";
|
|
@@ -505,12 +537,12 @@ var templateLoader = ({
|
|
|
505
537
|
root,
|
|
506
538
|
templateDir,
|
|
507
539
|
appName,
|
|
508
|
-
alias,
|
|
509
540
|
verbose,
|
|
510
541
|
mode = "",
|
|
511
542
|
srcDir,
|
|
512
543
|
runCommand,
|
|
513
|
-
installCommand
|
|
544
|
+
installCommand,
|
|
545
|
+
...customOptions
|
|
514
546
|
}) => async ({ path: path4 }) => {
|
|
515
547
|
const flag = mode.includes("append") ? "a+" : "w";
|
|
516
548
|
const file = import_fs4.default.readFileSync(`${templateDir}/${path4}`, "utf8");
|
|
@@ -519,13 +551,11 @@ var templateLoader = ({
|
|
|
519
551
|
return writeFile(
|
|
520
552
|
`${root}/${newPath}`,
|
|
521
553
|
newFile({
|
|
522
|
-
project: alias,
|
|
523
|
-
projectImport: alias,
|
|
524
|
-
projectImportPath: alias === "" ? "" : `${alias}/`,
|
|
525
554
|
projectName: appName,
|
|
526
555
|
srcDir: srcDir || ".",
|
|
527
556
|
runCommand,
|
|
528
|
-
installCommand
|
|
557
|
+
installCommand,
|
|
558
|
+
...customOptions
|
|
529
559
|
}),
|
|
530
560
|
flag,
|
|
531
561
|
verbose
|
|
@@ -536,11 +566,11 @@ var fileLoader = ({
|
|
|
536
566
|
templateDir,
|
|
537
567
|
appName,
|
|
538
568
|
originalDirectory,
|
|
539
|
-
alias,
|
|
540
569
|
verbose,
|
|
541
570
|
srcDir = DEFAULT_SRC_PATH,
|
|
542
571
|
runCommand,
|
|
543
|
-
installCommand
|
|
572
|
+
installCommand,
|
|
573
|
+
...customOptions
|
|
544
574
|
}) => ({ path: path4 }) => {
|
|
545
575
|
const mode = getModeFromPath(path4);
|
|
546
576
|
const loaders = {
|
|
@@ -554,12 +584,12 @@ var fileLoader = ({
|
|
|
554
584
|
templateDir,
|
|
555
585
|
appName,
|
|
556
586
|
originalDirectory,
|
|
557
|
-
alias,
|
|
558
587
|
verbose,
|
|
559
588
|
mode,
|
|
560
589
|
srcDir,
|
|
561
590
|
runCommand,
|
|
562
|
-
installCommand
|
|
591
|
+
installCommand,
|
|
592
|
+
...customOptions
|
|
563
593
|
})({
|
|
564
594
|
path: path4
|
|
565
595
|
});
|
|
@@ -569,11 +599,11 @@ var loadFiles = async ({
|
|
|
569
599
|
templatesOrExtensions = [],
|
|
570
600
|
appName,
|
|
571
601
|
originalDirectory,
|
|
572
|
-
alias,
|
|
573
602
|
verbose,
|
|
574
603
|
srcDir = DEFAULT_SRC_PATH,
|
|
575
604
|
runCommand,
|
|
576
|
-
installCommand
|
|
605
|
+
installCommand,
|
|
606
|
+
...customOptions
|
|
577
607
|
}) => {
|
|
578
608
|
for await (const { url: templateOrExtensionUrl } of templatesOrExtensions) {
|
|
579
609
|
const templateDir = await getTemplateDirPath(templateOrExtensionUrl);
|
|
@@ -597,11 +627,11 @@ var loadFiles = async ({
|
|
|
597
627
|
templateDir,
|
|
598
628
|
appName,
|
|
599
629
|
originalDirectory,
|
|
600
|
-
alias,
|
|
601
630
|
verbose,
|
|
602
631
|
srcDir,
|
|
603
632
|
runCommand,
|
|
604
|
-
installCommand
|
|
633
|
+
installCommand,
|
|
634
|
+
...customOptions
|
|
605
635
|
})(entry);
|
|
606
636
|
} catch (err) {
|
|
607
637
|
if (verbose) {
|
|
@@ -614,7 +644,7 @@ var loadFiles = async ({
|
|
|
614
644
|
};
|
|
615
645
|
|
|
616
646
|
// installer.ts
|
|
617
|
-
var install = (root, useYarn = false, dependencies = [], verbose = false, isOnline = true, isDevDependencies = false) => {
|
|
647
|
+
var install = (root, useYarn = false, usePnpm = false, dependencies = [], verbose = false, isOnline = true, isDevDependencies = false) => {
|
|
618
648
|
return new Promise((resolve, reject) => {
|
|
619
649
|
let command;
|
|
620
650
|
let args;
|
|
@@ -635,6 +665,15 @@ var install = (root, useYarn = false, dependencies = [], verbose = false, isOnli
|
|
|
635
665
|
console.log(import_chalk3.default.yellow("Falling back to the local Yarn cache."));
|
|
636
666
|
console.log();
|
|
637
667
|
}
|
|
668
|
+
} else if (usePnpm) {
|
|
669
|
+
command = "pnpm";
|
|
670
|
+
args = ["add", "--save"];
|
|
671
|
+
if (isDevDependencies) {
|
|
672
|
+
args.push("--save-dev");
|
|
673
|
+
}
|
|
674
|
+
args.push(...dependencies);
|
|
675
|
+
args.push("--cwd");
|
|
676
|
+
args.push(root);
|
|
638
677
|
} else {
|
|
639
678
|
command = "npm";
|
|
640
679
|
args = ["install", "--loglevel", "error"];
|
|
@@ -664,7 +703,6 @@ var runCommandInProjectDir = (root, command, args = [], successMessage = "Operat
|
|
|
664
703
|
child.on("close", (code) => {
|
|
665
704
|
if (code !== 0) {
|
|
666
705
|
console.log(import_chalk3.default.red(errorMessage));
|
|
667
|
-
reject(new Error(`${command} ${args.join(" ")}`));
|
|
668
706
|
return;
|
|
669
707
|
}
|
|
670
708
|
console.log(import_chalk3.default.green(successMessage));
|
|
@@ -678,14 +716,14 @@ var run = async ({
|
|
|
678
716
|
originalDirectory,
|
|
679
717
|
verbose = false,
|
|
680
718
|
useYarn = false,
|
|
719
|
+
usePnpm = false,
|
|
681
720
|
templatesOrExtensions = [],
|
|
682
721
|
dependencies = [],
|
|
683
722
|
devDependencies = [],
|
|
684
|
-
alias = "",
|
|
685
723
|
installDependencies = true,
|
|
686
|
-
srcDir = "",
|
|
687
724
|
runCommand = "",
|
|
688
|
-
installCommand = ""
|
|
725
|
+
installCommand = "",
|
|
726
|
+
...customOptions
|
|
689
727
|
}) => {
|
|
690
728
|
let isOnline = true;
|
|
691
729
|
if (useYarn) {
|
|
@@ -701,33 +739,52 @@ var run = async ({
|
|
|
701
739
|
console.log();
|
|
702
740
|
process.exit(0);
|
|
703
741
|
}
|
|
742
|
+
console.log();
|
|
743
|
+
console.log("Scaffolding project in " + root + "...");
|
|
704
744
|
await loadFiles({
|
|
705
745
|
root,
|
|
706
746
|
templatesOrExtensions,
|
|
707
747
|
appName,
|
|
708
748
|
originalDirectory,
|
|
709
|
-
alias,
|
|
710
749
|
verbose,
|
|
711
|
-
srcDir,
|
|
712
750
|
runCommand,
|
|
713
|
-
installCommand
|
|
751
|
+
installCommand,
|
|
752
|
+
...customOptions
|
|
714
753
|
});
|
|
754
|
+
console.log();
|
|
755
|
+
console.log(import_chalk3.default.green("Successfully scaffolded project."));
|
|
756
|
+
console.log();
|
|
715
757
|
if (installDependencies) {
|
|
716
758
|
console.log(
|
|
717
759
|
import_chalk3.default.green("Installing packages. This might take a couple of minutes.")
|
|
718
760
|
);
|
|
719
761
|
console.log(import_chalk3.default.green("Installing dependencies..."));
|
|
720
762
|
console.log();
|
|
721
|
-
await install(
|
|
763
|
+
await install(
|
|
764
|
+
root,
|
|
765
|
+
useYarn,
|
|
766
|
+
usePnpm,
|
|
767
|
+
dependencies,
|
|
768
|
+
verbose,
|
|
769
|
+
isOnline,
|
|
770
|
+
false
|
|
771
|
+
);
|
|
722
772
|
if (devDependencies.length > 0) {
|
|
723
773
|
console.log();
|
|
724
774
|
console.log(import_chalk3.default.green("Installing devDependencies..."));
|
|
725
775
|
console.log();
|
|
726
|
-
await install(
|
|
776
|
+
await install(
|
|
777
|
+
root,
|
|
778
|
+
useYarn,
|
|
779
|
+
usePnpm,
|
|
780
|
+
devDependencies,
|
|
781
|
+
verbose,
|
|
782
|
+
isOnline,
|
|
783
|
+
true
|
|
784
|
+
);
|
|
727
785
|
}
|
|
728
786
|
} else {
|
|
729
787
|
console.log(import_chalk3.default.yellow("Skip package installation."));
|
|
730
|
-
console.log(import_chalk3.default.yellow("Run npm install/yarn in your project."));
|
|
731
788
|
const packageJson = JSON.parse(
|
|
732
789
|
import_fs5.default.readFileSync(`${root}/package.json`, "utf8")
|
|
733
790
|
);
|
|
@@ -755,17 +812,19 @@ var run = async ({
|
|
|
755
812
|
import_path4.default.join(root, "package.json"),
|
|
756
813
|
JSON.stringify(packageJson, null, 2) + import_os3.default.EOL
|
|
757
814
|
);
|
|
815
|
+
console.log();
|
|
816
|
+
console.log(import_chalk3.default.green("Successfully updated package.json."));
|
|
817
|
+
console.log(import_chalk3.default.yellow(`Run ${import_chalk3.default.cyan(installCommand)} to install.`));
|
|
758
818
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
});
|
|
819
|
+
console.log();
|
|
820
|
+
console.log("Initializing git repository...");
|
|
821
|
+
await runCommandInProjectDir(
|
|
822
|
+
root,
|
|
823
|
+
"git",
|
|
824
|
+
["init"],
|
|
825
|
+
"Successfully initialized git repository.",
|
|
826
|
+
"Failed to initialize git repository."
|
|
827
|
+
);
|
|
769
828
|
if (installDependencies && isOnline) {
|
|
770
829
|
const packageJson = JSON.parse(
|
|
771
830
|
import_fs5.default.readFileSync(`${root}/package.json`, "utf8")
|
|
@@ -792,12 +851,10 @@ var run = async ({
|
|
|
792
851
|
var createApp = async ({
|
|
793
852
|
name,
|
|
794
853
|
verbose = false,
|
|
795
|
-
useNpm = false,
|
|
796
854
|
templatesOrExtensions = [],
|
|
797
|
-
alias = "",
|
|
798
855
|
installDependencies = true,
|
|
799
856
|
ignorePackage = false,
|
|
800
|
-
|
|
857
|
+
...customOptions
|
|
801
858
|
}) => {
|
|
802
859
|
const root = import_path4.default.resolve(name);
|
|
803
860
|
const appName = import_path4.default.basename(root);
|
|
@@ -806,14 +863,15 @@ var createApp = async ({
|
|
|
806
863
|
});
|
|
807
864
|
console.log(`Creating a new Node app in ${import_chalk3.default.green(root)}.`);
|
|
808
865
|
console.log();
|
|
809
|
-
const useYarn =
|
|
810
|
-
const
|
|
866
|
+
const useYarn = customOptions.packageManager === "yarn" && shouldUseYarn();
|
|
867
|
+
const usePnpm = customOptions.packageManager === "pnpm" && shouldUsePnpm();
|
|
868
|
+
const runCommand = useYarn ? "yarn" : "npm run";
|
|
869
|
+
const installCommand = useYarn ? "yarn" : usePnpm ? "pnpm install" : "npm install";
|
|
811
870
|
const { packageJson, dependencies, devDependencies } = await loadPackages({
|
|
812
871
|
templatesOrExtensions,
|
|
813
872
|
appName,
|
|
814
|
-
|
|
815
|
-
ignorePackage
|
|
816
|
-
srcDir
|
|
873
|
+
runCommand,
|
|
874
|
+
ignorePackage
|
|
817
875
|
});
|
|
818
876
|
import_fs5.default.writeFileSync(
|
|
819
877
|
import_path4.default.join(root, "package.json"),
|
|
@@ -869,14 +927,14 @@ Please update to npm 3 or higher for a better, fully supported experience.
|
|
|
869
927
|
originalDirectory,
|
|
870
928
|
verbose,
|
|
871
929
|
useYarn,
|
|
930
|
+
usePnpm,
|
|
872
931
|
templatesOrExtensions,
|
|
873
932
|
dependencies,
|
|
874
933
|
devDependencies,
|
|
875
|
-
alias,
|
|
876
934
|
installDependencies,
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
935
|
+
runCommand,
|
|
936
|
+
installCommand,
|
|
937
|
+
...customOptions
|
|
880
938
|
});
|
|
881
939
|
};
|
|
882
940
|
|
package/dist/index.mjs
CHANGED
|
@@ -50,6 +50,20 @@ var shouldUseYarn = () => {
|
|
|
50
50
|
}
|
|
51
51
|
return true;
|
|
52
52
|
};
|
|
53
|
+
var shouldUsePnpm = () => {
|
|
54
|
+
const { hasMinPnpm, pnpmVersion } = checkPnpmVersion();
|
|
55
|
+
if (!hasMinPnpm) {
|
|
56
|
+
console.log(
|
|
57
|
+
chalk.yellow(
|
|
58
|
+
`You are using pnpm version ${chalk.bold(
|
|
59
|
+
pnpmVersion
|
|
60
|
+
)} which is not supported yet. To use pnpm, install v5.0.0 or higher. See https://pnpm.js.org for instructions on how to update.`
|
|
61
|
+
)
|
|
62
|
+
);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
};
|
|
53
67
|
var checkThatNpmCanReadCwd = () => {
|
|
54
68
|
const cwd = process.cwd();
|
|
55
69
|
let childOutput = null;
|
|
@@ -102,6 +116,24 @@ This is probably caused by a misconfigured system terminal shell.`
|
|
|
102
116
|
}
|
|
103
117
|
return false;
|
|
104
118
|
};
|
|
119
|
+
var checkPnpmVersion = () => {
|
|
120
|
+
const minPnpm = "5.0.0";
|
|
121
|
+
let hasMinPnpm = false;
|
|
122
|
+
let pnpmVersion = null;
|
|
123
|
+
try {
|
|
124
|
+
pnpmVersion = execSync("pnpm --version").toString().trim();
|
|
125
|
+
if (semver.valid(pnpmVersion)) {
|
|
126
|
+
hasMinPnpm = semver.gte(pnpmVersion, minPnpm);
|
|
127
|
+
} else {
|
|
128
|
+
const trimmedPnpmVersionMatch = /^(.+?)[-+].+$/.exec(pnpmVersion);
|
|
129
|
+
if (trimmedPnpmVersionMatch) {
|
|
130
|
+
hasMinPnpm = semver.gte(trimmedPnpmVersionMatch[1], minPnpm);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
} catch (e) {
|
|
134
|
+
}
|
|
135
|
+
return { hasMinPnpm, pnpmVersion };
|
|
136
|
+
};
|
|
105
137
|
var checkYarnVersion = () => {
|
|
106
138
|
const minYarnPnp = "1.12.0";
|
|
107
139
|
const maxYarnPnp = "2.0.0";
|
|
@@ -477,12 +509,12 @@ var templateLoader = ({
|
|
|
477
509
|
root,
|
|
478
510
|
templateDir,
|
|
479
511
|
appName,
|
|
480
|
-
alias,
|
|
481
512
|
verbose,
|
|
482
513
|
mode = "",
|
|
483
514
|
srcDir,
|
|
484
515
|
runCommand,
|
|
485
|
-
installCommand
|
|
516
|
+
installCommand,
|
|
517
|
+
...customOptions
|
|
486
518
|
}) => async ({ path: path4 }) => {
|
|
487
519
|
const flag = mode.includes("append") ? "a+" : "w";
|
|
488
520
|
const file = fs3.readFileSync(`${templateDir}/${path4}`, "utf8");
|
|
@@ -491,13 +523,11 @@ var templateLoader = ({
|
|
|
491
523
|
return writeFile(
|
|
492
524
|
`${root}/${newPath}`,
|
|
493
525
|
newFile({
|
|
494
|
-
project: alias,
|
|
495
|
-
projectImport: alias,
|
|
496
|
-
projectImportPath: alias === "" ? "" : `${alias}/`,
|
|
497
526
|
projectName: appName,
|
|
498
527
|
srcDir: srcDir || ".",
|
|
499
528
|
runCommand,
|
|
500
|
-
installCommand
|
|
529
|
+
installCommand,
|
|
530
|
+
...customOptions
|
|
501
531
|
}),
|
|
502
532
|
flag,
|
|
503
533
|
verbose
|
|
@@ -508,11 +538,11 @@ var fileLoader = ({
|
|
|
508
538
|
templateDir,
|
|
509
539
|
appName,
|
|
510
540
|
originalDirectory,
|
|
511
|
-
alias,
|
|
512
541
|
verbose,
|
|
513
542
|
srcDir = DEFAULT_SRC_PATH,
|
|
514
543
|
runCommand,
|
|
515
|
-
installCommand
|
|
544
|
+
installCommand,
|
|
545
|
+
...customOptions
|
|
516
546
|
}) => ({ path: path4 }) => {
|
|
517
547
|
const mode = getModeFromPath(path4);
|
|
518
548
|
const loaders = {
|
|
@@ -526,12 +556,12 @@ var fileLoader = ({
|
|
|
526
556
|
templateDir,
|
|
527
557
|
appName,
|
|
528
558
|
originalDirectory,
|
|
529
|
-
alias,
|
|
530
559
|
verbose,
|
|
531
560
|
mode,
|
|
532
561
|
srcDir,
|
|
533
562
|
runCommand,
|
|
534
|
-
installCommand
|
|
563
|
+
installCommand,
|
|
564
|
+
...customOptions
|
|
535
565
|
})({
|
|
536
566
|
path: path4
|
|
537
567
|
});
|
|
@@ -541,11 +571,11 @@ var loadFiles = async ({
|
|
|
541
571
|
templatesOrExtensions = [],
|
|
542
572
|
appName,
|
|
543
573
|
originalDirectory,
|
|
544
|
-
alias,
|
|
545
574
|
verbose,
|
|
546
575
|
srcDir = DEFAULT_SRC_PATH,
|
|
547
576
|
runCommand,
|
|
548
|
-
installCommand
|
|
577
|
+
installCommand,
|
|
578
|
+
...customOptions
|
|
549
579
|
}) => {
|
|
550
580
|
for await (const { url: templateOrExtensionUrl } of templatesOrExtensions) {
|
|
551
581
|
const templateDir = await getTemplateDirPath(templateOrExtensionUrl);
|
|
@@ -569,11 +599,11 @@ var loadFiles = async ({
|
|
|
569
599
|
templateDir,
|
|
570
600
|
appName,
|
|
571
601
|
originalDirectory,
|
|
572
|
-
alias,
|
|
573
602
|
verbose,
|
|
574
603
|
srcDir,
|
|
575
604
|
runCommand,
|
|
576
|
-
installCommand
|
|
605
|
+
installCommand,
|
|
606
|
+
...customOptions
|
|
577
607
|
})(entry);
|
|
578
608
|
} catch (err) {
|
|
579
609
|
if (verbose) {
|
|
@@ -586,7 +616,7 @@ var loadFiles = async ({
|
|
|
586
616
|
};
|
|
587
617
|
|
|
588
618
|
// installer.ts
|
|
589
|
-
var install = (root, useYarn = false, dependencies = [], verbose = false, isOnline = true, isDevDependencies = false) => {
|
|
619
|
+
var install = (root, useYarn = false, usePnpm = false, dependencies = [], verbose = false, isOnline = true, isDevDependencies = false) => {
|
|
590
620
|
return new Promise((resolve, reject) => {
|
|
591
621
|
let command;
|
|
592
622
|
let args;
|
|
@@ -607,6 +637,15 @@ var install = (root, useYarn = false, dependencies = [], verbose = false, isOnli
|
|
|
607
637
|
console.log(chalk3.yellow("Falling back to the local Yarn cache."));
|
|
608
638
|
console.log();
|
|
609
639
|
}
|
|
640
|
+
} else if (usePnpm) {
|
|
641
|
+
command = "pnpm";
|
|
642
|
+
args = ["add", "--save"];
|
|
643
|
+
if (isDevDependencies) {
|
|
644
|
+
args.push("--save-dev");
|
|
645
|
+
}
|
|
646
|
+
args.push(...dependencies);
|
|
647
|
+
args.push("--cwd");
|
|
648
|
+
args.push(root);
|
|
610
649
|
} else {
|
|
611
650
|
command = "npm";
|
|
612
651
|
args = ["install", "--loglevel", "error"];
|
|
@@ -636,7 +675,6 @@ var runCommandInProjectDir = (root, command, args = [], successMessage = "Operat
|
|
|
636
675
|
child.on("close", (code) => {
|
|
637
676
|
if (code !== 0) {
|
|
638
677
|
console.log(chalk3.red(errorMessage));
|
|
639
|
-
reject(new Error(`${command} ${args.join(" ")}`));
|
|
640
678
|
return;
|
|
641
679
|
}
|
|
642
680
|
console.log(chalk3.green(successMessage));
|
|
@@ -650,14 +688,14 @@ var run = async ({
|
|
|
650
688
|
originalDirectory,
|
|
651
689
|
verbose = false,
|
|
652
690
|
useYarn = false,
|
|
691
|
+
usePnpm = false,
|
|
653
692
|
templatesOrExtensions = [],
|
|
654
693
|
dependencies = [],
|
|
655
694
|
devDependencies = [],
|
|
656
|
-
alias = "",
|
|
657
695
|
installDependencies = true,
|
|
658
|
-
srcDir = "",
|
|
659
696
|
runCommand = "",
|
|
660
|
-
installCommand = ""
|
|
697
|
+
installCommand = "",
|
|
698
|
+
...customOptions
|
|
661
699
|
}) => {
|
|
662
700
|
let isOnline = true;
|
|
663
701
|
if (useYarn) {
|
|
@@ -673,33 +711,52 @@ var run = async ({
|
|
|
673
711
|
console.log();
|
|
674
712
|
process.exit(0);
|
|
675
713
|
}
|
|
714
|
+
console.log();
|
|
715
|
+
console.log("Scaffolding project in " + root + "...");
|
|
676
716
|
await loadFiles({
|
|
677
717
|
root,
|
|
678
718
|
templatesOrExtensions,
|
|
679
719
|
appName,
|
|
680
720
|
originalDirectory,
|
|
681
|
-
alias,
|
|
682
721
|
verbose,
|
|
683
|
-
srcDir,
|
|
684
722
|
runCommand,
|
|
685
|
-
installCommand
|
|
723
|
+
installCommand,
|
|
724
|
+
...customOptions
|
|
686
725
|
});
|
|
726
|
+
console.log();
|
|
727
|
+
console.log(chalk3.green("Successfully scaffolded project."));
|
|
728
|
+
console.log();
|
|
687
729
|
if (installDependencies) {
|
|
688
730
|
console.log(
|
|
689
731
|
chalk3.green("Installing packages. This might take a couple of minutes.")
|
|
690
732
|
);
|
|
691
733
|
console.log(chalk3.green("Installing dependencies..."));
|
|
692
734
|
console.log();
|
|
693
|
-
await install(
|
|
735
|
+
await install(
|
|
736
|
+
root,
|
|
737
|
+
useYarn,
|
|
738
|
+
usePnpm,
|
|
739
|
+
dependencies,
|
|
740
|
+
verbose,
|
|
741
|
+
isOnline,
|
|
742
|
+
false
|
|
743
|
+
);
|
|
694
744
|
if (devDependencies.length > 0) {
|
|
695
745
|
console.log();
|
|
696
746
|
console.log(chalk3.green("Installing devDependencies..."));
|
|
697
747
|
console.log();
|
|
698
|
-
await install(
|
|
748
|
+
await install(
|
|
749
|
+
root,
|
|
750
|
+
useYarn,
|
|
751
|
+
usePnpm,
|
|
752
|
+
devDependencies,
|
|
753
|
+
verbose,
|
|
754
|
+
isOnline,
|
|
755
|
+
true
|
|
756
|
+
);
|
|
699
757
|
}
|
|
700
758
|
} else {
|
|
701
759
|
console.log(chalk3.yellow("Skip package installation."));
|
|
702
|
-
console.log(chalk3.yellow("Run npm install/yarn in your project."));
|
|
703
760
|
const packageJson = JSON.parse(
|
|
704
761
|
fs4.readFileSync(`${root}/package.json`, "utf8")
|
|
705
762
|
);
|
|
@@ -727,17 +784,19 @@ var run = async ({
|
|
|
727
784
|
path3.join(root, "package.json"),
|
|
728
785
|
JSON.stringify(packageJson, null, 2) + os3.EOL
|
|
729
786
|
);
|
|
787
|
+
console.log();
|
|
788
|
+
console.log(chalk3.green("Successfully updated package.json."));
|
|
789
|
+
console.log(chalk3.yellow(`Run ${chalk3.cyan(installCommand)} to install.`));
|
|
730
790
|
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
});
|
|
791
|
+
console.log();
|
|
792
|
+
console.log("Initializing git repository...");
|
|
793
|
+
await runCommandInProjectDir(
|
|
794
|
+
root,
|
|
795
|
+
"git",
|
|
796
|
+
["init"],
|
|
797
|
+
"Successfully initialized git repository.",
|
|
798
|
+
"Failed to initialize git repository."
|
|
799
|
+
);
|
|
741
800
|
if (installDependencies && isOnline) {
|
|
742
801
|
const packageJson = JSON.parse(
|
|
743
802
|
fs4.readFileSync(`${root}/package.json`, "utf8")
|
|
@@ -764,12 +823,10 @@ var run = async ({
|
|
|
764
823
|
var createApp = async ({
|
|
765
824
|
name,
|
|
766
825
|
verbose = false,
|
|
767
|
-
useNpm = false,
|
|
768
826
|
templatesOrExtensions = [],
|
|
769
|
-
alias = "",
|
|
770
827
|
installDependencies = true,
|
|
771
828
|
ignorePackage = false,
|
|
772
|
-
|
|
829
|
+
...customOptions
|
|
773
830
|
}) => {
|
|
774
831
|
const root = path3.resolve(name);
|
|
775
832
|
const appName = path3.basename(root);
|
|
@@ -778,14 +835,15 @@ var createApp = async ({
|
|
|
778
835
|
});
|
|
779
836
|
console.log(`Creating a new Node app in ${chalk3.green(root)}.`);
|
|
780
837
|
console.log();
|
|
781
|
-
const useYarn =
|
|
782
|
-
const
|
|
838
|
+
const useYarn = customOptions.packageManager === "yarn" && shouldUseYarn();
|
|
839
|
+
const usePnpm = customOptions.packageManager === "pnpm" && shouldUsePnpm();
|
|
840
|
+
const runCommand = useYarn ? "yarn" : "npm run";
|
|
841
|
+
const installCommand = useYarn ? "yarn" : usePnpm ? "pnpm install" : "npm install";
|
|
783
842
|
const { packageJson, dependencies, devDependencies } = await loadPackages({
|
|
784
843
|
templatesOrExtensions,
|
|
785
844
|
appName,
|
|
786
|
-
|
|
787
|
-
ignorePackage
|
|
788
|
-
srcDir
|
|
845
|
+
runCommand,
|
|
846
|
+
ignorePackage
|
|
789
847
|
});
|
|
790
848
|
fs4.writeFileSync(
|
|
791
849
|
path3.join(root, "package.json"),
|
|
@@ -841,14 +899,14 @@ Please update to npm 3 or higher for a better, fully supported experience.
|
|
|
841
899
|
originalDirectory,
|
|
842
900
|
verbose,
|
|
843
901
|
useYarn,
|
|
902
|
+
usePnpm,
|
|
844
903
|
templatesOrExtensions,
|
|
845
904
|
dependencies,
|
|
846
905
|
devDependencies,
|
|
847
|
-
alias,
|
|
848
906
|
installDependencies,
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
907
|
+
runCommand,
|
|
908
|
+
installCommand,
|
|
909
|
+
...customOptions
|
|
852
910
|
});
|
|
853
911
|
};
|
|
854
912
|
|