Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
gatherArtifacts: async function(config) {
// Gather all available contract artifacts
let files = await dir.promiseFiles(config.contracts_build_directory);
var contracts = files
.filter(file_path => {
return path.extname(file_path) === ".json";
})
.map(file_path => {
return path.basename(file_path, ".json");
})
.map(contract_name => {
return config.resolver.require(contract_name);
});
await Promise.all(
contracts.map(abstraction => abstraction.detectNetwork())
);
const getPortfolios = async () => {
let portfolioFiles;
try {
portfolioFiles = await dir.promiseFiles(portfoliosDirectoryPath);
} catch (error) {
if (error.code === 'ENOENT') {
return [];
}
throw error;
}
portfolioFiles = portfolioFiles.filter(file => file.endsWith('.json'));
const portfolios = await Promise.all(portfolioFiles.map(async filePath => {
const portfolio = await loadJsonFile(filePath);
portfolio.fileName = path.basename(filePath);
portfolio.id = fileNameToId(portfolio.fileName);
// TODO: Remove this sometime far in the future when everyone has migrated
export function list_files(input){
return dir.promiseFiles(input)
.then(files => {
files = files.filter(file => {
return file.indexOf('node_modules') === -1 && (['js', 'jsx', 'ts', 'tsx', 'html', 'htm'].includes(extension(file)) || file.toLowerCase().indexOf('package.json') > -1);
});
return files;
})
.catch(console.error);
}
export async function loadLocalPreloaders(connection: IConnection, projectFolder: string, storeProjectFolder: string) {
const localPreloadersDir = pathResolve(projectFolder, "preloaders");
if (existsSync(localPreloadersDir)) {
const localPreloaders: string[] = await dir.promiseFiles(localPreloadersDir);
const localPreloaderDefinitions = localPreloaders
.filter(function(preloader) {
return preloader.includes(".js") && !preloader.includes(".map");
})
.map(function(preloader) {
return {
module: preloader,
as: null,
waitForDOM: false
};
});
await loadPreloaders(
connection,
localPreloaderDefinitions,
projectFolder,
storeProjectFolder,
async function getPathToMainAppClassFile(projectDir) {
const pathToProjectSrcFiles = path.join(projectDir, 'src', 'main', 'java');
const srcFiles = await dir.promiseFiles(pathToProjectSrcFiles);
const mainAppClassFile = await findAsync(
srcFiles,
async(file) => {
const fileData = await fs.readFile(file, 'utf8');
const fileIsMainAppClassFile = fileData.includes(springAppAnnotation);
if (fileIsMainAppClassFile) {
return file;
}
throw new Error();
},
);
return mainAppClassFile;
}
static async getFiles(templatePath, generatorType) {
let promises;
switch (generatorType) {
case 'fullstack':
promises = [
dir.promiseFiles(
path.join(templatePath, FileUtilities.ClientTemplatesPath)
),
dir.promiseFiles(
path.join(templatePath, FileUtilities.ServerTemplatesPath)
),
dir.promiseFiles(
path.join(templatePath, FileUtilities.RootTemplatesPath)
)
];
break;
case 'server':
promises = [[], dir.promiseFiles(templatePath), []];
break;
default:
promises = [dir.promiseFiles(templatePath), [], []];
}
dir.promiseFiles(
path.join(templatePath, FileUtilities.ClientTemplatesPath)
),
dir.promiseFiles(
path.join(templatePath, FileUtilities.ServerTemplatesPath)
),
dir.promiseFiles(
path.join(templatePath, FileUtilities.RootTemplatesPath)
)
];
break;
case 'server':
promises = [[], dir.promiseFiles(templatePath), []];
break;
default:
promises = [dir.promiseFiles(templatePath), [], []];
}
const files = await Promise.all(promises);
return {
client: files[0],
server: files[1],
root: files[2]
};
}
async upload(args, ctx: IContext): Promise {
const { i18n } = ctx;
const oss = this.storage.get('oss');
const params: IOSSUploadParams = oss.find(({ project }) => project === this.project.path);
const buildPath = path.join(this.project.path, this.buildDir);
if (!await pathExists(buildPath)) {
throw new Error(i18n.format('baseAdapter.oss.upload.dirEmptyError', {buildDir: this.buildDir}));
}
const files = await dir.promiseFiles(buildPath);
if (!files.length) {
throw new Error(i18n.format('baseAdapter.oss.upload.buildEmptyError'));
}
const { bucket, directory, region } = params;
const aliOSS = new AliOSS({...params, endpoint: `${region}.${DOMAIN}`});
await aliOSS.setBucket(bucket);
return await Promise.all(files.map(async (file) => {
const fileRelativePath = path.relative(buildPath, file);
const storeFilepath = path.join(directory, fileRelativePath)
.replace(/\\/g, '/')
.replace(/^\//, '');
let result: IUploadResult;
try {
exports.preparePromise = function(specDir, specFile, infoFile, host, schemes, basePath, options) {
validate(options, constraints);
return dir.promiseFiles(specDir)
.then((files) => {
return files.filter(function(file) {
return file.endsWith(specFile);
});
})
.then((files) => {
return Promise.all(files.map(function(file) {
return SwaggerParser.validate(file, {
"allowUnknown": false,
});
}))
.then((apis) => {
SwaggerMerge.on('warn', function (msg) {
throw new Error(msg);
});
var info = yaml.safeLoad(fs.readFileSync(infoFile, 'utf8'));