MCPcopy Create free account
hub / github.com/cloudle/ruui / init

Function init

cli-local/init.js:13–90  ·  view source on GitHub ↗
(root, argsOrName, opts)

Source from the content-addressed store, hash-verified

11 .filter(isDirectory);
12
13function init(root, argsOrName, opts) {
14 const template = opts['base'] || 'default',
15 availableTemplates = getDirectories(path.resolve(ruuiCliModule('templates')))
16 .map(source => path.relative(ruuiCliModule('templates'), source))
17 .filter(name => name !== 'core'),
18 walk = require(rnCliModule('util/walk')),
19 copyAndReplace = require(rnCliModule('util/copyAndReplace')),
20 yarn = require(rnCliModule('util/yarn')),
21 yarnVersion = (!opts.npm) &&
22 yarn.getYarnVersionIfAvailable() &&
23 yarn.isGlobalCliUsingYarn(root),
24 templates = require('./util/templates'),
25 args = Array.isArray(argsOrName)
26 ? argsOrName // argsOrName was e.g. ['AwesomeApp', '--verbose']
27 : [argsOrName].concat(process.argv.slice(4)), // argsOrName was e.g. 'AwesomeApp';
28 newProjectName = args[0],
29 templateReplacements = {
30 'Hello App Display Name': newProjectName,
31 HelloWorld: newProjectName,
32 helloworld: newProjectName.toLowerCase(),
33 };
34
35 let dependencies = {}, devDependencies = {};
36 const coreTemplatePath = path.resolve(ruuiCliModule('templates/core')),
37 coreDependenciesPath = path.resolve(coreTemplatePath, 'dependencies.json'),
38 coreDevDependenciesPath = path.resolve(coreTemplatePath, 'devDependencies.json');
39
40 if (fs.existsSync(coreDependenciesPath)) {
41 const coreDependencies = require(coreDependenciesPath);
42 dependencies = { ...dependencies, ...coreDependencies };
43 }
44
45 if (fs.existsSync(coreDevDependenciesPath)) {
46 const coreDevDependencies = require(coreDevDependenciesPath);
47 devDependencies = { ...devDependencies, ...coreDevDependencies };
48 }
49
50 walk(coreTemplatePath).forEach((absoluteSrcPath) => {
51 const relativeFilePath = path.relative(coreTemplatePath, absoluteSrcPath),
52 relativeRenamedPath = dotFilePath(relativeFilePath),
53 absoluteDestinationPath = path.resolve(root, relativeRenamedPath);
54
55 if (templateExclustions.indexOf(relativeRenamedPath) >= 0) return;
56 copyAndReplace(absoluteSrcPath, absoluteDestinationPath, templateReplacements);
57 });
58
59 if (template !== 'core') {
60 if (availableTemplates.indexOf(template) >= 0) {
61 const childTemplatePath = path.resolve(ruuiCliModule(`templates/${template}`)),
62 childDependenciesPath = path.resolve(childTemplatePath, 'dependencies.json'),
63 childDevDependenciesPath = path.resolve(childTemplatePath, 'devDependencies.json');
64
65 walk(childTemplatePath).forEach((absoluteSrcPath) => {
66 const relativeFilePath = path.relative(childTemplatePath, absoluteSrcPath),
67 relativeRenamedPath = dotFilePath(relativeFilePath),
68 absoluteDestinationPath = path.resolve(root, relativeRenamedPath);
69
70 if (templateExclustions.indexOf(relativeRenamedPath) >= 0) return;

Callers

nothing calls this directly

Calls 4

getDirectoriesFunction · 0.85
ruuiCliModuleFunction · 0.85
rnCliModuleFunction · 0.85
dotFilePathFunction · 0.85

Tested by

no test coverage detected