本文整理汇总了TypeScript中@electron-forge/async-ora.asyncOra函数的典型用法代码示例。如果您正苦于以下问题:TypeScript asyncOra函数的具体用法?TypeScript asyncOra怎么用?TypeScript asyncOra使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了asyncOra函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
export default async (dir: string) => {
await asyncOra('Initializing NPM Module', async () => {
const packageJSON = await readPackageJSON(path.resolve(__dirname, '../../../tmpl'));
packageJSON.productName = packageJSON.name = path.basename(dir).toLowerCase();
packageJSON.author = await username();
setInitialForgeConfig(packageJSON);
packageJSON.scripts.lint = 'echo "No linting configured"';
d('writing package.json to:', dir);
await fs.writeJson(path.resolve(dir, 'package.json'), packageJSON, { spaces: 2 });
});
await asyncOra('Installing NPM Dependencies', async () => {
d('installing dependencies');
await installDepList(dir, deps);
d('installing devDependencies');
await installDepList(dir, devDeps, true);
d('installing exact dependencies');
for (const packageName of exactDevDeps) {
await installDepList(dir, [packageName], true, true);
}
});
};
示例2: async
export default async ({
dir = process.cwd(),
interactive = false,
}: LintOptions) => {
asyncOra.interactive = interactive;
let success = true;
let result = null;
await asyncOra('Linting Application', async (lintSpinner) => {
const resolvedDir = await resolveDir(dir);
if (!resolvedDir) {
throw 'Failed to locate lintable Electron application';
}
dir = resolvedDir;
d('executing "run lint" in dir:', dir);
try {
await yarnOrNpmSpawn(['run', 'lint'], {
stdio: process.platform === 'win32' ? 'inherit' : 'pipe',
cwd: dir,
});
} catch (err) {
lintSpinner.fail();
success = false;
result = err;
}
});
if (!success) {
throw result;
}
};
示例3: async
export default async (
buildPath: string,
electronVersion: string,
platform: ForgePlatform,
arch: ForgeArch,
config: Partial<RebuildOptions> = {},
) => {
await asyncOra('Preparing native dependencies', async (rebuildSpinner) => {
const rebuilder = rebuild(Object.assign({}, config, {
buildPath,
electronVersion,
arch,
}));
const { lifecycle } = rebuilder;
let found = 0;
let done = 0;
const redraw = () => {
rebuildSpinner.text = `Preparing native dependencies: ${done} / ${found}`; // eslint-disable-line
};
lifecycle.on('module-found', () => { found += 1; redraw(); });
lifecycle.on('module-done', () => { done += 1; redraw(); });
await rebuilder;
});
};
示例4: async
export default async (dir: string) => {
await asyncOra('Initializing Project Directory', async (initSpinner) => {
d('creating directory:', dir);
await fs.mkdirs(dir);
const files = await fs.readdir(dir);
if (files.length !== 0) {
d('found', files.length, 'files in the directory. warning the user');
initSpinner.stop(logSymbols.warning);
throw `The specified path: "${dir}" is not empty, do you wish to continue?`;
}
});
};
示例5: asyncOra
(async () => {
let goodSystem;
await asyncOra('Checking your system', async (ora) => {
goodSystem = await checkSystem(ora);
});
if (!goodSystem) {
console.error(('It looks like you are missing some dependencies you need to get Electron running.\n' +
'Make sure you have git installed and Node.js version 6.0.0+').red);
process.exit(1);
}
program.parse(process.argv);
})();
示例6: async
const forgeSpawn = async () => {
let electronExecPath = require(path.resolve(dir, 'node_modules/electron'));
// If a plugin has taken over the start command let's stop here
const spawnedPluginChild = await forgeConfig.pluginInterface.overrideStartLogic({
dir,
appPath,
interactive,
enableLogging,
args,
runAsNode,
inspect,
});
if (typeof spawnedPluginChild === 'string') {
electronExecPath = spawnedPluginChild;
} else if (spawnedPluginChild) {
await runHook(forgeConfig, 'postStart', spawnedPluginChild);
return spawnedPluginChild;
}
const spawnOpts = {
cwd: dir,
stdio: 'inherit',
env: Object.assign({}, process.env, enableLogging ? {
ELECTRON_ENABLE_LOGGING: 'true',
ELECTRON_ENABLE_STACK_DUMPING: 'true',
} : {}) as NodeJS.ProcessEnv,
};
if (runAsNode) {
spawnOpts.env.ELECTRON_RUN_AS_NODE = 'true';
} else {
delete spawnOpts.env.ELECTRON_RUN_AS_NODE;
}
if (inspect) {
args = ['--inspect' as (string|number)].concat(args);
}
let spawned!: ChildProcess;
await asyncOra('Launching Application', async () => {
spawned = spawn(electronExecPath, [appPath].concat(args as string[]), spawnOpts);
});
await runHook(forgeConfig, 'postStart', spawned);
return spawned;
};
示例7: async
export default async (dir: string) => {
await asyncOra('Initializing Git Repository', async () => {
await new Promise(async (resolve, reject) => {
if (await fs.pathExists(path.resolve(dir, '.git'))) {
d('.git directory already exists, skipping git initialization');
return resolve();
}
d('executing "git init" in directory:', dir);
exec('git init', {
cwd: dir,
}, (err) => {
if (err) return reject(err);
resolve();
});
});
});
};
示例8: async
export default async (dir: string, { copyCIFiles }: InitStarterFilesOptions) => {
await asyncOra('Copying Starter Files', async () => {
const tmplPath = path.resolve(__dirname, '../../../tmpl');
d('creating directory:', path.resolve(dir, 'src'));
await fs.mkdirs(path.resolve(dir, 'src'));
const rootFiles = ['_gitignore'];
if (copyCIFiles) rootFiles.push(...['_travis.yml', '_appveyor.yml']);
const srcFiles = ['index.js', 'index.html'];
for (const file of rootFiles) {
await copy(path.resolve(tmplPath, file), path.resolve(dir, file.replace(/^_/, '.')));
}
for (const file of srcFiles) {
await copy(path.resolve(tmplPath, file), path.resolve(dir, 'src', file));
}
});
};
示例9: async
export default async ({
dir = process.cwd(),
appPath = '.',
interactive = false,
enableLogging = false,
args = [],
runAsNode = false,
inspect = false,
}: StartOptions) => {
asyncOra.interactive = interactive;
await asyncOra('Locating Application', async () => {
const resolvedDir = await resolveDir(dir);
if (!resolvedDir) {
throw 'Failed to locate startable Electron application';
}
dir = resolvedDir;
});
const packageJSON = await readPackageJSON(dir);
if (!packageJSON.version) {
throw `Please set your application's 'version' in '${dir}/package.json'.`;
}
const forgeConfig = await getForgeConfig(dir);
await rebuild(
dir,
getElectronVersion(packageJSON),
process.platform as ForgePlatform,
process.arch as ForgeArch,
forgeConfig.electronRebuildConfig,
);
await runHook(forgeConfig, 'generateAssets');
let electronExecPath = path.resolve(dir, 'node_modules/electron/cli');
// If a plugin has taken over the start command let's stop here
const spawnedPluginChild = await forgeConfig.pluginInterface.overrideStartLogic({
dir,
appPath,
interactive,
enableLogging,
args,
runAsNode,
inspect,
});
if (typeof spawnedPluginChild === 'string') {
electronExecPath = spawnedPluginChild;
} else if (spawnedPluginChild) {
return spawnedPluginChild;
}
const spawnOpts = {
cwd: dir,
stdio: 'inherit',
env: Object.assign({}, process.env, enableLogging ? {
ELECTRON_ENABLE_LOGGING: 'true',
ELECTRON_ENABLE_STACK_DUMPING: 'true',
} : {}) as NodeJS.ProcessEnv,
};
if (runAsNode) {
spawnOpts.env.ELECTRON_RUN_AS_NODE = 'true';
} else {
delete spawnOpts.env.ELECTRON_RUN_AS_NODE;
}
if (inspect) {
args = ['--inspect' as (string|number)].concat(args);
}
let spawned!: ChildProcess;
await asyncOra('Launching Application', async () => {
spawned = spawn(process.execPath, [electronExecPath, appPath].concat(args as string[]), spawnOpts);
});
return spawned;
};
示例10: async
const publish = async ({
dir = process.cwd(),
interactive = false,
makeOptions = {},
publishTargets = undefined,
dryRun = false,
dryRunResume = false,
makeResults = undefined,
outDir,
}: PublishOptions) => {
asyncOra.interactive = interactive;
if (dryRun && dryRunResume) {
throw 'Can\'t dry run and resume a dry run at the same time';
}
if (dryRunResume && makeResults) {
throw 'Can\'t resume a dry run and use the provided makeResults at the same time';
}
const forgeConfig = await getForgeConfig(dir);
let packageJSON = await readMutatedPackageJson(dir, forgeConfig);
const calculatedOutDir = outDir || getCurrentOutDir(dir, forgeConfig);
const dryRunDir = path.resolve(calculatedOutDir, 'publish-dry-run');
if (dryRunResume) {
d('attempting to resume from dry run');
const publishes = await PublishState.loadFromDirectory(dryRunDir, dir);
for (const publishStates of publishes) {
d('publishing for given state set');
await publish({
dir,
interactive,
publishTargets,
makeOptions,
dryRun: false,
dryRunResume: false,
makeResults: publishStates.map(({ state }) => state),
});
}
return;
}
if (!makeResults) {
d('triggering make');
makeResults = await make(Object.assign({
dir,
interactive,
}, makeOptions));
} else {
// Restore values from dry run
d('restoring publish settings from dry run');
for (const makeResult of makeResults) {
packageJSON = makeResult.packageJSON;
makeOptions.platform = makeResult.platform;
makeOptions.arch = makeResult.arch;
for (const makePath of makeResult.artifacts) {
if (!await fs.pathExists(makePath)) {
throw `Attempted to resume a dry run but an artifact (${makePath}) could not be found`;
}
}
}
}
if (dryRun) {
d('saving results of make in dry run state', makeResults);
await fs.remove(dryRunDir);
await PublishState.saveToDirectory(dryRunDir, makeResults, dir);
return;
}
const resolvedDir = await resolveDir(dir);
if (!resolvedDir) {
throw 'Failed to locate publishable Electron application';
}
dir = resolvedDir;
const testPlatform = makeOptions.platform || process.platform as ForgePlatform;
if (!publishTargets) {
publishTargets = (forgeConfig.publishers || []);
// .filter(publisher => (typeof publisher !== 'string' && publisher.platforms) ? publisher.platforms.indexOf(testPlatform) !== -1 : true);
}
publishTargets = publishTargets.map((target) => {
if (typeof target === 'string') return { name: target };
return target;
}) as (IForgeResolvablePublisher | IForgePublisher)[];
for (const publishTarget of publishTargets) {
let publisher: PublisherBase<any>;
if ((publishTarget as IForgePublisher).__isElectronForgePublisher) {
publisher = publishTarget as any;
} else {
const resolvablePublishTarget = publishTarget as IForgeResolvablePublisher;
let publisherModule: any;
await asyncOra(`Resolving publish target: ${`${resolvablePublishTarget.name}`.cyan}`, async () => { // eslint-disable-line no-loop-func
try {
publisherModule = require(resolvablePublishTarget.name);
} catch (err) {
//.........这里部分代码省略.........