Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/ci mode #1274

Merged
merged 7 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions packages/cli/src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,32 @@ import {

export const inquirerPrompt = async (params: PromptParams): Promise<Record<string, any>> => {
const c = getContext();
if (c.program?.yes) return {};

if (c.program?.yes && params.type === 'confirm' && params.name) {
return { [params.name]: true };
} else if (c.program?.yes && params.type === 'input' && params.name && params.default) {
return { [params.name]: typeof params.default === 'function' ? params.default() : params.default };
}

const msg = params.logMessage || params.warningMessage || params.message;
if (c.program?.ci) {
if (
Array.isArray(params.choices) &&
typeof params.default !== 'undefined' &&
params.choices.includes(params.default)
) {
logDebug(`defaulting to choice '${params.default}' for prompt '${params.name}'`);
try {
if (
Array.isArray(params.choices) &&
typeof params.default !== 'undefined' &&
params.choices.includes(params.default)
) {
logDebug(`defaulting to choice '${params.default}' for prompt '${params.name}'`);

if (params.name) return Promise.resolve({ [params.name]: params.default });
if (params.name) return { [params.name]: params.default };
}
throw new Error(msg);
} catch (error) {
logWarning(error instanceof Error ? error.message : error);
}
return Promise.reject(`--ci option does not allow prompts. question: ${msg}.`);
}
if (msg && params.logMessage) logTask(msg, chalk().grey);
if (msg && params.warningMessage) logWarning(msg);
if (msg && params.warningMessage && !c.program.ci) logWarning(msg);

// allow passing in just { type: 'prompt', ... } instead of { type: 'prompt', name: 'prompt', ... }
const { type, name } = params;
Expand Down
102 changes: 70 additions & 32 deletions packages/engine-core/src/tasks/task.rnv.new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,48 +324,86 @@ export const taskRnvNew = async (c: RnvContext) => {
// ==================================================
// INPUT: Project Title, ID, Version
// ==================================================
let inputAppTitle;
let inputAppID;
let inputVersion;
if (title && title !== '' && id && id !== '' && appVersion && appVersion !== '') {
inputAppTitle = title;
inputAppID = id;
inputVersion = appVersion;
} else {
const answer1 = await inquirerPrompt({

const validator = {
validateAppTitle: (val: string) => (typeof val === 'string' && val !== '') || 'Please enter a title',
validateAppID: (appId: string) =>
(typeof appId === 'string' && !!appId.match(/^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$/)) ||
'Please enter a valid appID (com.test.app)',
validateAppVersion: (version: string) =>
!!semver.valid(semver.coerce(version)) ||
'Please enter a valid semver version (1.0.0, 42.6.7.9.3-alpha, etc.)',
};

const inputValues = [
{
value: title,
validFn: validator.validateAppTitle,
name: 'inputAppTitle',
type: 'input',
default: data.defaultAppTitle,
validate: (val) => !!val || 'Please enter a title',
defaultVal: data.defaultAppTitle,
message: "What's your project Title?",
});
const answer2 = await inquirerPrompt({
warning: 'Title was not provided',
},
{
value: id,
validFn: validator.validateAppID,
name: 'inputAppID',
type: 'input',
default: () => {
data.appID = `com.mycompany.${inputProjectName.replace(/\s+/g, '').toLowerCase()}`;
defaultVal: () => {
data.appID = `com.mycompany.${inputProjectName.replace(/[^a-zA-Z0-9]/g, '').toLowerCase()}`;
return data.appID;
},
validate: (appId) =>
!!appId.match(/^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$/) ||
'Please enter a valid appID (com.test.app)',
message: "What's your App ID?",
});

const answer3 = await inquirerPrompt({
warning: `Command contains invalid appId ${id}`,
},
{
value: appVersion,
validFn: validator.validateAppVersion,
name: 'inputVersion',
type: 'input',
default: data.defaultVersion,
validate: (v) =>
!!semver.valid(semver.coerce(v)) ||
'Please enter a valid semver version (1.0.0, 42.6.7.9.3-alpha, etc.)',
defaultVal: data.defaultVersion,
message: "What's your Version?",
});
inputAppTitle = answer1?.inputAppTitle;
inputAppID = answer2?.inputAppID;
inputVersion = answer3?.inputVersion;
warning: 'Command contains invalid appVersion',
},
];

const validateAndAssign = async ({
value,
validFn,
name,
defaultVal,
message,
warning,
}: {
value: string;
validFn: (value: string) => true | string;
name: string;
defaultVal: (() => string) | string | undefined;
message: string;
warning: string;
}): Promise<string> => {
const isValid = validFn(value);
if (value && isValid === true) {
return value;
} else {
const warningMessage = typeof isValid === 'string';
const answer = await inquirerPrompt({
name,
type: 'input',
default: defaultVal,
validate: validFn,
message,
warningMessage: ci && warningMessage && warning,
});
return answer[name];
}
};
const inputsResult = [];
for (const value of inputValues) {
const res = await validateAndAssign(value);
inputsResult.push(res);
}

const [inputAppTitle, inputAppID, inputVersion] = inputsResult;

// ==================================================
// INPUT: Workspace
// ==================================================
Expand Down
11 changes: 5 additions & 6 deletions packages/sdk-tizen/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,12 @@ export const buildTizenProject = async (c: RnvContext) => {
const tIntermediate = path.join(tDir, 'intermediate');
const tBuild = path.join(tDir, 'build');

const projectFile = path.join(tDir, '.project');
const tProjectFile = path.join(tDir, '.tproject');
const configXml = path.join(tDir, 'config.xml');
const requiredFiles = ['.project', '.tproject', 'config.xml', 'icon.png'];

copyFileSync(projectFile, path.join(tBuild, '.project'));
copyFileSync(tProjectFile, path.join(tBuild, '.tproject'));
copyFileSync(configXml, path.join(tBuild, 'config.xml'));
requiredFiles.map((requiredFile) => {
const requiredFilePath = path.join(tDir, requiredFile);
copyFileSync(requiredFilePath, path.join(tBuild, requiredFile));
});

await execCLI(c, CLI_TIZEN, `build-web -- ${tBuild} -out ${tIntermediate}`);
await execCLI(c, CLI_TIZEN, `package -- ${tIntermediate} -s ${certProfile} -t wgt -o ${tOut}`);
Expand Down