MCPcopy
hub / github.com/meteor/meteor / createIfNeeded

Method createIfNeeded

tools/cordova/project.js:96–191  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

94 }
95
96 createIfNeeded() {
97 buildmessage.assertInJob();
98
99 // Check if we have an existing Cordova project directory with outdated
100 // platforms. In that case, we remove the whole directory to avoid issues.
101 if (files.exists(this.projectRoot)) {
102 const installedPlatforms = this.listInstalledPlatforms();
103
104 const outdated = _.some(pinnedPlatformVersions, (pinnedVersion, platform) => {
105 // If the platform is not installed, it cannot be outdated
106 if (!_.contains(installedPlatforms, platform)) {
107 return false;
108 }
109
110 const installedVersion = this.installedVersionForPlatform(platform);
111 // If we cannot establish the installed version, we consider it outdated
112 if (!installedVersion) {
113 return true;
114 }
115
116 if (! semver.valid(pinnedVersion)) {
117 // If pinnedVersion is not a semantic version but instead
118 // something like a GitHub tarball URL, assume not outdated.
119 return false;
120 }
121
122 return semver.lt(installedVersion, pinnedVersion);
123 });
124
125 if (outdated) {
126 Console.debug(`Removing Cordova project directory to avoid issues with
127outdated platforms`);
128 // Remove Cordova project directory to start afresh
129 // and avoid a broken project
130 files.rm_recursive(this.projectRoot);
131 }
132 }
133
134 if (!files.exists(this.projectRoot)) {
135 // We create a temporary directory with a generated config.xml
136 // to use as a template for creating the Cordova project
137 // This way, we are not dependent on the contents of
138 // cordova-app-hello-world but we base our initial project state on
139 // our own defaults and optionally a mobile-config.js
140
141 const templatePath = files.mkdtemp('cordova-template-');
142
143 // If we don't create an empty hooks directory, cordova-lib will attempt
144 // to install one from a hardcoded path to cordova-app-hello-world
145 files.mkdir_p(files.pathJoin(templatePath, 'hooks'));
146
147 // If we don't create an empty www directory, cordova-lib will get
148 // confused
149 files.mkdir_p(files.pathJoin(templatePath, 'www'));
150
151 const builder = new CordovaBuilder(
152 this.projectContext,
153 templatePath,

Callers 1

constructorMethod · 0.95

Calls 7

processControlFileMethod · 0.95
runCommandsMethod · 0.95
writeBuildJsonMethod · 0.95
debugMethod · 0.45

Tested by

no test coverage detected