@create-node-app/core 0.2.4 → 0.2.6
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 +115 -55
- package/dist/index.mjs +115 -55
- 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";
|
|
@@ -229,6 +261,7 @@ var clone = (git, target, branch) => {
|
|
|
229
261
|
var pull = async (cwd) => {
|
|
230
262
|
await exec("git checkout -f", { cwd });
|
|
231
263
|
await exec("git pull", { cwd });
|
|
264
|
+
await new Promise((resolve) => setTimeout(resolve, 400));
|
|
232
265
|
};
|
|
233
266
|
var downloadRepository = async ({
|
|
234
267
|
url = "",
|
|
@@ -258,13 +291,11 @@ var downloadRepository = async ({
|
|
|
258
291
|
return;
|
|
259
292
|
}
|
|
260
293
|
await pull(cacheDir);
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
});
|
|
267
|
-
}, 400);
|
|
294
|
+
import_fs.default.cpSync(cacheDir, absoluteTarget, {
|
|
295
|
+
force: true,
|
|
296
|
+
filter: filterGit,
|
|
297
|
+
recursive: true
|
|
298
|
+
});
|
|
268
299
|
};
|
|
269
300
|
|
|
270
301
|
// paths.ts
|
|
@@ -425,7 +456,10 @@ var loadPackages = async ({
|
|
|
425
456
|
scripts: {}
|
|
426
457
|
})
|
|
427
458
|
);
|
|
428
|
-
return getInstallableSetup(
|
|
459
|
+
return getInstallableSetup({
|
|
460
|
+
...setup,
|
|
461
|
+
name: config.appName
|
|
462
|
+
});
|
|
429
463
|
};
|
|
430
464
|
|
|
431
465
|
// loaders.ts
|
|
@@ -505,12 +539,12 @@ var templateLoader = ({
|
|
|
505
539
|
root,
|
|
506
540
|
templateDir,
|
|
507
541
|
appName,
|
|
508
|
-
alias,
|
|
509
542
|
verbose,
|
|
510
543
|
mode = "",
|
|
511
544
|
srcDir,
|
|
512
545
|
runCommand,
|
|
513
|
-
installCommand
|
|
546
|
+
installCommand,
|
|
547
|
+
...customOptions
|
|
514
548
|
}) => async ({ path: path4 }) => {
|
|
515
549
|
const flag = mode.includes("append") ? "a+" : "w";
|
|
516
550
|
const file = import_fs4.default.readFileSync(`${templateDir}/${path4}`, "utf8");
|
|
@@ -519,13 +553,11 @@ var templateLoader = ({
|
|
|
519
553
|
return writeFile(
|
|
520
554
|
`${root}/${newPath}`,
|
|
521
555
|
newFile({
|
|
522
|
-
project: alias,
|
|
523
|
-
projectImport: alias,
|
|
524
|
-
projectImportPath: alias === "" ? "" : `${alias}/`,
|
|
525
556
|
projectName: appName,
|
|
526
557
|
srcDir: srcDir || ".",
|
|
527
558
|
runCommand,
|
|
528
|
-
installCommand
|
|
559
|
+
installCommand,
|
|
560
|
+
...customOptions
|
|
529
561
|
}),
|
|
530
562
|
flag,
|
|
531
563
|
verbose
|
|
@@ -536,11 +568,11 @@ var fileLoader = ({
|
|
|
536
568
|
templateDir,
|
|
537
569
|
appName,
|
|
538
570
|
originalDirectory,
|
|
539
|
-
alias,
|
|
540
571
|
verbose,
|
|
541
572
|
srcDir = DEFAULT_SRC_PATH,
|
|
542
573
|
runCommand,
|
|
543
|
-
installCommand
|
|
574
|
+
installCommand,
|
|
575
|
+
...customOptions
|
|
544
576
|
}) => ({ path: path4 }) => {
|
|
545
577
|
const mode = getModeFromPath(path4);
|
|
546
578
|
const loaders = {
|
|
@@ -554,12 +586,12 @@ var fileLoader = ({
|
|
|
554
586
|
templateDir,
|
|
555
587
|
appName,
|
|
556
588
|
originalDirectory,
|
|
557
|
-
alias,
|
|
558
589
|
verbose,
|
|
559
590
|
mode,
|
|
560
591
|
srcDir,
|
|
561
592
|
runCommand,
|
|
562
|
-
installCommand
|
|
593
|
+
installCommand,
|
|
594
|
+
...customOptions
|
|
563
595
|
})({
|
|
564
596
|
path: path4
|
|
565
597
|
});
|
|
@@ -569,11 +601,11 @@ var loadFiles = async ({
|
|
|
569
601
|
templatesOrExtensions = [],
|
|
570
602
|
appName,
|
|
571
603
|
originalDirectory,
|
|
572
|
-
alias,
|
|
573
604
|
verbose,
|
|
574
605
|
srcDir = DEFAULT_SRC_PATH,
|
|
575
606
|
runCommand,
|
|
576
|
-
installCommand
|
|
607
|
+
installCommand,
|
|
608
|
+
...customOptions
|
|
577
609
|
}) => {
|
|
578
610
|
for await (const { url: templateOrExtensionUrl } of templatesOrExtensions) {
|
|
579
611
|
const templateDir = await getTemplateDirPath(templateOrExtensionUrl);
|
|
@@ -597,11 +629,11 @@ var loadFiles = async ({
|
|
|
597
629
|
templateDir,
|
|
598
630
|
appName,
|
|
599
631
|
originalDirectory,
|
|
600
|
-
alias,
|
|
601
632
|
verbose,
|
|
602
633
|
srcDir,
|
|
603
634
|
runCommand,
|
|
604
|
-
installCommand
|
|
635
|
+
installCommand,
|
|
636
|
+
...customOptions
|
|
605
637
|
})(entry);
|
|
606
638
|
} catch (err) {
|
|
607
639
|
if (verbose) {
|
|
@@ -614,7 +646,7 @@ var loadFiles = async ({
|
|
|
614
646
|
};
|
|
615
647
|
|
|
616
648
|
// installer.ts
|
|
617
|
-
var install = (root, useYarn = false, dependencies = [], verbose = false, isOnline = true, isDevDependencies = false) => {
|
|
649
|
+
var install = (root, useYarn = false, usePnpm = false, dependencies = [], verbose = false, isOnline = true, isDevDependencies = false) => {
|
|
618
650
|
return new Promise((resolve, reject) => {
|
|
619
651
|
let command;
|
|
620
652
|
let args;
|
|
@@ -635,6 +667,15 @@ var install = (root, useYarn = false, dependencies = [], verbose = false, isOnli
|
|
|
635
667
|
console.log(import_chalk3.default.yellow("Falling back to the local Yarn cache."));
|
|
636
668
|
console.log();
|
|
637
669
|
}
|
|
670
|
+
} else if (usePnpm) {
|
|
671
|
+
command = "pnpm";
|
|
672
|
+
args = ["add", "--save"];
|
|
673
|
+
if (isDevDependencies) {
|
|
674
|
+
args.push("--save-dev");
|
|
675
|
+
}
|
|
676
|
+
args.push(...dependencies);
|
|
677
|
+
args.push("--cwd");
|
|
678
|
+
args.push(root);
|
|
638
679
|
} else {
|
|
639
680
|
command = "npm";
|
|
640
681
|
args = ["install", "--loglevel", "error"];
|
|
@@ -664,7 +705,6 @@ var runCommandInProjectDir = (root, command, args = [], successMessage = "Operat
|
|
|
664
705
|
child.on("close", (code) => {
|
|
665
706
|
if (code !== 0) {
|
|
666
707
|
console.log(import_chalk3.default.red(errorMessage));
|
|
667
|
-
reject(new Error(`${command} ${args.join(" ")}`));
|
|
668
708
|
return;
|
|
669
709
|
}
|
|
670
710
|
console.log(import_chalk3.default.green(successMessage));
|
|
@@ -678,14 +718,14 @@ var run = async ({
|
|
|
678
718
|
originalDirectory,
|
|
679
719
|
verbose = false,
|
|
680
720
|
useYarn = false,
|
|
721
|
+
usePnpm = false,
|
|
681
722
|
templatesOrExtensions = [],
|
|
682
723
|
dependencies = [],
|
|
683
724
|
devDependencies = [],
|
|
684
|
-
alias = "",
|
|
685
725
|
installDependencies = true,
|
|
686
|
-
srcDir = "",
|
|
687
726
|
runCommand = "",
|
|
688
|
-
installCommand = ""
|
|
727
|
+
installCommand = "",
|
|
728
|
+
...customOptions
|
|
689
729
|
}) => {
|
|
690
730
|
let isOnline = true;
|
|
691
731
|
if (useYarn) {
|
|
@@ -701,33 +741,52 @@ var run = async ({
|
|
|
701
741
|
console.log();
|
|
702
742
|
process.exit(0);
|
|
703
743
|
}
|
|
744
|
+
console.log();
|
|
745
|
+
console.log("Scaffolding project in " + root + "...");
|
|
704
746
|
await loadFiles({
|
|
705
747
|
root,
|
|
706
748
|
templatesOrExtensions,
|
|
707
749
|
appName,
|
|
708
750
|
originalDirectory,
|
|
709
|
-
alias,
|
|
710
751
|
verbose,
|
|
711
|
-
srcDir,
|
|
712
752
|
runCommand,
|
|
713
|
-
installCommand
|
|
753
|
+
installCommand,
|
|
754
|
+
...customOptions
|
|
714
755
|
});
|
|
756
|
+
console.log();
|
|
757
|
+
console.log(import_chalk3.default.green("Successfully scaffolded project."));
|
|
758
|
+
console.log();
|
|
715
759
|
if (installDependencies) {
|
|
716
760
|
console.log(
|
|
717
761
|
import_chalk3.default.green("Installing packages. This might take a couple of minutes.")
|
|
718
762
|
);
|
|
719
763
|
console.log(import_chalk3.default.green("Installing dependencies..."));
|
|
720
764
|
console.log();
|
|
721
|
-
await install(
|
|
765
|
+
await install(
|
|
766
|
+
root,
|
|
767
|
+
useYarn,
|
|
768
|
+
usePnpm,
|
|
769
|
+
dependencies,
|
|
770
|
+
verbose,
|
|
771
|
+
isOnline,
|
|
772
|
+
false
|
|
773
|
+
);
|
|
722
774
|
if (devDependencies.length > 0) {
|
|
723
775
|
console.log();
|
|
724
776
|
console.log(import_chalk3.default.green("Installing devDependencies..."));
|
|
725
777
|
console.log();
|
|
726
|
-
await install(
|
|
778
|
+
await install(
|
|
779
|
+
root,
|
|
780
|
+
useYarn,
|
|
781
|
+
usePnpm,
|
|
782
|
+
devDependencies,
|
|
783
|
+
verbose,
|
|
784
|
+
isOnline,
|
|
785
|
+
true
|
|
786
|
+
);
|
|
727
787
|
}
|
|
728
788
|
} else {
|
|
729
789
|
console.log(import_chalk3.default.yellow("Skip package installation."));
|
|
730
|
-
console.log(import_chalk3.default.yellow("Run npm install/yarn in your project."));
|
|
731
790
|
const packageJson = JSON.parse(
|
|
732
791
|
import_fs5.default.readFileSync(`${root}/package.json`, "utf8")
|
|
733
792
|
);
|
|
@@ -755,17 +814,19 @@ var run = async ({
|
|
|
755
814
|
import_path4.default.join(root, "package.json"),
|
|
756
815
|
JSON.stringify(packageJson, null, 2) + import_os3.default.EOL
|
|
757
816
|
);
|
|
817
|
+
console.log();
|
|
818
|
+
console.log(import_chalk3.default.green("Successfully updated package.json."));
|
|
819
|
+
console.log(import_chalk3.default.yellow(`Run ${import_chalk3.default.cyan(installCommand)} to install.`));
|
|
758
820
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
});
|
|
821
|
+
console.log();
|
|
822
|
+
console.log("Initializing git repository...");
|
|
823
|
+
await runCommandInProjectDir(
|
|
824
|
+
root,
|
|
825
|
+
"git",
|
|
826
|
+
["init"],
|
|
827
|
+
"Successfully initialized git repository.",
|
|
828
|
+
"Failed to initialize git repository."
|
|
829
|
+
);
|
|
769
830
|
if (installDependencies && isOnline) {
|
|
770
831
|
const packageJson = JSON.parse(
|
|
771
832
|
import_fs5.default.readFileSync(`${root}/package.json`, "utf8")
|
|
@@ -792,12 +853,10 @@ var run = async ({
|
|
|
792
853
|
var createApp = async ({
|
|
793
854
|
name,
|
|
794
855
|
verbose = false,
|
|
795
|
-
useNpm = false,
|
|
796
856
|
templatesOrExtensions = [],
|
|
797
|
-
alias = "",
|
|
798
857
|
installDependencies = true,
|
|
799
858
|
ignorePackage = false,
|
|
800
|
-
|
|
859
|
+
...customOptions
|
|
801
860
|
}) => {
|
|
802
861
|
const root = import_path4.default.resolve(name);
|
|
803
862
|
const appName = import_path4.default.basename(root);
|
|
@@ -806,14 +865,15 @@ var createApp = async ({
|
|
|
806
865
|
});
|
|
807
866
|
console.log(`Creating a new Node app in ${import_chalk3.default.green(root)}.`);
|
|
808
867
|
console.log();
|
|
809
|
-
const useYarn =
|
|
810
|
-
const
|
|
868
|
+
const useYarn = customOptions.packageManager === "yarn" && shouldUseYarn();
|
|
869
|
+
const usePnpm = customOptions.packageManager === "pnpm" && shouldUsePnpm();
|
|
870
|
+
const runCommand = useYarn ? "yarn" : "npm run";
|
|
871
|
+
const installCommand = useYarn ? "yarn" : usePnpm ? "pnpm install" : "npm install";
|
|
811
872
|
const { packageJson, dependencies, devDependencies } = await loadPackages({
|
|
812
873
|
templatesOrExtensions,
|
|
813
874
|
appName,
|
|
814
|
-
|
|
815
|
-
ignorePackage
|
|
816
|
-
srcDir
|
|
875
|
+
runCommand,
|
|
876
|
+
ignorePackage
|
|
817
877
|
});
|
|
818
878
|
import_fs5.default.writeFileSync(
|
|
819
879
|
import_path4.default.join(root, "package.json"),
|
|
@@ -869,14 +929,14 @@ Please update to npm 3 or higher for a better, fully supported experience.
|
|
|
869
929
|
originalDirectory,
|
|
870
930
|
verbose,
|
|
871
931
|
useYarn,
|
|
932
|
+
usePnpm,
|
|
872
933
|
templatesOrExtensions,
|
|
873
934
|
dependencies,
|
|
874
935
|
devDependencies,
|
|
875
|
-
alias,
|
|
876
936
|
installDependencies,
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
937
|
+
runCommand,
|
|
938
|
+
installCommand,
|
|
939
|
+
...customOptions
|
|
880
940
|
});
|
|
881
941
|
};
|
|
882
942
|
|
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";
|
|
@@ -201,6 +233,7 @@ var clone = (git, target, branch) => {
|
|
|
201
233
|
var pull = async (cwd) => {
|
|
202
234
|
await exec("git checkout -f", { cwd });
|
|
203
235
|
await exec("git pull", { cwd });
|
|
236
|
+
await new Promise((resolve) => setTimeout(resolve, 400));
|
|
204
237
|
};
|
|
205
238
|
var downloadRepository = async ({
|
|
206
239
|
url = "",
|
|
@@ -230,13 +263,11 @@ var downloadRepository = async ({
|
|
|
230
263
|
return;
|
|
231
264
|
}
|
|
232
265
|
await pull(cacheDir);
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
});
|
|
239
|
-
}, 400);
|
|
266
|
+
fs.cpSync(cacheDir, absoluteTarget, {
|
|
267
|
+
force: true,
|
|
268
|
+
filter: filterGit,
|
|
269
|
+
recursive: true
|
|
270
|
+
});
|
|
240
271
|
};
|
|
241
272
|
|
|
242
273
|
// paths.ts
|
|
@@ -397,7 +428,10 @@ var loadPackages = async ({
|
|
|
397
428
|
scripts: {}
|
|
398
429
|
})
|
|
399
430
|
);
|
|
400
|
-
return getInstallableSetup(
|
|
431
|
+
return getInstallableSetup({
|
|
432
|
+
...setup,
|
|
433
|
+
name: config.appName
|
|
434
|
+
});
|
|
401
435
|
};
|
|
402
436
|
|
|
403
437
|
// loaders.ts
|
|
@@ -477,12 +511,12 @@ var templateLoader = ({
|
|
|
477
511
|
root,
|
|
478
512
|
templateDir,
|
|
479
513
|
appName,
|
|
480
|
-
alias,
|
|
481
514
|
verbose,
|
|
482
515
|
mode = "",
|
|
483
516
|
srcDir,
|
|
484
517
|
runCommand,
|
|
485
|
-
installCommand
|
|
518
|
+
installCommand,
|
|
519
|
+
...customOptions
|
|
486
520
|
}) => async ({ path: path4 }) => {
|
|
487
521
|
const flag = mode.includes("append") ? "a+" : "w";
|
|
488
522
|
const file = fs3.readFileSync(`${templateDir}/${path4}`, "utf8");
|
|
@@ -491,13 +525,11 @@ var templateLoader = ({
|
|
|
491
525
|
return writeFile(
|
|
492
526
|
`${root}/${newPath}`,
|
|
493
527
|
newFile({
|
|
494
|
-
project: alias,
|
|
495
|
-
projectImport: alias,
|
|
496
|
-
projectImportPath: alias === "" ? "" : `${alias}/`,
|
|
497
528
|
projectName: appName,
|
|
498
529
|
srcDir: srcDir || ".",
|
|
499
530
|
runCommand,
|
|
500
|
-
installCommand
|
|
531
|
+
installCommand,
|
|
532
|
+
...customOptions
|
|
501
533
|
}),
|
|
502
534
|
flag,
|
|
503
535
|
verbose
|
|
@@ -508,11 +540,11 @@ var fileLoader = ({
|
|
|
508
540
|
templateDir,
|
|
509
541
|
appName,
|
|
510
542
|
originalDirectory,
|
|
511
|
-
alias,
|
|
512
543
|
verbose,
|
|
513
544
|
srcDir = DEFAULT_SRC_PATH,
|
|
514
545
|
runCommand,
|
|
515
|
-
installCommand
|
|
546
|
+
installCommand,
|
|
547
|
+
...customOptions
|
|
516
548
|
}) => ({ path: path4 }) => {
|
|
517
549
|
const mode = getModeFromPath(path4);
|
|
518
550
|
const loaders = {
|
|
@@ -526,12 +558,12 @@ var fileLoader = ({
|
|
|
526
558
|
templateDir,
|
|
527
559
|
appName,
|
|
528
560
|
originalDirectory,
|
|
529
|
-
alias,
|
|
530
561
|
verbose,
|
|
531
562
|
mode,
|
|
532
563
|
srcDir,
|
|
533
564
|
runCommand,
|
|
534
|
-
installCommand
|
|
565
|
+
installCommand,
|
|
566
|
+
...customOptions
|
|
535
567
|
})({
|
|
536
568
|
path: path4
|
|
537
569
|
});
|
|
@@ -541,11 +573,11 @@ var loadFiles = async ({
|
|
|
541
573
|
templatesOrExtensions = [],
|
|
542
574
|
appName,
|
|
543
575
|
originalDirectory,
|
|
544
|
-
alias,
|
|
545
576
|
verbose,
|
|
546
577
|
srcDir = DEFAULT_SRC_PATH,
|
|
547
578
|
runCommand,
|
|
548
|
-
installCommand
|
|
579
|
+
installCommand,
|
|
580
|
+
...customOptions
|
|
549
581
|
}) => {
|
|
550
582
|
for await (const { url: templateOrExtensionUrl } of templatesOrExtensions) {
|
|
551
583
|
const templateDir = await getTemplateDirPath(templateOrExtensionUrl);
|
|
@@ -569,11 +601,11 @@ var loadFiles = async ({
|
|
|
569
601
|
templateDir,
|
|
570
602
|
appName,
|
|
571
603
|
originalDirectory,
|
|
572
|
-
alias,
|
|
573
604
|
verbose,
|
|
574
605
|
srcDir,
|
|
575
606
|
runCommand,
|
|
576
|
-
installCommand
|
|
607
|
+
installCommand,
|
|
608
|
+
...customOptions
|
|
577
609
|
})(entry);
|
|
578
610
|
} catch (err) {
|
|
579
611
|
if (verbose) {
|
|
@@ -586,7 +618,7 @@ var loadFiles = async ({
|
|
|
586
618
|
};
|
|
587
619
|
|
|
588
620
|
// installer.ts
|
|
589
|
-
var install = (root, useYarn = false, dependencies = [], verbose = false, isOnline = true, isDevDependencies = false) => {
|
|
621
|
+
var install = (root, useYarn = false, usePnpm = false, dependencies = [], verbose = false, isOnline = true, isDevDependencies = false) => {
|
|
590
622
|
return new Promise((resolve, reject) => {
|
|
591
623
|
let command;
|
|
592
624
|
let args;
|
|
@@ -607,6 +639,15 @@ var install = (root, useYarn = false, dependencies = [], verbose = false, isOnli
|
|
|
607
639
|
console.log(chalk3.yellow("Falling back to the local Yarn cache."));
|
|
608
640
|
console.log();
|
|
609
641
|
}
|
|
642
|
+
} else if (usePnpm) {
|
|
643
|
+
command = "pnpm";
|
|
644
|
+
args = ["add", "--save"];
|
|
645
|
+
if (isDevDependencies) {
|
|
646
|
+
args.push("--save-dev");
|
|
647
|
+
}
|
|
648
|
+
args.push(...dependencies);
|
|
649
|
+
args.push("--cwd");
|
|
650
|
+
args.push(root);
|
|
610
651
|
} else {
|
|
611
652
|
command = "npm";
|
|
612
653
|
args = ["install", "--loglevel", "error"];
|
|
@@ -636,7 +677,6 @@ var runCommandInProjectDir = (root, command, args = [], successMessage = "Operat
|
|
|
636
677
|
child.on("close", (code) => {
|
|
637
678
|
if (code !== 0) {
|
|
638
679
|
console.log(chalk3.red(errorMessage));
|
|
639
|
-
reject(new Error(`${command} ${args.join(" ")}`));
|
|
640
680
|
return;
|
|
641
681
|
}
|
|
642
682
|
console.log(chalk3.green(successMessage));
|
|
@@ -650,14 +690,14 @@ var run = async ({
|
|
|
650
690
|
originalDirectory,
|
|
651
691
|
verbose = false,
|
|
652
692
|
useYarn = false,
|
|
693
|
+
usePnpm = false,
|
|
653
694
|
templatesOrExtensions = [],
|
|
654
695
|
dependencies = [],
|
|
655
696
|
devDependencies = [],
|
|
656
|
-
alias = "",
|
|
657
697
|
installDependencies = true,
|
|
658
|
-
srcDir = "",
|
|
659
698
|
runCommand = "",
|
|
660
|
-
installCommand = ""
|
|
699
|
+
installCommand = "",
|
|
700
|
+
...customOptions
|
|
661
701
|
}) => {
|
|
662
702
|
let isOnline = true;
|
|
663
703
|
if (useYarn) {
|
|
@@ -673,33 +713,52 @@ var run = async ({
|
|
|
673
713
|
console.log();
|
|
674
714
|
process.exit(0);
|
|
675
715
|
}
|
|
716
|
+
console.log();
|
|
717
|
+
console.log("Scaffolding project in " + root + "...");
|
|
676
718
|
await loadFiles({
|
|
677
719
|
root,
|
|
678
720
|
templatesOrExtensions,
|
|
679
721
|
appName,
|
|
680
722
|
originalDirectory,
|
|
681
|
-
alias,
|
|
682
723
|
verbose,
|
|
683
|
-
srcDir,
|
|
684
724
|
runCommand,
|
|
685
|
-
installCommand
|
|
725
|
+
installCommand,
|
|
726
|
+
...customOptions
|
|
686
727
|
});
|
|
728
|
+
console.log();
|
|
729
|
+
console.log(chalk3.green("Successfully scaffolded project."));
|
|
730
|
+
console.log();
|
|
687
731
|
if (installDependencies) {
|
|
688
732
|
console.log(
|
|
689
733
|
chalk3.green("Installing packages. This might take a couple of minutes.")
|
|
690
734
|
);
|
|
691
735
|
console.log(chalk3.green("Installing dependencies..."));
|
|
692
736
|
console.log();
|
|
693
|
-
await install(
|
|
737
|
+
await install(
|
|
738
|
+
root,
|
|
739
|
+
useYarn,
|
|
740
|
+
usePnpm,
|
|
741
|
+
dependencies,
|
|
742
|
+
verbose,
|
|
743
|
+
isOnline,
|
|
744
|
+
false
|
|
745
|
+
);
|
|
694
746
|
if (devDependencies.length > 0) {
|
|
695
747
|
console.log();
|
|
696
748
|
console.log(chalk3.green("Installing devDependencies..."));
|
|
697
749
|
console.log();
|
|
698
|
-
await install(
|
|
750
|
+
await install(
|
|
751
|
+
root,
|
|
752
|
+
useYarn,
|
|
753
|
+
usePnpm,
|
|
754
|
+
devDependencies,
|
|
755
|
+
verbose,
|
|
756
|
+
isOnline,
|
|
757
|
+
true
|
|
758
|
+
);
|
|
699
759
|
}
|
|
700
760
|
} else {
|
|
701
761
|
console.log(chalk3.yellow("Skip package installation."));
|
|
702
|
-
console.log(chalk3.yellow("Run npm install/yarn in your project."));
|
|
703
762
|
const packageJson = JSON.parse(
|
|
704
763
|
fs4.readFileSync(`${root}/package.json`, "utf8")
|
|
705
764
|
);
|
|
@@ -727,17 +786,19 @@ var run = async ({
|
|
|
727
786
|
path3.join(root, "package.json"),
|
|
728
787
|
JSON.stringify(packageJson, null, 2) + os3.EOL
|
|
729
788
|
);
|
|
789
|
+
console.log();
|
|
790
|
+
console.log(chalk3.green("Successfully updated package.json."));
|
|
791
|
+
console.log(chalk3.yellow(`Run ${chalk3.cyan(installCommand)} to install.`));
|
|
730
792
|
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
});
|
|
793
|
+
console.log();
|
|
794
|
+
console.log("Initializing git repository...");
|
|
795
|
+
await runCommandInProjectDir(
|
|
796
|
+
root,
|
|
797
|
+
"git",
|
|
798
|
+
["init"],
|
|
799
|
+
"Successfully initialized git repository.",
|
|
800
|
+
"Failed to initialize git repository."
|
|
801
|
+
);
|
|
741
802
|
if (installDependencies && isOnline) {
|
|
742
803
|
const packageJson = JSON.parse(
|
|
743
804
|
fs4.readFileSync(`${root}/package.json`, "utf8")
|
|
@@ -764,12 +825,10 @@ var run = async ({
|
|
|
764
825
|
var createApp = async ({
|
|
765
826
|
name,
|
|
766
827
|
verbose = false,
|
|
767
|
-
useNpm = false,
|
|
768
828
|
templatesOrExtensions = [],
|
|
769
|
-
alias = "",
|
|
770
829
|
installDependencies = true,
|
|
771
830
|
ignorePackage = false,
|
|
772
|
-
|
|
831
|
+
...customOptions
|
|
773
832
|
}) => {
|
|
774
833
|
const root = path3.resolve(name);
|
|
775
834
|
const appName = path3.basename(root);
|
|
@@ -778,14 +837,15 @@ var createApp = async ({
|
|
|
778
837
|
});
|
|
779
838
|
console.log(`Creating a new Node app in ${chalk3.green(root)}.`);
|
|
780
839
|
console.log();
|
|
781
|
-
const useYarn =
|
|
782
|
-
const
|
|
840
|
+
const useYarn = customOptions.packageManager === "yarn" && shouldUseYarn();
|
|
841
|
+
const usePnpm = customOptions.packageManager === "pnpm" && shouldUsePnpm();
|
|
842
|
+
const runCommand = useYarn ? "yarn" : "npm run";
|
|
843
|
+
const installCommand = useYarn ? "yarn" : usePnpm ? "pnpm install" : "npm install";
|
|
783
844
|
const { packageJson, dependencies, devDependencies } = await loadPackages({
|
|
784
845
|
templatesOrExtensions,
|
|
785
846
|
appName,
|
|
786
|
-
|
|
787
|
-
ignorePackage
|
|
788
|
-
srcDir
|
|
847
|
+
runCommand,
|
|
848
|
+
ignorePackage
|
|
789
849
|
});
|
|
790
850
|
fs4.writeFileSync(
|
|
791
851
|
path3.join(root, "package.json"),
|
|
@@ -841,14 +901,14 @@ Please update to npm 3 or higher for a better, fully supported experience.
|
|
|
841
901
|
originalDirectory,
|
|
842
902
|
verbose,
|
|
843
903
|
useYarn,
|
|
904
|
+
usePnpm,
|
|
844
905
|
templatesOrExtensions,
|
|
845
906
|
dependencies,
|
|
846
907
|
devDependencies,
|
|
847
|
-
alias,
|
|
848
908
|
installDependencies,
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
909
|
+
runCommand,
|
|
910
|
+
installCommand,
|
|
911
|
+
...customOptions
|
|
852
912
|
});
|
|
853
913
|
};
|
|
854
914
|
|