Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Non-destructively copy over files from /templates/app/<template>/template
templateDir = path.join(sdkPath, 'templates', 'app', cli.argv.template, 'template');
if (!appc.fs.exists(templateDir)) {
logger.error(__('Unknown project template %s', cli.argv.template) + '\n');
process.exit(1);
}
n = appc.fs.nonDestructiveCopyDirSyncRecursive(templateDir, projectDir, {
logger: logger.log,
ignoreHiddenFiles: true
});
// Non-destructively copy over files from //templates/app/<template>/
for (p = 0; p < value.length; p++) {
if (value[p]) {
templateDir = path.join(sdkPath, ti.resolvePlatform(value[p]), 'templates', 'app', cli.argv.template, 'template');
if (appc.fs.exists(templateDir)) {
n += appc.fs.nonDestructiveCopyDirSyncRecursive(templateDir, projectDir, {
logger: logger.log,
ignoreHiddenFiles: true
});
}
}
}
value = value.join(', ');
n && logger.log();
break;
case 'sdk-version':
value = args[1];
if (value === 'latest') {
value = Object.keys(cli.env.sdks).sort().reverse()[0];
}</template></template>
} else if (fs.existsSync(path.join(projectDir, 'timodule.xml'))) {
let timodule;
try {
timodule = cli.tiapp = cli.timodule = new tiappxml(path.join(projectDir, 'timodule.xml'));
} catch (ex) {
logger.error(ex);
logger.log();
process.exit(1);
}
const manifest = cli.manifest = ti.loadModuleManifest(logger, path.join(projectDir, 'manifest'));
// if they didn't explicitly set --platform and we have a platform in the manifest,
// then just use that and skip the platform prompting
if (!cli.argv.platform && manifest.platform) {
cli.argv.platform = ti.resolvePlatform(manifest.platform);
conf.options.platform.required = false;
}
timodule.properties || (timodule.properties = {});
cli.argv.type = 'module';
} else {
// neither app nor module
return;
}
cli.scanHooks(path.join(projectDir, 'hooks'));
return projectDir;
},
exports.run = function (logger, config, cli) {
function done(err) {
if (err) {
logger.error(__('Failed to clean project in %s', appc.time.prettyDiff(cli.startTime, Date.now())) + '\n');
} else {
logger.info(__('Project cleaned successfully in %s', appc.time.prettyDiff(cli.startTime, Date.now())) + '\n');
}
}
if (cli.argv.type === 'module') {
// TODO Iterate over platforms? For multi-platform modules we should handle this...
const platform = ti.resolvePlatform(cli.argv.platform);
const cleanModule = path.join(__dirname, '..', '..', platform, 'cli', 'commands', '_cleanModule.js');
if (!fs.existsSync(cleanModule)) {
logger.error(__('Unable to find platform specific module clean command') + '\n');
logger.log(__('Your SDK installation may be corrupt. You can reinstall it by running \'%s\'.', (cli.argv.$ + ' sdk install --force --default').cyan) + '\n');
process.exit(1);
}
// Now wrap the actual cleaning of the module (specific to a given platform),
// in hooks so a module itself could potentially do additional cleanup itself
cli.fireHook('clean.module.pre', function () {
cli.fireHook('clean.module.' + platform + '.pre', function () {
// Do the actual cleaning per-sdk _cleanModule command
require(cleanModule).run(logger, config, cli, function (err) { // eslint-disable-line security/detect-non-literal-require
const delta = appc.time.prettyDiff(cli.startTime, Date.now());
if (err) {
} else if (fs.existsSync(path.join(projectDir, 'timodule.xml'))) {
let timodule;
try {
timodule = cli.tiapp = cli.timodule = new tiappxml(path.join(projectDir, 'timodule.xml'));
} catch (ex) {
logger.error(ex);
logger.log();
process.exit(1);
}
const manifest = cli.manifest = ti.loadModuleManifest(logger, path.join(projectDir, 'manifest'));
// if they didn't explicitly set --platform and we have a platform in the manifest,
// then just use that and skip the platform prompting
if (!cli.argv.platform && manifest.platform) {
cli.argv.platform = ti.resolvePlatform(manifest.platform);
conf.options.platform.required = false;
}
timodule.properties || (timodule.properties = {});
cli.argv.type = 'module';
} else {
// neither app nor module
return;
}
cli.scanHooks(path.join(projectDir, 'hooks'));
return projectDir;
},
logger.log.init = function (callback) {
var platform = ti.resolvePlatform(cli.argv.platform),
buildDir = path.join(cli.argv['project-dir'], 'build');
logger.fileWriteEnabled = true;
fs.ensureDirSync(buildDir, 0o766);
// create our write stream
logger.log.filestream = fs.createWriteStream(path.join(buildDir, 'build_' + platform + '.log'), { flags: 'w', encoding: 'utf8', mode: 0o666 });
function styleHeading(s) {
return ('' + s).bold;
}
function styleValue(s) {
return ('' + s).magenta;
}
logger.log.init = function (callback) {
var platform = ti.resolvePlatform(cli.argv.platform),
buildDir = path.join(cli.argv['project-dir'], 'build');
logger.fileWriteEnabled = true;
fs.ensureDirSync(buildDir, 0o766);
// create our write stream
logger.log.filestream = fs.createWriteStream(path.join(buildDir, 'build_' + platform + '.log'), { flags: 'w', encoding: 'utf8', mode: 0o666 });
function styleHeading(s) {
return ('' + s).bold;
}
function styleValue(s) {
return ('' + s).magenta;
}
exports.run = function run(logger, config, cli, finished) {
const buildFile = cli.argv.type === 'module' ? '_buildModule.js' : '_build.js',
platform = ti.resolvePlatform(cli.argv.platform),
buildModule = path.join(__dirname, '..', '..', platform, 'cli', 'commands', buildFile);
if (!fs.existsSync(buildModule)) {
logger.error(__('Unable to find platform specific build command') + '\n');
logger.log(__('Your SDK installation may be corrupt. You can reinstall it by running \'%s\'.', (cli.argv.$ + ' sdk install --force --default').cyan) + '\n');
process.exit(1);
}
if (config.get('cli.sendAPIUsage', true)) {
cli.on('build.finalize', function (builder) {
const deployType = builder.deployType || cli.argv['deploy-type'] || null;
if (deployType === 'production') {
cli.addAnalyticsEvent('Titanium API Usage', {
platform: platform,
tisdkname: (ti.manifest && ti.manifest.name) || (cli.sdk && cli.sdk.name) || null,
tisdkver: (ti.manifest && ti.manifest.version) || (cli.sdk && cli.sdk.name) || null,
callback: function (platform) {
if (!cli.argv.$originalPlatform) {
cli.argv.$originalPlatform = platform;
}
platform = cli.argv.platform = ti.resolvePlatform(platform);
const p = platformConf[platform];
p && p.options && Object.keys(p.options).forEach(function (name) {
if (p.options[name].default && cli.argv[name] === undefined) {
cli.argv[name] = p.options[name].default;
}
});
return platform;
},
desc: __('the target build platform'),
' ' + rpad(__('Version')) + ' = ' + styleValue(osInfo.osver),
' ' + rpad(__('Architecture')) + ' = ' + styleValue(osInfo.ostype),
' ' + rpad(__('# CPUs')) + ' = ' + styleValue(osInfo.oscpu),
' ' + rpad(__('Memory')) + ' = ' + styleValue(osInfo.memory),
'',
styleHeading(__('Node.js')),
' ' + rpad(__('Node.js Version')) + ' = ' + styleValue(osInfo.node),
' ' + rpad(__('npm Version')) + ' = ' + styleValue(osInfo.npm),
'',
styleHeading(__('Titanium CLI')),
' ' + rpad(__('CLI Version')) + ' = ' + styleValue(cli.version),
'',
styleHeading(__('Titanium SDK')),
' ' + rpad(__('SDK Version')) + ' = ' + styleValue(cli.argv.sdk),
' ' + rpad(__('SDK Path')) + ' = ' + styleValue(cli.sdk.path),
' ' + rpad(__('Target Platform')) + ' = ' + styleValue(ti.resolvePlatform(cli.argv.platform)),
'',
styleHeading(__('Command')),
' ' + styleValue(process.argv.join(' ')),
''
].join('\n'));
logger.log.flush();
callback();
});
};